From 52304a8149d781dae9706347bf81c6f7df61dfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mart=C3=ADnez=20Interactiv4?= Date: Fri, 29 Jan 2021 20:15:22 +0100 Subject: [PATCH] fix: update storage.js to match pageHelper.injectPageMetadata (#2832) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update storage.js to match pageHelper.injectPageMetadata At pageHelper.injectPageMetadata references editorKey and tags to build metadata, but this data seems not to be supplied to this function, since page object is only built from specified columns. As a result, tags are always empty when exporting pages, and editor key appears as undefined. It happens also with git storage, but may happen with another storage providers. I run into this issue running Wiki.js 2.5.170 with the following Docker stack: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 39373979b693 requarks/wiki:2 "docker-entrypoint.s…" 44 minutes ago Up 9 minutes 0.0.0.0:80->3000/tcp, 0.0.0.0:443->3443/tcp wiki 608de6278aaa requarks/wiki-update-companion:latest "dotnet wiki-update-…" 5 months ago Up 6 hours 80/tcp wiki-update-companion 12c7b35ba295 postgres:11 "docker-entrypoint.s…" 5 months ago Up 6 hours 5432/tcp db * Provide id to allow to query for tags * Update git storage to provide editorKey and tags --- server/modules/storage/disk/storage.js | 5 ++++- server/modules/storage/git/storage.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/server/modules/storage/disk/storage.js b/server/modules/storage/disk/storage.js index 8f4edce6..1c3a7c40 100644 --- a/server/modules/storage/disk/storage.js +++ b/server/modules/storage/disk/storage.js @@ -127,12 +127,15 @@ module.exports = { // -> Pages await pipeline( - WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt').select().from('pages').where({ + WIKI.models.knex.column('id', 'path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt', 'editorKey').select().from('pages').where({ isPrivate: false }).stream(), new stream.Transform({ objectMode: true, transform: async (page, enc, cb) => { + const pageObject = await WIKI.models.pages.query().findById(page.id) + page.tags = await pageObject.$relatedQuery('tags') + let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}` if (WIKI.config.lang.code !== page.localeCode) { fileName = `${page.localeCode}/${fileName}` diff --git a/server/modules/storage/git/storage.js b/server/modules/storage/git/storage.js index e9cf0b46..c023c7e8 100644 --- a/server/modules/storage/git/storage.js +++ b/server/modules/storage/git/storage.js @@ -411,12 +411,15 @@ module.exports = { // -> Pages await pipeline( - WIKI.models.knex.column('path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt').select().from('pages').where({ + WIKI.models.knex.column('id', 'path', 'localeCode', 'title', 'description', 'contentType', 'content', 'isPublished', 'updatedAt', 'createdAt', 'editorKey').select().from('pages').where({ isPrivate: false }).stream(), new stream.Transform({ objectMode: true, transform: async (page, enc, cb) => { + const pageObject = await WIKI.models.pages.query().findById(page.id) + page.tags = await pageObject.$relatedQuery('tags') + let fileName = `${page.path}.${pageHelper.getFileExtension(page.contentType)}` if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) { fileName = `${page.localeCode}/${fileName}`