Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

;;; Commands
import-help (do
(clojure "-X:dev:import-help")
(clojure "-X:dev:import-help!")
(fs/copy-tree "bases/behave-docs/XHTML_Output/Resources/Images/"
"projects/behave/resources/public/help/images"
{:replace-existing true}))
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@
{:extra-paths
["projects/behave_cms/src/clj"
"projects/behave_cms/src/cljc"]
:exec-fn help-import/import-help}
:exec-fn help-import/import-help!}

:rollback-help-import
{:extra-paths
["projects/behave_cms/src/clj"
"projects/behave_cms/src/cljc"
"projects/behave_cms/resources"]
:exec-fn help-import/rollback-import}}}
:exec-fn help-import/rollback-import!}}}
56 changes: 33 additions & 23 deletions development/help_import.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
[datomic.api :as d]
[dita.xhtml-cleaner :refer [clean-topic clean-variables]]
[me.raynes.fs :as fs]
[schema-migrate.interface :as sm]))
[schema-migrate.interface :as sm]
[clojure.java.shell :refer [sh]]))

;;; Helpers

Expand All @@ -32,6 +33,10 @@
(:language/help-page)
(map (fn [p] [:db/retractEntity (:db/id p)]))))

(defn- behave-docs-git-hash []
(let [process (sh "git" "rev-parse" "--short" "HEAD" :dir "bases/behave-docs")]
(str/replace (:out process) "\n" "")))

;;; Topics

(defn- cleaned-topics-tx [behave-docs-base-dir english-lang]
Expand Down Expand Up @@ -61,38 +66,43 @@

;;; Public fns

(defn import-help
(defn import-help!
"Imports help from `bases/behave-docs`."
[& _]
(cms/init-db! (io/file "projects/behave_cms/resources/config.edn"))
(let [conn @ds/datomic-conn
db (d/db conn)
en-us (q-english-lang-id db)
-now (now)
add-tx (format "help-import-add-%s" -now)
remove-tx (format "help-import-remove-%s" -now)
(let [conn @ds/datomic-conn
db (d/db conn)
en-us (q-english-lang-id db)
git-hash (behave-docs-git-hash)
add-tx (format "help-import-add-%s" git-hash)
remove-tx (format "help-import-remove-%s" git-hash)
;; Behave Docs dir
behave-docs (io/file "bases" "behave-docs" "XHTML_Output" "BehaveAppHelp")]

#_(println (format "Removing old help docs %s" -now))
(d/transact conn (concat [(sm/->migration remove-tx)]
(remove-existing-pages-tx db en-us)))

#_(println (format "Adding new help docs %s" -now))
(d/transact conn (concat [(sm/->migration add-tx)]
(cleaned-topics-tx behave-docs en-us)
(cleaned-variables-tx behave-docs en-us)))))

(defn rollback-import
behave-docs (io/file "bases" "behave-docs" "XHTML_Output" "BehaveAppHelp")
existing-tx? (d/q '[:find ?t .
:in $ ?mid
:where [?t :bp/migration-id ?mid]]
(d/db @ds/datomic-conn) add-tx)]

(when-not existing-tx?
#_(println (format "Removing old help docs from hash: %s" -now))
(d/transact conn (concat [(sm/->migration remove-tx)]
(remove-existing-pages-tx db en-us)))

#_(println (format "Adding new help docs %s" -now))
(d/transact conn (concat [(sm/->migration add-tx)]
(cleaned-topics-tx behave-docs en-us)
(cleaned-variables-tx behave-docs en-us))))))

(defn rollback-import!
"Rollback imports. Option to provide a transaction date."
[& args]
(cms/init-db!)
(let [a-datetime (first args)
conn @ds/datomic-conn
db (d/db conn)
-now (now)
tx-remove-id (q-tx db (format "help-import-remove-%s" (or a-datetime -now)))
tx-add-id (q-tx db (format "help-import-add-%s" (or a-datetime -now)))]
git-hash (behave-docs-git-hash)
tx-remove-id (q-tx db (format "help-import-remove-%s" (or a-datetime git-hash)))
tx-add-id (q-tx db (format "help-import-add-%s" (or a-datetime git-hash)))]

(sm/rollback-tx! conn tx-remove-id)
(sm/rollback-tx! conn tx-add-id)))
Expand Down