Merge pull request #4055 from penpot/staging-migration

🐛 Migration bugfixes
This commit is contained in:
Andrey Antukh 2024-01-25 20:59:28 +01:00 committed by GitHub
commit a0a7b0dc7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 74 additions and 13 deletions

View file

@ -198,6 +198,15 @@
(update file-data :pages-index update-vals update-page)))
;; Sometimes we found that the file has issues in the internal
;; data structure of the local library; this function tries to
;; fix that issues.
fix-file-data
(fn [file-data]
(-> file-data
(d/update-when :colors dissoc nil)
(d/update-when :typographies dissoc nil)))
delete-big-geometry-shapes
(fn [file-data]
;; At some point in time, we had a bug that generated shapes
@ -205,12 +214,10 @@
;; schema. Since we don't have a way to fix those shapes, we
;; simply proceed to delete it. We ignore path type shapes
;; because they have not been affected by the bug.
(letfn [(fix-container
[container]
(letfn [(fix-container [container]
(d/update-when container :objects #(reduce-kv fix-shape % %)))
(fix-shape
[objects id shape]
(fix-shape [objects id shape]
(cond
(or (cfh/path-shape? shape)
(cfh/bool-shape? shape))
@ -232,6 +239,33 @@
(update :pages-index update-vals fix-container)
(d/update-when :components update-vals fix-container))))
;; Some files has totally broken shapes, we just remove them
fix-completly-broken-shapes
(fn [file-data]
(letfn [(update-object [objects id shape]
(cond
(nil? (:type shape))
(let [ids (cfh/get-children-ids objects id)]
(-> objects
(dissoc id)
(as-> $ (reduce dissoc $ ids))
(d/update-in-when [(:parent-id shape) :shapes]
(fn [shapes] (filterv #(not= id %) shapes)))))
(and (cfh/text-shape? shape)
(not (seq (:content shape))))
(dissoc objects id)
:else
objects))
(update-container [container]
(d/update-when container :objects #(reduce-kv update-object % %)))]
(-> file-data
(update :pages-index update-vals update-container)
(update :components update-vals update-container))))
fix-misc-shape-issues
(fn [file-data]
(letfn [(fix-container [container]
@ -248,6 +282,9 @@
0
gap)))
(nil? (:name shape))
(assoc :name (d/name (:type shape)))
;; Fix broken fills
(seq (:fills shape))
(update :fills (fn [fills] (filterv valid-fill? fills)))
@ -649,7 +686,9 @@
(update :pages-index update-vals fix-container))))]
(-> file-data
(fix-file-data)
(fix-page-invalid-options)
(fix-completly-broken-shapes)
(fix-bad-children)
(fix-misc-shape-issues)
(fix-recent-colors)