From a9a97aedd982166f6371a5a31f0858b10856b844 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 7 Mar 2023 14:52:29 +0100 Subject: [PATCH] wip #5781 @1 --- app/Console/Commands/ToolboxToWorkshop.php | 49 ++++++++++++++++++++++ app/Console/Commands/WorkshopMigration.php | 39 ++++++++++++----- 2 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 app/Console/Commands/ToolboxToWorkshop.php diff --git a/app/Console/Commands/ToolboxToWorkshop.php b/app/Console/Commands/ToolboxToWorkshop.php new file mode 100644 index 000000000..7c72de9d1 --- /dev/null +++ b/app/Console/Commands/ToolboxToWorkshop.php @@ -0,0 +1,49 @@ +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 + } +} diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php index c29a02303..c3d7ed02a 100644 --- a/app/Console/Commands/WorkshopMigration.php +++ b/app/Console/Commands/WorkshopMigration.php @@ -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); } -- 2.39.5