|
|
@ -1,5 +1,5 @@
|
|
|
|
import { Model } from 'objection'
|
|
|
|
import { Model } from 'objection'
|
|
|
|
import { find, get, has, initial, isEmpty, isString, last, pick } from 'lodash-es'
|
|
|
|
import { cloneDeep, find, get, has, initial, isEmpty, isString, last, pick } from 'lodash-es'
|
|
|
|
import { Type as JSBinType } from 'js-binary'
|
|
|
|
import { Type as JSBinType } from 'js-binary'
|
|
|
|
import { getDictNameFromLocale } from '../helpers/common.mjs'
|
|
|
|
import { getDictNameFromLocale } from '../helpers/common.mjs'
|
|
|
|
import { generateHash, getFileExtension, injectPageMetadata } from '../helpers/page.mjs'
|
|
|
|
import { generateHash, getFileExtension, injectPageMetadata } from '../helpers/page.mjs'
|
|
|
@ -888,15 +888,10 @@ export class Page extends Model {
|
|
|
|
* @returns {Promise} Promise with no value
|
|
|
|
* @returns {Promise} Promise with no value
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static async movePage (opts) {
|
|
|
|
static async movePage (opts) {
|
|
|
|
let page
|
|
|
|
if (!has(opts, 'id')) {
|
|
|
|
if (has(opts, 'id')) {
|
|
|
|
throw new Error('Missing page ID')
|
|
|
|
page = await WIKI.db.pages.query().findById(opts.id)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
page = await WIKI.db.pages.query().findOne({
|
|
|
|
|
|
|
|
path: opts.path,
|
|
|
|
|
|
|
|
locale: opts.locale
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const page = await WIKI.db.pages.query().findById(opts.id)
|
|
|
|
if (!page) {
|
|
|
|
if (!page) {
|
|
|
|
throw new WIKI.Error.PageNotFound()
|
|
|
|
throw new WIKI.Error.PageNotFound()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -947,63 +942,83 @@ export class Page extends Model {
|
|
|
|
versionDate: page.updatedAt
|
|
|
|
versionDate: page.updatedAt
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const destinationHash = generateHash({ path: opts.destinationPath, locale: opts.destinationLocale })
|
|
|
|
// -> Update page object
|
|
|
|
|
|
|
|
const updatedPage = cloneDeep(page)
|
|
|
|
|
|
|
|
updatedPage.path = opts.destinationPath
|
|
|
|
|
|
|
|
updatedPage.locale = opts.destinationLocale
|
|
|
|
|
|
|
|
updatedPage.title = opts.title ?? page.title
|
|
|
|
|
|
|
|
updatedPage.hash = generateHash({ path: opts.destinationPath, locale: opts.destinationLocale })
|
|
|
|
|
|
|
|
updatedPage.authorId = opts.user.id
|
|
|
|
|
|
|
|
|
|
|
|
// -> Move page
|
|
|
|
// -> Move page
|
|
|
|
const destinationTitle = (page.title === page.path ? opts.destinationPath : page.title)
|
|
|
|
|
|
|
|
await WIKI.db.pages.query().patch({
|
|
|
|
await WIKI.db.pages.query().patch({
|
|
|
|
path: opts.destinationPath,
|
|
|
|
path: updatedPage.path,
|
|
|
|
locale: opts.destinationLocale,
|
|
|
|
locale: updatedPage.locale,
|
|
|
|
title: destinationTitle,
|
|
|
|
title: updatedPage.title,
|
|
|
|
hash: destinationHash
|
|
|
|
hash: updatedPage.hash,
|
|
|
|
|
|
|
|
authorId: updatedPage.authorId
|
|
|
|
}).findById(page.id)
|
|
|
|
}).findById(page.id)
|
|
|
|
await WIKI.db.pages.deletePageFromCache(page.hash)
|
|
|
|
await WIKI.db.pages.deletePageFromCache(page.hash)
|
|
|
|
WIKI.events.outbound.emit('deletePageFromCache', page.hash)
|
|
|
|
WIKI.events.outbound.emit('deletePageFromCache', page.hash)
|
|
|
|
|
|
|
|
|
|
|
|
// -> Rebuild page tree
|
|
|
|
// -> Replace tree node
|
|
|
|
await WIKI.db.pages.rebuildTree()
|
|
|
|
const pathParts = updatedPage.path.split('/')
|
|
|
|
|
|
|
|
await WIKI.db.knex('tree').where('id', page.id).del()
|
|
|
|
|
|
|
|
await WIKI.db.tree.addPage({
|
|
|
|
|
|
|
|
id: page.id,
|
|
|
|
|
|
|
|
parentPath: initial(pathParts).join('/'),
|
|
|
|
|
|
|
|
fileName: last(pathParts),
|
|
|
|
|
|
|
|
locale: updatedPage.locale,
|
|
|
|
|
|
|
|
title: updatedPage.title,
|
|
|
|
|
|
|
|
tags: updatedPage.tags,
|
|
|
|
|
|
|
|
meta: {
|
|
|
|
|
|
|
|
authorId: updatedPage.authorId,
|
|
|
|
|
|
|
|
contentType: updatedPage.contentType,
|
|
|
|
|
|
|
|
creatorId: updatedPage.creatorId,
|
|
|
|
|
|
|
|
description: updatedPage.description,
|
|
|
|
|
|
|
|
isBrowsable: updatedPage.isBrowsable,
|
|
|
|
|
|
|
|
ownerId: updatedPage.ownerId,
|
|
|
|
|
|
|
|
publishState: updatedPage.publishState,
|
|
|
|
|
|
|
|
publishEndDate: updatedPage.publishEndDate,
|
|
|
|
|
|
|
|
publishStartDate: updatedPage.publishStartDate
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
siteId: updatedPage.siteId
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// -> Rename in Search Index
|
|
|
|
// -> Rename in Search Index
|
|
|
|
const pageContents = await WIKI.db.pages.query().findById(page.id).select('render')
|
|
|
|
WIKI.db.pages.updatePageSearchVector({ id: page.id })
|
|
|
|
page.safeContent = WIKI.db.pages.cleanHTML(pageContents.render)
|
|
|
|
|
|
|
|
await WIKI.data.searchEngine.renamed({
|
|
|
|
|
|
|
|
...page,
|
|
|
|
|
|
|
|
destinationPath: opts.destinationPath,
|
|
|
|
|
|
|
|
destinationLocale: opts.destinationLocale,
|
|
|
|
|
|
|
|
destinationHash
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -> Rename in Storage
|
|
|
|
// -> Rename in Storage
|
|
|
|
if (!opts.skipStorage) {
|
|
|
|
if (!opts.skipStorage) {
|
|
|
|
await WIKI.db.storage.pageEvent({
|
|
|
|
// await WIKI.db.storage.pageEvent({
|
|
|
|
event: 'renamed',
|
|
|
|
// event: 'renamed',
|
|
|
|
page: {
|
|
|
|
// page: {
|
|
|
|
...page,
|
|
|
|
// ...page,
|
|
|
|
destinationPath: opts.destinationPath,
|
|
|
|
// destinationPath: updatedPage.path,
|
|
|
|
destinationLocale: opts.destinationLocale,
|
|
|
|
// destinationLocale: updatedPage.locale,
|
|
|
|
destinationHash,
|
|
|
|
// destinationHash: updatedPage.hash,
|
|
|
|
moveAuthorId: opts.user.id,
|
|
|
|
// moveAuthorId: opts.user.id,
|
|
|
|
moveAuthorName: opts.user.name,
|
|
|
|
// moveAuthorName: opts.user.name,
|
|
|
|
moveAuthorEmail: opts.user.email
|
|
|
|
// moveAuthorEmail: opts.user.email
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
})
|
|
|
|
// })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -> Reconnect Links : Changing old links to the new path
|
|
|
|
// // -> Reconnect Links : Changing old links to the new path
|
|
|
|
await WIKI.db.pages.reconnectLinks({
|
|
|
|
// await WIKI.db.pages.reconnectLinks({
|
|
|
|
sourceLocale: page.locale,
|
|
|
|
// sourceLocale: page.locale,
|
|
|
|
sourcePath: page.path,
|
|
|
|
// sourcePath: page.path,
|
|
|
|
locale: opts.destinationLocale,
|
|
|
|
// locale: opts.destinationLocale,
|
|
|
|
path: opts.destinationPath,
|
|
|
|
// path: opts.destinationPath,
|
|
|
|
mode: 'move'
|
|
|
|
// mode: 'move'
|
|
|
|
})
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
// -> Reconnect Links : Validate invalid links to the new path
|
|
|
|
// // -> Reconnect Links : Validate invalid links to the new path
|
|
|
|
await WIKI.db.pages.reconnectLinks({
|
|
|
|
// await WIKI.db.pages.reconnectLinks({
|
|
|
|
locale: opts.destinationLocale,
|
|
|
|
// locale: opts.destinationLocale,
|
|
|
|
path: opts.destinationPath,
|
|
|
|
// path: opts.destinationPath,
|
|
|
|
mode: 'create'
|
|
|
|
// mode: 'create'
|
|
|
|
})
|
|
|
|
// })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|