You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
10 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <template lang='pug'>
  2. v-card
  3. v-toolbar(flat, color='primary', dark, dense)
  4. .subtitle-1 {{ $t('admin:utilities.contentTitle') }}
  5. v-card-text
  6. .subtitle-1.pb-3.primary--text Rebuild Page Tree
  7. .body-2 The virtual structure of your wiki is automatically inferred from all page paths. You can trigger a full rebuild of the tree if some virtual folders are missing or not valid anymore.
  8. v-btn(outlined, color='primary', @click='rebuildTree', :disabled='loading').ml-0.mt-3
  9. v-icon(left) mdi-gesture-double-tap
  10. span Proceed
  11. v-divider.my-5
  12. .subtitle-1.pb-3.primary--text Rerender All Pages
  13. .body-2 All pages will be rendered again. Useful if internal links are broken or the rendering pipeline has changed.
  14. v-btn(outlined, color='primary', @click='rerenderPages', :disabled='loading', :loading='isRerendering').ml-0.mt-3
  15. v-icon(left) mdi-gesture-double-tap
  16. span Proceed
  17. v-dialog(
  18. v-model='isRerendering'
  19. persistent
  20. max-width='450'
  21. )
  22. v-card(color='blue darken-2', dark)
  23. v-card-text.pa-10.text-center
  24. semipolar-spinner.animated.fadeIn(
  25. :animation-duration='1500'
  26. :size='65'
  27. color='#FFF'
  28. style='margin: 0 auto;'
  29. )
  30. .mt-5.body-1.white--text Rendering all pages...
  31. .caption(v-if='renderIndex > 0') Rendering {{renderCurrentPath}}... ({{renderIndex}}/{{renderTotal}}, {{renderProgress}}%)
  32. .caption.mt-4 Do not leave this page.
  33. v-progress-linear.mt-5(
  34. color='white'
  35. :value='renderProgress'
  36. stream
  37. rounded
  38. :buffer-value='0'
  39. )
  40. v-divider.my-5
  41. .subtitle-1.pb-3.pl-0.primary--text Migrate all pages to target locale
  42. .body-2 If you created content before selecting a different locale and activating the namespacing capabilities, you may want to transfer all content to the base locale.
  43. .body-2.red--text: strong This operation is destructive and cannot be reversed! Make sure you have proper backups!
  44. v-toolbar.radius-7.mt-5(flat, :color='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-4`', height='80')
  45. v-select(
  46. label='Source Locale'
  47. outlined
  48. hide-details
  49. :items='locales'
  50. item-text='name'
  51. item-value='code'
  52. v-model='sourceLocale'
  53. )
  54. v-icon.mx-3(large) mdi-chevron-right-box-outline
  55. v-select(
  56. label='Target Locale'
  57. outlined
  58. hide-details
  59. :items='locales'
  60. item-text='name'
  61. item-value='code'
  62. v-model='targetLocale'
  63. )
  64. .body-2.mt-5 Pages that are already in the target locale will not be touched. If a page already exists at the target, the source page will not be modified as it would create a conflict. If you want to overwrite the target page, you must first delete it.
  65. v-btn(outlined, color='primary', @click='migrateToLocale', :disabled='loading').ml-0.mt-3
  66. v-icon(left) mdi-gesture-double-tap
  67. span Proceed
  68. v-divider.my-5
  69. .subtitle-1.pb-3.pl-0.primary--text Purge Page History
  70. .body-2 You may want to purge old history for pages to reduce database usage.
  71. .body-2 This operation only affects the database and not any history saved by a storage module (e.g. git version history)
  72. v-toolbar.radius-7.mt-5(flat, :color='$vuetify.theme.dark ? `grey darken-3-d5` : `grey lighten-4`', height='80')
  73. v-select(
  74. label='Delete history older than...'
  75. outlined
  76. hide-details
  77. :items='purgeHistoryOptions'
  78. item-text='title'
  79. item-value='key'
  80. v-model='purgeHistorySelection'
  81. )
  82. v-btn(outlined, color='primary', @click='purgeHistory', :disabled='loading').ml-0.mt-3
  83. v-icon(left) mdi-gesture-double-tap
  84. span Proceed
  85. </template>
  86. <script>
  87. import _ from 'lodash'
  88. import gql from 'graphql-tag'
  89. import utilityContentMigrateLocaleMutation from 'gql/admin/utilities/utilities-mutation-content-migratelocale.gql'
  90. import utilityContentRebuildTreeMutation from 'gql/admin/utilities/utilities-mutation-content-rebuildtree.gql'
  91. import { SemipolarSpinner } from 'epic-spinners'
  92. /* global siteLangs, siteConfig */
  93. export default {
  94. components: {
  95. SemipolarSpinner
  96. },
  97. data: () => {
  98. return {
  99. isRerendering: false,
  100. loading: false,
  101. renderProgress: 0,
  102. renderIndex: 0,
  103. renderTotal: 0,
  104. renderCurrentPath: '',
  105. sourceLocale: '',
  106. targetLocale: '',
  107. purgeHistorySelection: 'P1Y',
  108. purgeHistoryOptions: [
  109. { key: 'P1D', title: 'Today' },
  110. { key: 'P1M', title: '1 month' },
  111. { key: 'P3M', title: '3 months' },
  112. { key: 'P6M', title: '6 months' },
  113. { key: 'P1Y', title: '1 year' },
  114. { key: 'P2Y', title: '2 years' },
  115. { key: 'P3Y', title: '3 years' },
  116. { key: 'P5Y', title: '5 years' }
  117. ]
  118. }
  119. },
  120. computed: {
  121. currentLocale () {
  122. return siteConfig.lang
  123. },
  124. locales () {
  125. return siteLangs
  126. }
  127. },
  128. methods: {
  129. async rebuildTree () {
  130. this.loading = true
  131. this.$store.commit(`loadingStart`, 'admin-utilities-content-rebuildtree')
  132. try {
  133. const respRaw = await this.$apollo.mutate({
  134. mutation: utilityContentRebuildTreeMutation
  135. })
  136. const resp = _.get(respRaw, 'data.pages.rebuildTree.responseResult', {})
  137. if (resp.succeeded) {
  138. this.$store.commit('showNotification', {
  139. message: 'Page Tree rebuilt successfully.',
  140. style: 'success',
  141. icon: 'check'
  142. })
  143. } else {
  144. throw new Error(resp.message)
  145. }
  146. } catch (err) {
  147. this.$store.commit('pushGraphError', err)
  148. }
  149. this.$store.commit(`loadingStop`, 'admin-utilities-content-rebuildtree')
  150. this.loading = false
  151. },
  152. async rerenderPages () {
  153. this.loading = true
  154. this.isRerendering = true
  155. this.$store.commit(`loadingStart`, 'admin-utilities-content-rerender')
  156. try {
  157. const pagesRaw = await this.$apollo.query({
  158. query: gql`
  159. {
  160. pages {
  161. list {
  162. id
  163. path
  164. locale
  165. }
  166. }
  167. }
  168. `,
  169. fetchPolicy: 'network-only'
  170. })
  171. if (_.get(pagesRaw, 'data.pages.list', []).length < 1) {
  172. throw new Error('Could not find any page to render!')
  173. }
  174. this.renderIndex = 0
  175. this.renderTotal = pagesRaw.data.pages.list.length
  176. let failed = 0
  177. for (const page of pagesRaw.data.pages.list) {
  178. this.renderCurrentPath = `${page.locale}/${page.path}`
  179. this.renderIndex++
  180. this.renderProgress = Math.round(this.renderIndex / this.renderTotal * 100)
  181. const respRaw = await this.$apollo.mutate({
  182. mutation: gql`
  183. mutation($id: Int!) {
  184. pages {
  185. render(id: $id) {
  186. responseResult {
  187. succeeded
  188. errorCode
  189. slug
  190. message
  191. }
  192. }
  193. }
  194. }
  195. `,
  196. variables: {
  197. id: page.id
  198. }
  199. })
  200. const resp = _.get(respRaw, 'data.pages.render.responseResult', {})
  201. if (!resp.succeeded) {
  202. failed++
  203. }
  204. }
  205. if (failed > 0) {
  206. this.$store.commit('showNotification', {
  207. message: `Completed with ${failed} pages that failed to render. Check server logs for details.`,
  208. style: 'error',
  209. icon: 'alert'
  210. })
  211. } else {
  212. this.$store.commit('showNotification', {
  213. message: 'All pages have been rendered successfully.',
  214. style: 'success',
  215. icon: 'check'
  216. })
  217. }
  218. } catch (err) {
  219. this.$store.commit('pushGraphError', err)
  220. }
  221. this.$store.commit(`loadingStop`, 'admin-utilities-content-rerender')
  222. this.isRerendering = false
  223. this.loading = false
  224. },
  225. async migrateToLocale () {
  226. this.loading = true
  227. this.$store.commit(`loadingStart`, 'admin-utilities-content-migratelocale')
  228. try {
  229. const respRaw = await this.$apollo.mutate({
  230. mutation: utilityContentMigrateLocaleMutation,
  231. variables: {
  232. sourceLocale: this.sourceLocale,
  233. targetLocale: this.targetLocale
  234. }
  235. })
  236. const resp = _.get(respRaw, 'data.pages.migrateToLocale.responseResult', {})
  237. if (resp.succeeded) {
  238. this.$store.commit('showNotification', {
  239. message: `Migrated ${_.get(respRaw, 'data.pages.migrateToLocale.count', 0)} page(s) to target locale successfully.`,
  240. style: 'success',
  241. icon: 'check'
  242. })
  243. } else {
  244. throw new Error(resp.message)
  245. }
  246. } catch (err) {
  247. this.$store.commit('pushGraphError', err)
  248. }
  249. this.$store.commit(`loadingStop`, 'admin-utilities-content-migratelocale')
  250. this.loading = false
  251. },
  252. async purgeHistory () {
  253. this.loading = true
  254. this.$store.commit(`loadingStart`, 'admin-utilities-content-purgehistory')
  255. try {
  256. const respRaw = await this.$apollo.mutate({
  257. mutation: gql`
  258. mutation ($olderThan: String!) {
  259. pages {
  260. purgeHistory (
  261. olderThan: $olderThan
  262. ) {
  263. responseResult {
  264. errorCode
  265. message
  266. slug
  267. succeeded
  268. }
  269. }
  270. }
  271. }
  272. `,
  273. variables: {
  274. olderThan: this.purgeHistorySelection
  275. }
  276. })
  277. const resp = _.get(respRaw, 'data.pages.purgeHistory.responseResult', {})
  278. if (resp.succeeded) {
  279. this.$store.commit('showNotification', {
  280. message: `Purged history successfully.`,
  281. style: 'success',
  282. icon: 'check'
  283. })
  284. } else {
  285. throw new Error(resp.message)
  286. }
  287. } catch (err) {
  288. this.$store.commit('pushGraphError', err)
  289. }
  290. this.$store.commit(`loadingStop`, 'admin-utilities-content-purgehistory')
  291. this.loading = false
  292. }
  293. }
  294. }
  295. </script>
  296. <style lang='scss'>
  297. </style>