0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 00:10:11 -05:00

🐛 Add migration for fix some inconsistencies on page data.

This commit is contained in:
Andrey Antukh 2021-07-15 16:40:00 +02:00
parent 185e06ed79
commit 455b0efa71
2 changed files with 57 additions and 0 deletions

View file

@ -95,3 +95,33 @@
[{:v1 (alength (blob/encode data {:version 1}))
:v2 (alength (blob/encode data {:version 2}))
:v3 (alength (blob/encode data {:version 3}))}]))
(defn update-page-1
[data]
(letfn [(find-empty-groups [objects]
(->> (vals objects)
(filter (fn [shape]
(and (= :group (:type shape))
(or (empty? (:shapes shape))
(every? (fn [child-id]
(not (contains? objects child-id)))
(:shapes shape))))))
(map :id)))
(update-page [[page-id page]]
(let [objects (:objects page)
eids (find-empty-groups objects)]
(map (fn [id]
{:type :del-obj
:page-id page-id
:id id})
eids)))]
(loop [i 0 data data]
(let [changes (mapcat update-page (:pages-index data))]
(prn "==== loop " i " ====")
(clojure.pprint/pprint changes)
(if (seq changes)
(recur (inc i)
(app.common.pages.changes/process-changes data changes))
data)))))

View file

@ -222,3 +222,30 @@
(update :pages-index #(d/mapm clean-container %))
(d/update-when :components #(d/mapm clean-container %)))))
(defmethod migrate 9
[data]
(letfn [(find-empty-groups [objects]
(->> (vals objects)
(filter (fn [shape]
(and (= :group (:type shape))
(or (empty? (:shapes shape))
(every? (fn [child-id]
(not (contains? objects child-id)))
(:shapes shape))))))
(map :id)))
(update-page [[page-id page]]
(let [objects (:objects page)
eids (find-empty-groups objects)]
(map (fn [id]
{:type :del-obj
:page-id page-id
:id id})
eids)))]
(loop [data data]
(let [changes (mapcat update-page (:pages-index data))]
(if (seq changes)
(recur (cp/process-changes data changes))
data)))))