Skip to content

Instantly share code, notes, and snippets.

@assertchris
Created June 11, 2012 14:25
Show Gist options
  • Select an option

  • Save assertchris/2910313 to your computer and use it in GitHub Desktop.

Select an option

Save assertchris/2910313 to your computer and use it in GitHub Desktop.
DB Sync
public function sync()
{
$models = array(
"issue" => new Issue(),
"layout" => new Layout(),
"template" => new Template(),
"page" => new Page(),
"element" => new Element(),
"style" => new Style(),
"event" => new Event(),
"action" => new Action(),
"animation" => new Animation()
);
$data = array();
foreach ($models as $label => $model)
{
$class = $model->class;
$rows = $class::all();
$data[$class] = Collection::map($rows, function($key, $value) {
return $value->toDataArray();
});
$this->database->sync($model);
Collection::map($data[$class], function($key, $value) use ($class) {
$row = new $class($value);
$row->id = null;
return $row->save();
});
}
$time = time();
$data = json_encode($data);
$ds = DIRECTORY_SEPARATOR;
file_put_contents(PATH."{$ds}application{$ds}backups{$ds}{$time}.json", $data);
echo "Sync done.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment