]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6571 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 29 Jan 2024 09:54:30 +0000 (10:54 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 29 Jan 2024 09:54:30 +0000 (10:54 +0100)
app/Console/Commands/SyncFluidbooksV3ToWorkshop.php [new file with mode: 0644]
app/Console/Commands/WorkshopMigration.php
app/Models/FluidbookPublication.php

diff --git a/app/Console/Commands/SyncFluidbooksV3ToWorkshop.php b/app/Console/Commands/SyncFluidbooksV3ToWorkshop.php
new file mode 100644 (file)
index 0000000..a54dca9
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Console\Commands\Base\ToolboxCommand;
+use App\Models\FluidbookPublication;
+use Illuminate\Support\Facades\DB;
+
+class SyncFluidbooksV3ToWorkshop extends ToolboxCommand
+{
+    protected $signature = 'syncfluidbooksv3toworkshop';
+    protected $description = 'Sync fluidbooks database to show on workshop fluidbooks made on toolbox';
+
+    public function handle()
+    {
+        // Delete fluidbook V3
+        DB::connection('extranet')->table('books')->where('version', "3")->delete();
+
+        $inserts = [];
+        $ids = [];
+
+        foreach (FluidbookPublication::withoutGlobalScopes()->where('created_ok', '1')->where('version', 3)->orderBy('id', 'ASC')->get() as $fb) {
+            /** @var $fb FluidbookPublication */
+            $i = ['book_id' => $fb->id,
+                'version' => 3,
+                'nom' => $fb->c_title,
+                'lang' => $fb->locale,
+                'region' => $fb->region,
+                'theme' => $fb->theme,
+                'proprietaire' => $fb->owner,
+                'status' => $fb->status,
+                'tache' => $fb->extranet_task ?? 0,
+                'date' => (new \DateTime($fb->created_at))->getTimestamp(),
+                'changedate' => (new \DateTime($fb->updated_at))->getTimestamp(),
+                'numerotation' => $fb->page_numbers??'',
+                'parametres' => $fb->settings,
+                'hash' => $fb->hash,
+                'cid' => $fb->cid,
+            ];
+            $inserts[] = $i;
+            $ids[] = $fb->id;
+        }
+
+        DB::connection('extranet')->table('books')->whereIn('book_id', $ids)->delete();
+        foreach ($inserts as $insert) {
+            DB::connection('extranet')->table('books')->insert($insert);
+        }
+    }
+}
index 118018c255cd7ef45bb3c9809454470d9fa945bc..e48482a0726a367144004ca8168176cca4ce6e2c 100644 (file)
@@ -49,6 +49,7 @@ class WorkshopMigration extends CubistCommand
             'Migrate magic models' => 'migrate',
             'Import documents' => 'importDocuments',
             'Import publications' => 'importPublications',
+            'Export publications' => 'exportPublications',
             'Clean caches' => 'cleanCache'
         ];
 
@@ -191,6 +192,10 @@ class WorkshopMigration extends CubistCommand
         return $res;
     }
 
+    protected function exportPublications(){
+
+    }
+
     protected function importPublications()
     {
         if ($this->option('publications') === 'none') {
index debe66d96b311ba934ea8e26c365e07197ab2628..17e3fe9a94729a326e87dafbf37b6e8231e8b88a 100644 (file)
@@ -794,6 +794,8 @@ class FluidbookPublication extends ToolboxStatusModel
         $new->visits_counter = 0;
         $new->hash = '';
         $new->cid = '';
+        $new->owner = backpack_user()->id;
+        $new->extranet_task = null;
         $new->version = 3;
         return $new;
     }