|
15 | 15 | [logseq.db.common.order :as db-order] |
16 | 16 | [logseq.db.common.sqlite :as common-sqlite] |
17 | 17 | [logseq.db.frontend.class :as db-class] |
| 18 | + [logseq.db.sqlite.create-graph :as sqlite-create-graph] |
18 | 19 | [logseq.db.sqlite.export :as sqlite-export] |
19 | 20 | [logseq.graph-parser.exporter :as gp-exporter] |
20 | 21 | [logseq.outliner.core :as outliner-core] |
|
86 | 87 | (:block/uuid e)))))))] |
87 | 88 | blocks))))] |
88 | 89 | (when (seq template-blocks) |
| 90 | + ;; FIXME: outliner core apis shouldn't use `repo` |
89 | 91 | (let [result (outliner-core/insert-blocks |
90 | 92 | repo db template-blocks object |
91 | 93 | {:sibling? false |
|
323 | 325 | (cond->> add-created-by-tx-data |
324 | 326 | (nil? created-by-ent) (cons created-by-block)))))) |
325 | 327 |
|
| 328 | +(defn- revert-disallowed-changes |
| 329 | + [{:keys [tx-meta tx-data db-before db-after]}] |
| 330 | + (when-not (rtc-tx-or-download-graph? tx-meta) |
| 331 | + (let [built-in-page? (fn [id] |
| 332 | + (let [block (d/entity db-after id)] |
| 333 | + (and (contains? sqlite-create-graph/built-in-pages-names |
| 334 | + (:block/title block)) |
| 335 | + (ldb/built-in? block)))) |
| 336 | + tx-data' (mapcat |
| 337 | + (fn [[e a v _t added]] |
| 338 | + (when added |
| 339 | + (cond |
| 340 | + ;; using built-in pages as tags |
| 341 | + (and (= a :block/tags) (built-in-page? v)) |
| 342 | + [[:db/retract v :db/ident] |
| 343 | + [:db/retract v :logseq.property.class/extends] |
| 344 | + [:db/retract v :block/tags :logseq.class/Tag] |
| 345 | + [:db/add v :block/tags :logseq.class/Page] |
| 346 | + [:db/retract e a v]] |
| 347 | + |
| 348 | + ;; built-in block protected properties updated |
| 349 | + (and (contains? #{:db/ident :block/title :block/name :logseq.property/type |
| 350 | + :logseq.property/built-in? :logseq.property.class/extends} a) |
| 351 | + (some? (d/entity db-before e)) |
| 352 | + (let [block (d/entity db-after e)] |
| 353 | + (and (ldb/built-in? block) |
| 354 | + (not= (get block a) (get (d/entity db-before e) a))))) |
| 355 | + (if-some [prev-v (get (d/entity db-before e) a)] |
| 356 | + [[:db/add e a prev-v]] |
| 357 | + [[:db/retract e a v]]) |
| 358 | + |
| 359 | + :else |
| 360 | + nil))) |
| 361 | + tx-data)] |
| 362 | + (when (seq tx-data') |
| 363 | + (prn :debug ::revert-built-in-block-updates :tx-data (distinct tx-data'))) |
| 364 | + (distinct tx-data')))) |
| 365 | + |
326 | 366 | (defn- compute-extra-tx-data |
327 | 367 | [repo tx-report] |
328 | 368 | (let [{:keys [db-before db-after tx-data tx-meta]} tx-report |
329 | 369 | db db-after |
| 370 | + revert-tx-data (revert-disallowed-changes tx-report) |
330 | 371 | fix-page-tags-tx-data (fix-page-tags tx-report) |
331 | 372 | fix-inline-page-tx-data (fix-inline-built-in-page-classes tx-report) |
332 | 373 | toggle-page-and-block-tx-data (when (empty? fix-inline-page-tx-data) |
|
337 | 378 | insert-templates-tx (when-not (rtc-tx-or-download-graph? tx-meta) |
338 | 379 | (insert-tag-templates repo tx-report)) |
339 | 380 | created-by-tx (add-created-by-ref-hook db-before db-after tx-data tx-meta)] |
340 | | - (concat toggle-page-and-block-tx-data |
| 381 | + (concat revert-tx-data |
| 382 | + toggle-page-and-block-tx-data |
341 | 383 | display-blocks-tx-data |
342 | 384 | commands-tx |
343 | 385 | insert-templates-tx |
|
0 commit comments