]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5394 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 16 Aug 2022 10:55:54 +0000 (12:55 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 16 Aug 2022 10:55:54 +0000 (12:55 +0200)
app/Console/Commands/WorkshopMigration.php

index 0b8262a3afc0bdc3020d7a0cf1367d3150830e0b..e4e5206c9878702bf161d027fc9f61a7f8eb3a1f 100644 (file)
@@ -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);
-    }
+
 }