From 6b817d102b4c2454b0af7d2f9b56f9652bb00a18 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 28 Oct 2024 15:38:17 +0100 Subject: [PATCH] :bug: Add migration for a fix of invalid fills --- common/src/app/common/files/defaults.cljc | 2 +- common/src/app/common/files/migrations.cljc | 30 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/files/defaults.cljc b/common/src/app/common/files/defaults.cljc index fb70a81ee..7628d9469 100644 --- a/common/src/app/common/files/defaults.cljc +++ b/common/src/app/common/files/defaults.cljc @@ -6,4 +6,4 @@ (ns app.common.files.defaults) -(def version 55) +(def version 56) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 2b6c4b450..a2e2b5f55 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1075,6 +1075,33 @@ (update data :pages-index d/update-vals update-page))) +(defn migrate-up-56 + [data] + (letfn [(fix-fills [object] + (d/update-when object :fills (partial filterv valid-fill?))) + + (update-object [object] + (-> object + (fix-fills) + + ;; If shape contains shape-ref but has a nil value, we + ;; should remove it from shape object + (cond-> (and (contains? object :shape-ref) + (nil? (get object :shape-ref))) + (dissoc :shape-ref)) + + ;; The text shape also can has fills on the text + ;; fragments so we need to fix fills there + (cond-> (cfh/text-shape? object) + (update :content (partial txt/transform-nodes identity fix-fills))))) + + (update-container [container] + (d/update-when container :objects update-vals update-object))] + + (-> data + (update :pages-index update-vals update-container) + (update :components update-vals update-container)))) + (def migrations "A vector of all applicable migrations" [{:id 2 :migrate-up migrate-up-2} @@ -1121,4 +1148,5 @@ {:id 52 :migrate-up migrate-up-52} {:id 53 :migrate-up migrate-up-26} {:id 54 :migrate-up migrate-up-54} - {:id 55 :migrate-up migrate-up-55}]) + {:id 55 :migrate-up migrate-up-55} + {:id 56 :migrate-up migrate-up-56}])