diff --git a/server/core/db.js b/server/core/db.js index 2d614c55..25f21ad3 100644 --- a/server/core/db.js +++ b/server/core/db.js @@ -138,7 +138,7 @@ module.exports = { switch (WIKI.config.db.type) { case 'postgres': await conn.query(`set application_name = 'Wiki.js'`) - // -> Set schema if it's not public + // -> Set schema if it's not public if (WIKI.config.db.schema && WIKI.config.db.schema !== 'public') { await conn.query(`set search_path TO ${WIKI.config.db.schema}, public;`) } diff --git a/server/models/pages.js b/server/models/pages.js index dc54af9a..bb5b6585 100644 --- a/server/models/pages.js +++ b/server/models/pages.js @@ -725,7 +725,7 @@ module.exports = class Page extends Model { const destinationHash = pageHelper.generateHash({ path: opts.destinationPath, locale: opts.destinationLocale, privateNS: opts.isPrivate ? 'TODO' : '' }) // -> Move page - const destinationTitle = (page.title === page.path ? opts.destinationPath : page.title) + const destinationTitle = (page.title === _.last(page.path.split('/')) ? _.last(opts.destinationPath.split('/')) : page.title) await WIKI.models.pages.query().patch({ path: opts.destinationPath, localeCode: opts.destinationLocale, @@ -745,6 +745,7 @@ module.exports = class Page extends Model { ...page, destinationPath: opts.destinationPath, destinationLocaleCode: opts.destinationLocale, + title: destinationTitle, destinationHash }) diff --git a/server/modules/storage/disk/storage.js b/server/modules/storage/disk/storage.js index 1c3a7c40..8e4e4661 100644 --- a/server/modules/storage/disk/storage.js +++ b/server/modules/storage/disk/storage.js @@ -135,7 +135,7 @@ module.exports = { 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 0995445a..14b805ce 100644 --- a/server/modules/storage/git/storage.js +++ b/server/modules/storage/git/storage.js @@ -146,10 +146,24 @@ module.exports = { const diff = await this.git.diffSummary(['-M', currentCommitLog.hash, latestCommitLog.hash]) if (_.get(diff, 'files', []).length > 0) { let filesToProcess = [] + const filePattern = /(.*?)(?:{(.*?))? => (?:(.*?)})?(.*)/ for (const f of diff.files) { - const fMoved = f.file.split(' => ') - const fName = fMoved.length === 2 ? fMoved[1] : fMoved[0] - const fPath = path.join(this.repoPath, fName) + const fMatch = f.file.match(filePattern) + const fNames = { + old: null, + new: null + } + if (!fMatch) { + fNames.old = f.file + fNames.new = f.file + } else if (!fMatch[2] && !fMatch[3]) { + fNames.old = fMatch[1] + fNames.new = fMatch[4] + } else { + fNames.old = (fMatch[1]+fMatch[2]+fMatch[4]).replace('//', '/'), + fNames.new = (fMatch[1]+fMatch[3]+fMatch[4]).replace('//', '/') + } + const fPath = path.join(this.repoPath, fNames.new) let fStats = { size: 0 } try { fStats = await fs.stat(fPath) @@ -166,8 +180,8 @@ module.exports = { path: fPath, stats: fStats }, - oldPath: fMoved[0], - relPath: fName + oldPath: fNames.old, + relPath: fNames.new }) } await this.processFiles(filesToProcess, rootUser)