mirror of
https://github.com/penpot/penpot.git
synced 2025-05-12 06:36:37 +02:00
🐛 Ignore invalid file references on importing file-media-object
This commit is contained in:
parent
c30d4d313c
commit
58a06b8cf3
1 changed files with 33 additions and 25 deletions
|
@ -545,16 +545,13 @@
|
||||||
(us/assert! ::read-import-options options)
|
(us/assert! ::read-import-options options)
|
||||||
|
|
||||||
(letfn [(lookup-index [id]
|
(letfn [(lookup-index [id]
|
||||||
(if ignore-index-errors?
|
|
||||||
(or (get @*index* id) id)
|
|
||||||
(let [val (get @*index* id)]
|
(let [val (get @*index* id)]
|
||||||
(l/trace :fn "lookup-index" :id id :val val ::l/async false)
|
(l/trace :fn "lookup-index" :id id :val val ::l/async false)
|
||||||
(when-not val
|
(when (and (not ignore-index-errors?) (not val))
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code :incomplete-index
|
:code :incomplete-index
|
||||||
:hint "looks like index has missing data"))
|
:hint "looks like index has missing data"))
|
||||||
val)))
|
(or val id)))
|
||||||
|
|
||||||
(update-index [index coll]
|
(update-index [index coll]
|
||||||
(loop [items (seq coll)
|
(loop [items (seq coll)
|
||||||
index index]
|
index index]
|
||||||
|
@ -707,7 +704,6 @@
|
||||||
(let [storage (media/configure-assets-storage storage)
|
(let [storage (media/configure-assets-storage storage)
|
||||||
ids (read-obj! input)]
|
ids (read-obj! input)]
|
||||||
|
|
||||||
;; Step 1: process all storage objects
|
|
||||||
(doseq [expected-storage-id ids]
|
(doseq [expected-storage-id ids]
|
||||||
(let [id (read-uuid! input)
|
(let [id (read-uuid! input)
|
||||||
mdata (read-obj! input)]
|
mdata (read-obj! input)]
|
||||||
|
@ -729,18 +725,28 @@
|
||||||
(assoc ::sto/touched-at (dt/now)))
|
(assoc ::sto/touched-at (dt/now)))
|
||||||
sobject @(sto/put-object! storage params)]
|
sobject @(sto/put-object! storage params)]
|
||||||
(l/trace :hint "persisted storage object" :id id :new-id (:id sobject) ::l/async false)
|
(l/trace :hint "persisted storage object" :id id :new-id (:id sobject) ::l/async false)
|
||||||
(vswap! *index* assoc id (:id sobject)))))
|
(vswap! *index* assoc id (:id sobject)))))))
|
||||||
|
|
||||||
|
(persist-file-media-objects! []
|
||||||
|
(l/debug :hint "processing file media objects" :section :v1/sobjects ::l/async false)
|
||||||
|
|
||||||
;; Step 2: insert all file-media-object rows with correct
|
;; Step 2: insert all file-media-object rows with correct
|
||||||
;; storage-id reference.
|
;; storage-id reference.
|
||||||
(doseq [item @*media*]
|
(doseq [item @*media*]
|
||||||
(l/trace :hint "inserting file media objects" :id (:id item) ::l/async false)
|
(l/trace :hint "inserting file media object"
|
||||||
|
:id (:id item)
|
||||||
|
:file-id (:file-id item)
|
||||||
|
::l/async false)
|
||||||
|
|
||||||
|
(let [file-id (lookup-index (:file-id item))]
|
||||||
|
(if (= file-id (:file-id item))
|
||||||
|
(l/warn :hint "ignoring file media object" :file-id (:file-id item) ::l/async false)
|
||||||
(db/insert! *conn* :file-media-object
|
(db/insert! *conn* :file-media-object
|
||||||
(-> item
|
(-> item
|
||||||
(update :file-id lookup-index)
|
(assoc :file-id file-id)
|
||||||
(d/update-when :media-id lookup-index)
|
(d/update-when :media-id lookup-index)
|
||||||
(d/update-when :thumbnail-id lookup-index))
|
(d/update-when :thumbnail-id lookup-index))
|
||||||
{:on-conflict-do-nothing overwrite?}))))]
|
{:on-conflict-do-nothing overwrite?})))))]
|
||||||
|
|
||||||
(with-open [input (bs/zstd-input-stream input)]
|
(with-open [input (bs/zstd-input-stream input)]
|
||||||
(with-open [input (bs/data-input-stream input)]
|
(with-open [input (bs/data-input-stream input)]
|
||||||
|
@ -758,7 +764,9 @@
|
||||||
(case section
|
(case section
|
||||||
:v1/rels (read-rels-section! input)
|
:v1/rels (read-rels-section! input)
|
||||||
:v1/files (read-files-section! input files)
|
:v1/files (read-files-section! input files)
|
||||||
:v1/sobjects (read-sobjects-section! input))))))))))
|
:v1/sobjects (do
|
||||||
|
(read-sobjects-section! input)
|
||||||
|
(persist-file-media-objects!)))))))))))
|
||||||
|
|
||||||
(defn export!
|
(defn export!
|
||||||
[cfg]
|
[cfg]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue