From 4a266a5e04af4ceff036c291c5f2201b336ebdd9 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 16 Aug 2022 12:55:54 +0200 Subject: [PATCH] wip #5394 @0.5 --- app/Console/Commands/WorkshopMigration.php | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/app/Console/Commands/WorkshopMigration.php b/app/Console/Commands/WorkshopMigration.php index 0b8262a3a..e4e5206c9 100644 --- a/app/Console/Commands/WorkshopMigration.php +++ b/app/Console/Commands/WorkshopMigration.php @@ -94,9 +94,10 @@ class WorkshopMigration extends CubistCommand $c->file = $e->file; $c->owner = $e->proprietaire; $c->pages = $e->pages; - $c->pdf_data = $this->_unserializeAndJSON($e->generalInfos); - $c->file_data = $this->_unserializeAndJSON($e->localInfos); - $c->bookmarks = str_replace('"titre":', '"title":', $this->_unserializeAndJSON($e->bookmarks, '[]')); + + $c->pdf_data = $this->_unserialize($e->generalInfos); + $c->file_data = $this->_unserialize($e->localInfos); + $c->bookmarks = $this->_migrateBookmarks($e->bookmarks); $c->saveWithoutFlushingCache(); } if ($reset) { @@ -104,13 +105,26 @@ class WorkshopMigration extends CubistCommand } } - protected function _unserializeAndJSON($s, $default = '[]') + protected function _migrateBookmarks($bookmarks, $default = []) { - $r = ObjectUtil::safeUnserialize($s); - if (!$r) { - return $default; + $bookmarks = $this->_unserialize($bookmarks, $default); + $res = []; + foreach ($bookmarks as $bookmark) { + $bookmark['title'] = $bookmark['titre']; + unset($bookmark['titre']); + $res[] = $bookmark; } - return json_encode($r); + return $res; + } + + protected function _unserialize($s, $default = []) + { + return ObjectUtil::safeUnserialize($s, $default); + } + + protected function _unserializeAndJSON($s, $default = []) + { + return json_encode($this->_unserialize($s, $default)); } protected function importPublications($reset = false) @@ -214,11 +228,5 @@ class WorkshopMigration extends CubistCommand } } - protected function _unserialize($str) - { - $class = 'stdClass'; - $str = preg_replace('/^O:\d+:"[^"]++"/', 'O:' . strlen($class) . ':"' . $class . '"', $str); - $str = str_replace("s:8:\"\0*\0datas\"", 's:5:"datas"', $str); - return unserialize($str); - } + } -- 2.39.5