Created
June 11, 2012 14:25
-
-
Save assertchris/2910313 to your computer and use it in GitHub Desktop.
DB Sync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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