//'Backup current database' => 'backup',
'Migrate magic models' => 'migrate',
'Import documents' => 'importDocuments',
- //'Import publications' => 'importPublications',
+ 'Import publications' => 'importPublications',
'Clean caches' => 'cleanCache'
];
$this->executeProcessQuiet('/usr/bin/php8.0 artisan optimize:clear');
}
- protected function importDocuments()
+ protected function importDocuments($reset = true)
{
PHP::neverStop();
- FluidbookDocument::truncate();
+
+ $ws3step = 200000;
+
+ if ($reset) {
+ FluidbookDocument::truncate();
+ } else {
+ DB::update('DELETE FROM fluidbook_document WHERE id<' . $ws3step);
+ }
foreach (DB::table($this->_oldDB . '.documents')->orderBy('document_id', 'desc')->get() as $e) {
$this->line('Import ' . $e->document_id);
$c->bookmarks = str_replace('"titre":', '"title":', $this->_unserializeAndJSON($e->bookmarks, '[]'));
$c->saveWithoutFlushingCache();
}
- DB::update('ALTER TABLE ' . $c->getTable() . ' AUTO_INCREMENT = 200000;');
+ if ($reset) {
+ DB::update('ALTER TABLE ' . $c->getTable() . ' AUTO_INCREMENT = ' . $ws3step . ';');
+ }
}
protected function _unserializeAndJSON($s, $default = '[]')
return json_encode($r);
}
- protected function importPublications()
+ protected function importPublications($reset = false)
{
PHP::neverStop();
+ $ws3step = 30000;
$map = ['book_id' => 'id',
'nom' => 'name',
// $this->line('Delete ' . $book->id);
// $book->delete();
// }
- FluidbookPublication::truncate();
+ if ($reset) {
+ FluidbookPublication::truncate();
+ } else {
+ DB::update('DELETE FROM fluidbook_publication WHERE id<' . $ws3step);
+ }
+
foreach (DB::table($this->_oldDB . '.books')->orderBy('book_id', 'asc')->get() as $e) {
$this->line('Import ' . $e->book_id);
dd($e);
}
}
+ if ($reset) {
+ DB::update('ALTER TABLE ' . $c->getTable() . ' AUTO_INCREMENT = ' . $ws3step . ';');
+ }
+ }
+
+ protected function _unserialize($str)
+ {
+ $class = 'stdClass';
+ $str = preg_replace('/^O:\d+:"[^"]++"/', 'O:' . strlen($class) . ':"' . $class . '"', $str);
+ $str = str_replace("s:8:\"\0*\0datas\"", 's:5:"datas"', $str);
+ return unserialize($str);
}
}