fix: search engine broken when renaming or moving pages (#2815)

For building suggest in elasticsearch, the safeContent field will be splitted into arrays. If the page is renamed or moved, the server will throw error: "Cannot read property 'split' of Undefined", and the index will be broken. Here two lines are added to fix this issue.
This commit is contained in:
scienceasdf 2020-12-14 03:51:44 +08:00 committed by GitHub
parent a1f1cd7356
commit d7d00b44f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -544,6 +544,8 @@ module.exports = class Page extends Model {
await WIKI.models.pages.rebuildTree() await WIKI.models.pages.rebuildTree()
// -> Rename in Search Index // -> Rename in Search Index
const pageContents = await WIKI.models.pages.query().findById(page.id).select('render')
page.safeContent = WIKI.models.pages.cleanHTML(pageContents.render)
await WIKI.data.searchEngine.renamed({ await WIKI.data.searchEngine.renamed({
...page, ...page,
destinationPath: opts.destinationPath, destinationPath: opts.destinationPath,