]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5781 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 Mar 2023 13:52:29 +0000 (14:52 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 Mar 2023 13:52:29 +0000 (14:52 +0100)
app/Console/Commands/ToolboxToWorkshop.php [new file with mode: 0644]
app/Console/Commands/WorkshopMigration.php

diff --git a/app/Console/Commands/ToolboxToWorkshop.php b/app/Console/Commands/ToolboxToWorkshop.php
new file mode 100644 (file)
index 0000000..7c72de9
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\FluidbookPublication;
+use Cubist\Backpack\Console\Commands\CubistCommand;
+use Illuminate\Support\Facades\DB;
+
+class ToolboxToWorkshop extends CubistCommand
+{
+    protected $signature = 'toolboxtows {id} {targetid=new}';
+    protected $description = 'Migrate a fluidbook made on the toolbox back to the workshop';
+
+    protected static $_wstable = 'extranet_clean.books';
+
+    public function handle()
+    {
+        /** @var FluidbookPublication $source */
+        $source = FluidbookPublication::find($this->argument('id'));
+        $map = WorkshopMigration::mapNames(true);
+        $mapValues = WorkshopMigration::mapValues(true);
+
+        $data = [];
+        foreach ($source->getAttributes() as $k => $v) {
+            if ($k === 'settings' || $k === 'id' || !isset($map[$k])) {
+                continue;
+            }
+            $key = isset($map[$k]) ? $map[$k] : $k;
+
+            if (stristr($key, 'date')) {
+                $date = new \DateTime($v);
+                $v = $date->getTimestamp();
+            }
+            $data[$key] = $v;
+
+        }
+        $targetid = $this->argument('targetid');
+        if ($targetid === 'new') {
+            $res = DB::select(DB::raw('SELECT MAX(book_id)+1 AS book_id FROM ' . self::$_wstable));
+            $data['book_id'] = $res[0]->book_id;
+
+            DB::table(self::$_wstable)->insert($data);
+        } else {
+            DB::table(self::$_wstable)->where('book_id', $targetid)->update($data);
+        }
+
+        //DB::table(self::$_wstable)->in
+    }
+}
index c29a023035603eb953b6d5b4d9b9d12d5d8e136b..c3d7ed02a2e39fec3f1d76313dc7e6982499a720 100644 (file)
@@ -148,16 +148,9 @@ class WorkshopMigration extends CubistCommand
         return json_encode($this->_unserialize($s, $default));
     }
 
-    protected function importPublications($reset = false)
+    public static function mapNames($flip = false)
     {
-        if ($this->option('publications') === 'none') {
-            return;
-        }
-
-        PHP::neverStop();
-
-
-        $map = ['book_id' => 'id',
+        $res = ['book_id' => 'id',
             'nom' => 'name',
             'proprietaire' => 'owner',
             'date' => 'created_at',
@@ -172,8 +165,32 @@ class WorkshopMigration extends CubistCommand
             'composition_update' => 'composition_updated_at',
             'exportdatas' => 'export_data',
         ];
+        if ($flip) {
+            $res = array_flip($res);
+        }
+        return $res;
+    }
+
+    public static function mapValues($flip = false)
+    {
+        $res = ['Open Sans (police du Fluidbook)' => 'OpenSans'];
+        if ($flip) {
+            $res = array_flip($res);
+        }
+        return $res;
+    }
+
+    protected function importPublications($reset = false)
+    {
+        if ($this->option('publications') === 'none') {
+            return;
+        }
+
+        PHP::neverStop();
+
 
-        $mapValues = ['Open Sans (police du Fluidbook)' => 'OpenSans'];
+        $map = self::mapNames();
+        $mapValues = self::mapValues();
 
         $ignore = [];
 
@@ -253,7 +270,7 @@ class WorkshopMigration extends CubistCommand
             $c->setAttribute('composition', $composition);
 
             try {
-                $c->saveWithoutFlushingCache();
+                $c->saveQuietlyWithoutFlushingCache();
             } catch (\Exception $e) {
                 dd($e);
             }