]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5394 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 12 Aug 2022 12:36:53 +0000 (14:36 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 12 Aug 2022 12:36:53 +0000 (14:36 +0200)
app/Console/Commands/WorkshopMigration.php

index 1fc18bff420426d84a552997e4cccb3102524f78..0b8262a3afc0bdc3020d7a0cf1367d3150830e0b 100644 (file)
@@ -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);
     }
 }