From: Vincent Vanwaelscappel Date: Fri, 12 Aug 2022 12:36:53 +0000 (+0200) Subject: wip #5394 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=550b623ea4bc5b3b0bed689fdef19f60da780430;p=fluidbook-toolbox.git wip #5394 @1.5 --- diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php index 1fc18bff4..0b8262a3a 100644 --- a/app/Console/Commands/WorkshopMigration.php +++ b/app/Console/Commands/WorkshopMigration.php @@ -35,7 +35,7 @@ class WorkshopMigration extends CubistCommand //'Backup current database' => 'backup', 'Migrate magic models' => 'migrate', 'Import documents' => 'importDocuments', - //'Import publications' => 'importPublications', + 'Import publications' => 'importPublications', 'Clean caches' => 'cleanCache' ]; @@ -71,10 +71,17 @@ class WorkshopMigration extends CubistCommand $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); @@ -92,7 +99,9 @@ class WorkshopMigration extends CubistCommand $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 = '[]') @@ -104,9 +113,10 @@ class WorkshopMigration extends CubistCommand return json_encode($r); } - protected function importPublications() + protected function importPublications($reset = false) { PHP::neverStop(); + $ws3step = 30000; $map = ['book_id' => 'id', 'nom' => 'name', @@ -135,7 +145,12 @@ class WorkshopMigration extends CubistCommand // $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); @@ -194,5 +209,16 @@ class WorkshopMigration extends CubistCommand 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); } }