mirror of
https://github.com/penpot/penpot.git
synced 2025-12-23 22:48:40 -05:00
🐛 Fix migration sync-component-id-with-near-main (loop added)
This commit is contained in:
@@ -1779,34 +1779,44 @@
|
|||||||
|
|
||||||
(defmethod migrate-data "0018-sync-component-id-with-near-main"
|
(defmethod migrate-data "0018-sync-component-id-with-near-main"
|
||||||
[data _]
|
[data _]
|
||||||
(letfn [(fix-shape [page shape]
|
(let [libs (some-> (:libs data) deref)]
|
||||||
(if (and (ctk/subcopy-head? shape)
|
(letfn [(fix-shape
|
||||||
(nil? (ctk/get-swap-slot shape)))
|
[data page shape]
|
||||||
(let [file {:id (:id data) :data data}
|
(if (and (ctk/subcopy-head? shape)
|
||||||
libs (some-> (:libs data) deref)
|
(nil? (ctk/get-swap-slot shape)))
|
||||||
ref-shape (ctf/find-ref-shape file page libs shape {:include-deleted? true :with-context? true})]
|
(let [file {:id (:id data) :data data}
|
||||||
(if (and (some? ref-shape)
|
ref-shape (ctf/find-ref-shape file page libs shape {:include-deleted? true :with-context? true})]
|
||||||
(or (not= (:component-id shape) (:component-id ref-shape))
|
(if (and (some? ref-shape)
|
||||||
(not= (:component-file shape) (:component-file ref-shape))))
|
(or (not= (:component-id shape) (:component-id ref-shape))
|
||||||
(cond-> shape
|
(not= (:component-file shape) (:component-file ref-shape))))
|
||||||
(some? (:component-id ref-shape))
|
(cond-> shape
|
||||||
(assoc :component-id (:component-id ref-shape))
|
(some? (:component-id ref-shape))
|
||||||
|
(assoc :component-id (:component-id ref-shape))
|
||||||
|
|
||||||
(nil? (:component-id ref-shape))
|
(nil? (:component-id ref-shape))
|
||||||
(dissoc :component-id)
|
(dissoc :component-id)
|
||||||
|
|
||||||
(some? (:component-file ref-shape))
|
(some? (:component-file ref-shape))
|
||||||
(assoc :component-file (:component-file ref-shape))
|
(assoc :component-file (:component-file ref-shape))
|
||||||
|
|
||||||
(nil? (:component-file ref-shape))
|
(nil? (:component-file ref-shape))
|
||||||
(dissoc :component-file))
|
(dissoc :component-file))
|
||||||
shape))
|
shape))
|
||||||
shape))
|
shape))
|
||||||
|
|
||||||
(update-page [page]
|
(update-page
|
||||||
(d/update-when page :objects d/update-vals (partial fix-shape page)))]
|
[data page]
|
||||||
(-> data
|
(d/update-when page :objects d/update-vals (partial fix-shape data page)))
|
||||||
(update :pages-index d/update-vals update-page))))
|
|
||||||
|
(fix-data [data]
|
||||||
|
(loop [current-data data
|
||||||
|
iteration 0]
|
||||||
|
(let [next-data (update current-data :pages-index d/update-vals (partial update-page current-data))]
|
||||||
|
(if (or (= current-data next-data)
|
||||||
|
(> iteration 20)) ;; safety bound
|
||||||
|
next-data
|
||||||
|
(recur next-data (inc iteration))))))]
|
||||||
|
(fix-data data))))
|
||||||
|
|
||||||
|
|
||||||
(def available-migrations
|
(def available-migrations
|
||||||
|
|||||||
Reference in New Issue
Block a user