From 1f5991112dc7762a353b58e49236dcb25c1aa042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 23 Jan 2024 11:06:54 +0100 Subject: [PATCH] :bug: Add two more fixes to v2 migration --- backend/src/app/features/components_v2.clj | 37 +++++++++++++++++++++ common/src/app/common/files/migrations.cljc | 2 -- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index 34fb5d851..0d5875a14 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -118,6 +118,24 @@ (vswap! detached-ids conj (:id shape))) (ctk/detach-shape shape))) + remove-missing-children + (fn [file-data] + ;; Remove any child that does not exist. + (letfn [(fix-container + [container] + (update container :objects update-vals (partial fix-shape container))) + + (fix-shape + [container shape] + (let [objects (:objects container)] + (d/update-when shape :shapes + (fn [shapes] + (d/removev #(nil? (get objects %)) shapes)))))] + + (-> file-data + (update :pages-index update-vals fix-container) + (update :components update-vals fix-container)))) + fix-missing-image-metadata (fn [file-data] (let [update-object @@ -356,6 +374,23 @@ (update :pages-index update-vals fix-container) (update :components update-vals fix-container)))) + fix-path-copies + (fn [file-data] + ;; If the user has created a copy and then converted into a path, detach it + ;; because the synchronization will no longer work. + (letfn [(fix-container [container] + (update container :objects update-vals fix-shape)) + + (fix-shape [shape] + (if (and (ctk/instance-head? shape) + (cfh/path-shape? shape)) + (ctk/detach-shape shape) + shape))] + + (-> file-data + (update :pages-index update-vals fix-container) + (update :components update-vals fix-container)))) + transform-to-frames (fn [file-data] ;; Transform component and copy heads to frames, and set the @@ -450,6 +485,7 @@ (update :components update-vals fix-container))))] (-> file-data + (remove-missing-children) (fix-misc-shape-issues) (fix-recent-colors) (fix-missing-image-metadata) @@ -460,6 +496,7 @@ (fix-orphan-copies) (remap-refs) (fix-copies-of-detached) + (fix-path-copies) (transform-to-frames) (remap-frame-ids) (fix-frame-ids) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 982d5b10d..1cc3f4c8b 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -780,5 +780,3 @@ (-> data (update :pages-index update-vals update-container) (update :components update-vals update-container)))) - -