]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6501 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Nov 2023 08:50:18 +0000 (09:50 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 22 Nov 2023 08:50:18 +0000 (09:50 +0100)
app/Console/Commands/FluidbookDocumentSetRegion.php [new file with mode: 0644]
app/Console/Commands/WorkshopMigration.php
app/Models/FluidbookPublication.php

diff --git a/app/Console/Commands/FluidbookDocumentSetRegion.php b/app/Console/Commands/FluidbookDocumentSetRegion.php
new file mode 100644 (file)
index 0000000..428b950
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\FluidbookPublication;
+use Cubist\Backpack\Console\Commands\CubistCommand;
+use Illuminate\Support\Facades\DB;
+
+class FluidbookDocumentSetRegion extends CubistCommand
+{
+    protected $signature = 'fluidbook:document:setregion';
+    protected $description = 'Set right region to all documents';
+
+    /**
+     * @throws \Exception
+     */
+    public function handle()
+    {
+        $regions = [];
+        $default = 'UE';
+        foreach (FluidbookPublication::withoutGlobalScopes()->whereNot('region', $default)->get() as $fluidbook) {
+            /** @var $fluidbook FluidbookPublication */
+            $r = $fluidbook->region;
+
+            if (!isset($regions[$r])) {
+                $regions[$r] = [];
+            }
+            $regions[$r] += $fluidbook->getDocumentsId();
+
+        }
+
+        DB::table('fluidbook_document')->update(['region' => $default]);
+        foreach ($regions as $region => $documents) {
+            DB::table('fluidbook_document')->whereIn('id', $documents)->update(['region' => $region]);
+        }
+    }
+}
index c5e037c5faa4483a87090530ea96b6238d220961..befce7197ec208c0b6354a47fd654019d8380d9a 100644 (file)
@@ -307,7 +307,10 @@ class WorkshopMigration extends CubistCommand
             } catch (\Exception $e) {
                 dd($e);
             }
+
         }
+
+        Artisan::call('fluidbook:document:setregion');
     }
 
     protected function _normalizeLang($lang)
index 81ecbc1185021e886c471f5f313cdf6cb54baf18..d15b0552b00111feb67a25b531e54cd2cc0fc1c2 100644 (file)
@@ -443,6 +443,18 @@ class FluidbookPublication extends ToolboxStatusModel
 
     }
 
+    public function getDocumentsId()
+    {
+        $res = [];
+        if (null === $this->getComposition()) {
+            return [];
+        }
+        foreach ($this->getComposition() as $page) {
+            $res[$page[0]] = true;
+        }
+        return array_keys($res);
+    }
+
     public function getDocumentSizes()
     {
         if (null === $this->_documentsSize) {
@@ -956,6 +968,9 @@ class FluidbookPublication extends ToolboxStatusModel
     public function getComposition()
     {
         $res = $this->_getCompositionAttribute('composition');
+        if (null === $res) {
+            return [];
+        }
         return $res;
     }