]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5394 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 Aug 2022 08:03:12 +0000 (10:03 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 Aug 2022 08:03:12 +0000 (10:03 +0200)
app/Console/Commands/WorkshopMigration.php

index c63d841dbd695903ccc573b29f404d4e8c9eb7ab..1a0235a0a1b9c88ad4b2291d32c25785766a0518 100644 (file)
@@ -13,13 +13,14 @@ use Cubist\Backpack\Magic\Fields\Color;
 use Cubist\Backpack\Magic\Fields\Date;
 use Cubist\Backpack\Magic\Fields\Datetime;
 use Cubist\Backpack\Magic\Fields\Files;
+use Cubist\Util\ArrayUtil;
 use Cubist\Util\ObjectUtil;
 use Cubist\Util\PHP;
 use Illuminate\Support\Facades\DB;
 
 class WorkshopMigration extends CubistCommand
 {
-    protected $signature = 'ws:migrate';
+    protected $signature = 'ws:migrate {--publications=v2} {--documents=v2}';
     protected $description = 'Migrate data from Workshop V2';
     protected $_wsRanks = [];
     protected $_oldDB = 'extranet_clean';
@@ -71,19 +72,30 @@ class WorkshopMigration extends CubistCommand
         $this->executeProcessQuiet('/usr/bin/php8.0 artisan optimize:clear');
     }
 
-    protected function importDocuments($reset = true)
+    protected function importDocuments()
     {
+        if($this->option('documents')==='none'){
+            return;
+        }
+
         PHP::neverStop();
 
         $ws3step = 200000;
 
-        if ($reset) {
+        $q = DB::table($this->_oldDB . '.documents')->orderBy('document_id', 'desc');
+
+        if ($this->option('documents') === 'v2') {
+            DB::update('DELETE FROM fluidbook_document WHERE id<' . $ws3step);
+        } else if ($this->option('documents') === 'all') {
             FluidbookDocument::truncate();
         } else {
-            DB::update('DELETE FROM fluidbook_document WHERE id<' . $ws3step);
+            $range = ArrayUtil::parseRange($this->option('documents'));
+            FluidbookDocument::whereIn('id', $range)->delete();
+            $q->whereIn('document_id', $range);
         }
 
-        foreach (DB::table($this->_oldDB . '.documents')->orderBy('document_id', 'desc')->get() as $e) {
+
+        foreach ($q->get() as $e) {
             $this->line('Import ' . $e->document_id);
             $c = new FluidbookDocument();
             $c->setIncrementing(false);
@@ -100,7 +112,7 @@ class WorkshopMigration extends CubistCommand
             $c->bookmarks = $this->_migrateBookmarks($e->bookmarks);
             $c->saveWithoutFlushingCache();
         }
-        if ($reset) {
+        if ($this->option('documents') === 'all') {
             DB::update('ALTER TABLE ' . $c->getTable() . ' AUTO_INCREMENT = ' . $ws3step . ';');
         }
     }
@@ -133,6 +145,10 @@ class WorkshopMigration extends CubistCommand
 
     protected function importPublications($reset = false)
     {
+        if($this->option('publications')==='none'){
+            return;
+        }
+
         PHP::neverStop();
         $ws3step = 30000;
 
@@ -159,18 +175,20 @@ class WorkshopMigration extends CubistCommand
         $this->line('Begin publications migration');
 
         FluidbookTheme::$updateWS2ViewOnChange = false;
-//        foreach (FluidbookPublication::lazy() as $book) {
-//            $this->line('Delete ' . $book->id);
-//            $book->delete();
-//        }
-        if ($reset) {
+
+        $q = DB::table($this->_oldDB . '.books')->orderBy('book_id', 'asc');
+
+        if ($this->option('publications') === 'v2') {
+            DB::update('DELETE FROM fluidbook_publication WHERE id<' . $ws3step);
+        } else if ($this->option('publications') === 'all') {
             FluidbookPublication::truncate();
         } else {
-            DB::update('DELETE FROM fluidbook_publication WHERE id<' . $ws3step);
+            $range = ArrayUtil::parseRange($this->option('publications'));
+            FluidbookPublication::whereIn('id', $range)->delete();
+            $q->whereIn('book_id', $range);
         }
 
-
-        foreach (DB::table($this->_oldDB . '.books')->orderBy('book_id', 'asc')->get() as $e) {
+        foreach ($q->get() as $e) {
             $this->line('Import ' . $e->book_id);
             $oldRoot = $this->_oldRoot . 'books/working/' . $e->book_id . '/';
             $c = new FluidbookPublication();
@@ -207,7 +225,7 @@ class WorkshopMigration extends CubistCommand
                     $date = new \DateTime();
                     $date->setTimestamp($data);
                     $data = $date;
-                } else if ($k === 'chapters') {
+                } else if ($k == 'chapters') {
                     $data = $this->_normalizeChapters($data);
                 }
                 if (isset($mapValues[$data])) {