|
@@ -434,19 +434,13 @@ class PageService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const pathToTest = escapeStringRegexp(addTrailingSlash(page.path));
|
|
|
|
|
- const pathToBeTested = newPagePath;
|
|
|
|
|
- const isRenamingToUnderExTarget = (new RegExp(`^${pathToTest}`)).test(pathToBeTested);
|
|
|
|
|
-
|
|
|
|
|
// 1. Take target off from tree
|
|
// 1. Take target off from tree
|
|
|
await Page.takeOffFromTree(page._id);
|
|
await Page.takeOffFromTree(page._id);
|
|
|
- console.log('00000', newPagePath, await Page.count({ path: page.path }), await Page.find({ path: page.path }).lean().exec());
|
|
|
|
|
|
|
|
|
|
// 2. Find new parent
|
|
// 2. Find new parent
|
|
|
const update: Partial<IPage> = {};
|
|
const update: Partial<IPage> = {};
|
|
|
// find or create parent
|
|
// find or create parent
|
|
|
const newParent = await Page.getParentAndFillAncestors(newPagePath);
|
|
const newParent = await Page.getParentAndFillAncestors(newPagePath);
|
|
|
- console.log('11111', newPagePath, await Page.count({ path: page.path }), await Page.find({ path: page.path }).lean().exec());
|
|
|
|
|
|
|
|
|
|
// 3. Put back target page to tree (also update the other attrs)
|
|
// 3. Put back target page to tree (also update the other attrs)
|
|
|
update.path = newPagePath;
|
|
update.path = newPagePath;
|
|
@@ -456,12 +450,6 @@ class PageService {
|
|
|
update.updatedAt = new Date();
|
|
update.updatedAt = new Date();
|
|
|
}
|
|
}
|
|
|
const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
|
|
const renamedPage = await Page.findByIdAndUpdate(page._id, { $set: update }, { new: true });
|
|
|
- console.log('2w222', await Page.count({ path: page.path }), await Page.find({ path: page.path }).lean().exec());
|
|
|
|
|
- // Remove leaf empty pages if not moving to under the ex-target position
|
|
|
|
|
- if (!isRenamingToUnderExTarget) {
|
|
|
|
|
- // remove empty pages at leaf position
|
|
|
|
|
- await Page.removeLeafEmptyPagesRecursively(page.parent);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
// create page redirect
|
|
// create page redirect
|
|
|
if (options.createRedirectPage) {
|
|
if (options.createRedirectPage) {
|
|
@@ -498,6 +486,15 @@ class PageService {
|
|
|
const nToIncrease = (renamedPage.isEmpty ? 0 : 1) + page.descendantCount;
|
|
const nToIncrease = (renamedPage.isEmpty ? 0 : 1) + page.descendantCount;
|
|
|
await this.updateDescendantCountOfAncestors(renamedPage._id, nToIncrease, false);
|
|
await this.updateDescendantCountOfAncestors(renamedPage._id, nToIncrease, false);
|
|
|
|
|
|
|
|
|
|
+ // Remove leaf empty pages if not moving to under the ex-target position
|
|
|
|
|
+ const pathToTest = escapeStringRegexp(addTrailingSlash(page.path));
|
|
|
|
|
+ const pathToBeTested = newPagePath;
|
|
|
|
|
+ const isRenamingToUnderExTarget = (new RegExp(`^${pathToTest}`)).test(pathToBeTested);
|
|
|
|
|
+ if (!isRenamingToUnderExTarget) {
|
|
|
|
|
+ // remove empty pages at leaf position
|
|
|
|
|
+ await Page.removeLeafEmptyPagesRecursively(page.parent);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
await PageOperation.findByIdAndDelete(pageOpId);
|
|
await PageOperation.findByIdAndDelete(pageOpId);
|
|
|
}
|
|
}
|
|
|
|
|
|