|
@@ -5,11 +5,11 @@ import type {
|
|
|
Ref, HasObjectId, IUserHasId,
|
|
Ref, HasObjectId, IUserHasId,
|
|
|
IPage, IPageInfo, IPageInfoAll, IPageInfoForEntity, IPageWithMeta,
|
|
IPage, IPageInfo, IPageInfoAll, IPageInfoForEntity, IPageWithMeta,
|
|
|
} from '@growi/core';
|
|
} from '@growi/core';
|
|
|
-import { PageGrant, PageStatus } from '@growi/core';
|
|
|
|
|
|
|
+import { PageGrant, PageStatus, getIdForRef } from '@growi/core';
|
|
|
import {
|
|
import {
|
|
|
pagePathUtils, pathUtils,
|
|
pagePathUtils, pathUtils,
|
|
|
} from '@growi/core/dist/utils';
|
|
} from '@growi/core/dist/utils';
|
|
|
-import { collectAncestorPaths } from '@growi/core/dist/utils/page-path-utils';
|
|
|
|
|
|
|
+import { collectAncestorPaths, isUsersHomepage } from '@growi/core/dist/utils/page-path-utils';
|
|
|
import escapeStringRegexp from 'escape-string-regexp';
|
|
import escapeStringRegexp from 'escape-string-regexp';
|
|
|
import mongoose, { ObjectId, Cursor } from 'mongoose';
|
|
import mongoose, { ObjectId, Cursor } from 'mongoose';
|
|
|
import streamToPromise from 'stream-to-promise';
|
|
import streamToPromise from 'stream-to-promise';
|
|
@@ -1972,24 +1972,38 @@ class PageService {
|
|
|
* @throws {Error} - If an error occurs during the deletion process.
|
|
* @throws {Error} - If an error occurs during the deletion process.
|
|
|
*/
|
|
*/
|
|
|
async deleteCompletelyUserHomeBySystem(userHomepagePath: string): Promise<void> {
|
|
async deleteCompletelyUserHomeBySystem(userHomepagePath: string): Promise<void> {
|
|
|
- const Page = this.crowi.model('Page');
|
|
|
|
|
|
|
+ if (!isUsersHomepage(userHomepagePath)) {
|
|
|
|
|
+ const msg = 'input value is not user homepage path.';
|
|
|
|
|
+ logger.error(msg);
|
|
|
|
|
+ throw new Error(msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const Page = mongoose.model<IPage, PageModel>('Page');
|
|
|
const userHomepage = await Page.findByPath(userHomepagePath, true);
|
|
const userHomepage = await Page.findByPath(userHomepagePath, true);
|
|
|
|
|
|
|
|
if (userHomepage == null) {
|
|
if (userHomepage == null) {
|
|
|
- logger.error('user homepage is not found.');
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ const msg = 'user homepage is not found.';
|
|
|
|
|
+ logger.error(msg);
|
|
|
|
|
+ throw new Error(msg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (userHomepage.parent == null) {
|
|
|
|
|
+ const msg = 'user homepage parent is not found.';
|
|
|
|
|
+ logger.error(msg);
|
|
|
|
|
+ throw new Error(msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const shouldUseV4Process = this.shouldUseV4Process(userHomepage);
|
|
const shouldUseV4Process = this.shouldUseV4Process(userHomepage);
|
|
|
|
|
|
|
|
const ids = [userHomepage._id];
|
|
const ids = [userHomepage._id];
|
|
|
const paths = [userHomepage.path];
|
|
const paths = [userHomepage.path];
|
|
|
|
|
+ const parentId = getIdForRef(userHomepage.parent);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
if (!shouldUseV4Process) {
|
|
if (!shouldUseV4Process) {
|
|
|
// Ensure consistency of ancestors
|
|
// Ensure consistency of ancestors
|
|
|
const inc = userHomepage.isEmpty ? -userHomepage.descendantCount : -(userHomepage.descendantCount + 1);
|
|
const inc = userHomepage.isEmpty ? -userHomepage.descendantCount : -(userHomepage.descendantCount + 1);
|
|
|
- await this.updateDescendantCountOfAncestors(userHomepage.parent, inc, true);
|
|
|
|
|
|
|
+ await this.updateDescendantCountOfAncestors(parentId, inc, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Delete the user's homepage
|
|
// Delete the user's homepage
|
|
@@ -1997,7 +2011,7 @@ class PageService {
|
|
|
|
|
|
|
|
if (!shouldUseV4Process) {
|
|
if (!shouldUseV4Process) {
|
|
|
// Remove leaf empty pages
|
|
// Remove leaf empty pages
|
|
|
- await Page.removeLeafEmptyPagesRecursively(userHomepage.parent);
|
|
|
|
|
|
|
+ await Page.removeLeafEmptyPagesRecursively(parentId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!userHomepage.isEmpty) {
|
|
if (!userHomepage.isEmpty) {
|
|
@@ -2010,7 +2024,7 @@ class PageService {
|
|
|
// Find descendant pages with system deletion condition
|
|
// Find descendant pages with system deletion condition
|
|
|
const builder = new PageQueryBuilder(Page.find(), true)
|
|
const builder = new PageQueryBuilder(Page.find(), true)
|
|
|
.addConditionForSystemDeletion()
|
|
.addConditionForSystemDeletion()
|
|
|
- .addConditionToListOnlyDescendants(userHomepage.path);
|
|
|
|
|
|
|
+ .addConditionToListOnlyDescendants(userHomepage.path, {});
|
|
|
|
|
|
|
|
// Stream processing to delete descendant pages
|
|
// Stream processing to delete descendant pages
|
|
|
// ────────┤ start │─────────
|
|
// ────────┤ start │─────────
|