🐛 Avoid creating backup page if no components and no graphics

This commit is contained in:
Andrés Moya 2023-11-14 12:23:32 +01:00 committed by Andrey Antukh
parent c7fdbe37f1
commit 02612ab4ca

View file

@ -580,39 +580,41 @@
(defn- migrate-graphics (defn- migrate-graphics
[fdata] [fdata]
(let [[fdata page-id position] (if (empty? (:media fdata))
(ctf/get-or-add-library-page fdata grid-gap) fdata
(let [[fdata page-id position]
(ctf/get-or-add-library-page fdata grid-gap)
media (->> (vals (:media fdata)) media (->> (vals (:media fdata))
(map (fn [{:keys [width height] :as media}] (map (fn [{:keys [width height] :as media}]
(let [points (-> (grc/make-rect 0 0 width height) (let [points (-> (grc/make-rect 0 0 width height)
(grc/rect->points))] (grc/rect->points))]
(assoc media :points points))))) (assoc media :points points)))))
;; FIXME: think about what to do with existing media entries ?? ;; FIXME: think about what to do with existing media entries ??
grid (ctst/generate-shape-grid media position grid-gap)] grid (ctst/generate-shape-grid media position grid-gap)]
(when (some? *stats*) (when (some? *stats*)
(let [total (count media)] (let [total (count media)]
(swap! *stats* (fn [stats] (swap! *stats* (fn [stats]
(-> stats (-> stats
(update :processed/graphics (fnil + 0) total) (update :processed/graphics (fnil + 0) total)
(assoc :current/graphics total)))))) (assoc :current/graphics total))))))
(->> (d/zip media grid) (->> (d/zip media grid)
(reduce (fn [fdata [mobj position]] (reduce (fn [fdata [mobj position]]
(try (try
(process-media-object fdata page-id mobj position) (process-media-object fdata page-id mobj position)
(catch Throwable cause (catch Throwable cause
(l/warn :hint "unable to process file media object (skiping)" (l/warn :hint "unable to process file media object (skiping)"
:file-id (str (:id fdata)) :file-id (str (:id fdata))
:id (str (:id mobj)) :id (str (:id mobj))
:cause cause) :cause cause)
(if-not *skip-on-error* (if-not *skip-on-error*
(throw cause) (throw cause)
fdata)))) fdata))))
fdata)))) fdata)))))
(defn- migrate-file-data (defn- migrate-file-data
[fdata libs] [fdata libs]