mirror of
https://github.com/penpot/penpot.git
synced 2025-07-04 23:27:17 +02:00
🐛 Add migration fixing files with shape-ref cycles (#5663)
* 🐛 Add migration fixing files with shape-ref cycles
* :wip: Add optimized version of migration 62
---------
Co-authored-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
parent
9c60d1cdf9
commit
2ef22ecd08
2 changed files with 37 additions and 3 deletions
|
@ -6,4 +6,4 @@
|
|||
|
||||
(ns app.common.files.defaults)
|
||||
|
||||
(def version 59)
|
||||
(def version 62)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
[app.common.text :as txt]
|
||||
[app.common.types.color :as ctc]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape.shadow :as ctss]
|
||||
|
@ -1145,6 +1146,39 @@
|
|||
(update :pages-index update-vals update-container)
|
||||
(update :components update-vals update-container))))
|
||||
|
||||
(defn migrate-up-62
|
||||
[data]
|
||||
(let [xform-cycles-ids
|
||||
(comp (filter #(= (:id %) (:shape-ref %)))
|
||||
(map :id))
|
||||
|
||||
remove-cycles
|
||||
(fn [objects]
|
||||
(let [cycles-ids (into #{} xform-cycles-ids (vals objects))
|
||||
to-detach (->> cycles-ids
|
||||
(map #(get objects %))
|
||||
(map #(ctn/get-head-shape objects %))
|
||||
(map :id)
|
||||
distinct
|
||||
(mapcat #(ctn/get-children-in-instance objects %))
|
||||
(map :id)
|
||||
set)]
|
||||
|
||||
(reduce-kv (fn [objects id shape]
|
||||
(if (contains? to-detach id)
|
||||
(assoc objects id (ctk/detach-shape shape))
|
||||
objects))
|
||||
objects
|
||||
objects)))
|
||||
|
||||
update-component
|
||||
(fn [component]
|
||||
;; we only have encounter this on deleted components,
|
||||
;; so the relevant objects are inside the component
|
||||
(d/update-when component :objects remove-cycles))]
|
||||
|
||||
(update data :components update-vals update-component)))
|
||||
|
||||
(def migrations
|
||||
"A vector of all applicable migrations"
|
||||
[{:id 2 :migrate-up migrate-up-2}
|
||||
|
@ -1194,5 +1228,5 @@
|
|||
{:id 55 :migrate-up migrate-up-55}
|
||||
{:id 56 :migrate-up migrate-up-56}
|
||||
{:id 57 :migrate-up migrate-up-57}
|
||||
{:id 59 :migrate-up migrate-up-59}])
|
||||
|
||||
{:id 59 :migrate-up migrate-up-59}
|
||||
{:id 62 :migrate-up migrate-up-62}])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue