mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -05:00
✨ Update srepl helpers
This commit is contained in:
parent
c0eab96253
commit
b2cbb1e60f
2 changed files with 31 additions and 25 deletions
|
@ -66,17 +66,20 @@
|
|||
(db/with-atomic [conn (:app.db/pool system)]
|
||||
(let [file (db/get-by-id conn :file id {:for-update true})
|
||||
file (-> file
|
||||
(update :features db/decode-pgarray #{})
|
||||
(update :data blob/decode)
|
||||
(cond-> migrate? (update :data pmg/migrate-data))
|
||||
(update :data update-fn)
|
||||
(update :data blob/encode)
|
||||
(cond-> migrate? (update :data pmg/migrate-data)))
|
||||
file (-> (update-fn file)
|
||||
(cond-> inc-revn? (update :revn inc)))]
|
||||
(when save?
|
||||
(db/update! conn :file
|
||||
{:data (:data file)
|
||||
:revn (:revn file)}
|
||||
{:id (:id file)}))
|
||||
(update file :data blob/decode))))
|
||||
(let [features (db/create-array conn "text" (:features file))
|
||||
data (blob/encode (:data file))]
|
||||
(db/update! conn :file
|
||||
{:data data
|
||||
:revn (:revn file)
|
||||
:features features}
|
||||
{:id id})))
|
||||
file)))
|
||||
|
||||
(def ^:private sql:retrieve-files-chunk
|
||||
"SELECT id, name, created_at, data FROM file
|
||||
|
@ -122,27 +125,12 @@
|
|||
(on-end state)
|
||||
state))))))
|
||||
|
||||
|
||||
(defn analyze-file-data
|
||||
[system & {:keys [id on-form on-data]}]
|
||||
(let [file (get-file system id)]
|
||||
(cond
|
||||
(fn? on-data)
|
||||
(on-data (:data file))
|
||||
|
||||
(fn? on-form)
|
||||
(walk/postwalk (fn [form]
|
||||
(on-form form)
|
||||
form)
|
||||
(:data file)))
|
||||
nil))
|
||||
|
||||
(defn update-pages
|
||||
"Apply a function to all pages of one file. The function receives a page and returns an updated page."
|
||||
[data f]
|
||||
(update data :pages-index d/update-vals f))
|
||||
(update data :pages-index update-vals f))
|
||||
|
||||
(defn update-shapes
|
||||
"Apply a function to all shapes of one page The function receives a shape and returns an updated shape"
|
||||
[page f]
|
||||
(update page :objects d/update-vals f))
|
||||
(update page :objects update-vals f))
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
[app.rpc.queries.profile :as profile]
|
||||
[app.srepl.fixes :as f]
|
||||
[app.srepl.helpers :as h]
|
||||
[app.util.objects-map :as omap]
|
||||
[app.util.time :as dt]
|
||||
[clojure.pprint :refer [pprint]]
|
||||
[cuerdas.core :as str]))
|
||||
|
@ -101,3 +102,20 @@
|
|||
(db/update! conn :profile {:is-blocked true} {:id (:id profile)})
|
||||
(db/delete! conn :http-session {:profile-id (:id profile)})
|
||||
:blocked))))
|
||||
|
||||
(defn enable-objects-map-on-file
|
||||
[system & {:keys [save? id]}]
|
||||
(letfn [(update-file [{:keys [features] :as file}]
|
||||
(if (contains? features "storage/objects-map")
|
||||
file
|
||||
(update file :data migrate-to-omap)))
|
||||
|
||||
(migrate-to-omap [data]
|
||||
(-> data
|
||||
(update :pages-index update-vals #(update % :objects omap/wrap))
|
||||
(update :components update-vals #(update % :objects omap/wrap))))]
|
||||
|
||||
(h/update-file! system
|
||||
:id id
|
||||
:update-fn update-file
|
||||
:save? save?)))
|
||||
|
|
Loading…
Reference in a new issue