|
@@ -350,15 +350,15 @@ class PageService {
|
|
|
.cursor({ batchSize: BULK_REINDEX_SIZE });
|
|
.cursor({ batchSize: BULK_REINDEX_SIZE });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async renamePage(page: IPage, newPagePath, user, options, nOptions): Promise<PageDocument | null> {
|
|
|
|
|
|
|
+ async renamePage(page: IPage, newPagePath, user, options, activityParameters): Promise<PageDocument | null> {
|
|
|
/*
|
|
/*
|
|
|
* Common Operation
|
|
* Common Operation
|
|
|
*/
|
|
*/
|
|
|
const Page = mongoose.model('Page') as unknown as PageModel;
|
|
const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
|
|
|
|
|
const parameters = {
|
|
const parameters = {
|
|
|
- ip: nOptions.ip,
|
|
|
|
|
- endpoint: nOptions.endpoint,
|
|
|
|
|
|
|
+ ip: activityParameters.ip,
|
|
|
|
|
+ endpoint: activityParameters.endpoint,
|
|
|
action: page.descendantCount > 0 ? SupportedAction.ACTION_PAGE_RECURSIVELY_RENAME : SupportedAction.ACTION_PAGE_RENAME,
|
|
action: page.descendantCount > 0 ? SupportedAction.ACTION_PAGE_RECURSIVELY_RENAME : SupportedAction.ACTION_PAGE_RENAME,
|
|
|
user,
|
|
user,
|
|
|
snapshot: {
|
|
snapshot: {
|
|
@@ -417,20 +417,20 @@ class PageService {
|
|
|
logger.error('Failed to create PageOperation document.', err);
|
|
logger.error('Failed to create PageOperation document.', err);
|
|
|
throw err;
|
|
throw err;
|
|
|
}
|
|
}
|
|
|
- const renamedPage = await this.renameMainOperation(page, newPagePath, user, options, pageOp._id, nOptions);
|
|
|
|
|
|
|
+ const renamedPage = await this.renameMainOperation(page, newPagePath, user, options, pageOp._id, activityParameters);
|
|
|
if (!options.isRecursively) {
|
|
if (!options.isRecursively) {
|
|
|
const parameters = {
|
|
const parameters = {
|
|
|
targetModel: SupportedTargetModel.MODEL_PAGE,
|
|
targetModel: SupportedTargetModel.MODEL_PAGE,
|
|
|
target: page,
|
|
target: page,
|
|
|
action: SupportedAction.ACTION_PAGE_RENAME,
|
|
action: SupportedAction.ACTION_PAGE_RENAME,
|
|
|
};
|
|
};
|
|
|
- this.activityEvent.emit('update', nOptions.activityId, parameters, page);
|
|
|
|
|
|
|
+ this.activityEvent.emit('update', activityParameters.activityId, parameters, page);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return renamedPage;
|
|
return renamedPage;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async renameMainOperation(page, newPagePath: string, user, options, pageOpId: ObjectIdLike, nOptions): Promise<PageDocument | null> {
|
|
|
|
|
|
|
+ async renameMainOperation(page, newPagePath: string, user, options, pageOpId: ObjectIdLike, activityParameters): Promise<PageDocument | null> {
|
|
|
const Page = mongoose.model('Page') as unknown as PageModel;
|
|
const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
|
|
|
|
|
const updateMetadata = options.updateMetadata || false;
|
|
const updateMetadata = options.updateMetadata || false;
|
|
@@ -515,12 +515,12 @@ class PageService {
|
|
|
/*
|
|
/*
|
|
|
* Sub Operation
|
|
* Sub Operation
|
|
|
*/
|
|
*/
|
|
|
- this.renameSubOperation(page, newPagePath, user, options, renamedPage, pageOp._id, nOptions);
|
|
|
|
|
|
|
+ this.renameSubOperation(page, newPagePath, user, options, renamedPage, pageOp._id, activityParameters);
|
|
|
|
|
|
|
|
return renamedPage;
|
|
return renamedPage;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async renameSubOperation(page, newPagePath: string, user, options, renamedPage, pageOpId: ObjectIdLike, nOptions?): Promise<void> {
|
|
|
|
|
|
|
+ async renameSubOperation(page, newPagePath: string, user, options, renamedPage, pageOpId: ObjectIdLike, activityParameters?): Promise<void> {
|
|
|
const Page = mongoose.model('Page') as unknown as PageModel;
|
|
const Page = mongoose.model('Page') as unknown as PageModel;
|
|
|
|
|
|
|
|
const exParentId = page.parent;
|
|
const exParentId = page.parent;
|
|
@@ -534,7 +534,7 @@ class PageService {
|
|
|
try {
|
|
try {
|
|
|
// update descendants first
|
|
// update descendants first
|
|
|
const descendantPages = await this.renameDescendantsWithStream(page, newPagePath, user, options, false);
|
|
const descendantPages = await this.renameDescendantsWithStream(page, newPagePath, user, options, false);
|
|
|
- this.activityEvent.emit('update', nOptions.activityId, parameters, page, descendantPages);
|
|
|
|
|
|
|
+ this.activityEvent.emit('update', activityParameters.activityId, parameters, page, descendantPages);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.warn(err);
|
|
logger.warn(err);
|
|
@@ -565,7 +565,7 @@ class PageService {
|
|
|
await PageOperation.findByIdAndDelete(pageOpId);
|
|
await PageOperation.findByIdAndDelete(pageOpId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async resumeRenameSubOperation(renamedPage: PageDocument, pageOp: PageOperationDocument, nOptions?): Promise<void> {
|
|
|
|
|
|
|
+ async resumeRenameSubOperation(renamedPage: PageDocument, pageOp: PageOperationDocument, activityParameters?): Promise<void> {
|
|
|
const isProcessable = pageOp.isProcessable();
|
|
const isProcessable = pageOp.isProcessable();
|
|
|
if (!isProcessable) {
|
|
if (!isProcessable) {
|
|
|
throw Error('This page operation is currently being processed');
|
|
throw Error('This page operation is currently being processed');
|
|
@@ -578,7 +578,7 @@ class PageService {
|
|
|
page, fromPath, toPath, options, user,
|
|
page, fromPath, toPath, options, user,
|
|
|
} = pageOp;
|
|
} = pageOp;
|
|
|
|
|
|
|
|
- this.fixPathsAndDescendantCountOfAncestors(page, user, options, renamedPage, pageOp._id, fromPath, toPath, nOptions);
|
|
|
|
|
|
|
+ this.fixPathsAndDescendantCountOfAncestors(page, user, options, renamedPage, pageOp._id, fromPath, toPath, activityParameters);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -586,8 +586,8 @@ class PageService {
|
|
|
* `renameSubOperation` to restart rename operation
|
|
* `renameSubOperation` to restart rename operation
|
|
|
* `updateDescendantCountOfPagesWithPaths` to fix descendantCount of ancestors
|
|
* `updateDescendantCountOfPagesWithPaths` to fix descendantCount of ancestors
|
|
|
*/
|
|
*/
|
|
|
- private async fixPathsAndDescendantCountOfAncestors(page, user, options, renamedPage, pageOpId, fromPath, toPath, nOptions?): Promise<void> {
|
|
|
|
|
- await this.renameSubOperation(page, toPath, user, options, renamedPage, pageOpId, nOptions);
|
|
|
|
|
|
|
+ private async fixPathsAndDescendantCountOfAncestors(page, user, options, renamedPage, pageOpId, fromPath, toPath, activityParameters?): Promise<void> {
|
|
|
|
|
+ await this.renameSubOperation(page, toPath, user, options, renamedPage, pageOpId, activityParameters);
|
|
|
const ancestorsPaths = this.crowi.pageOperationService.getAncestorsPathsByFromAndToPath(fromPath, toPath);
|
|
const ancestorsPaths = this.crowi.pageOperationService.getAncestorsPathsByFromAndToPath(fromPath, toPath);
|
|
|
await this.updateDescendantCountOfPagesWithPaths(ancestorsPaths);
|
|
await this.updateDescendantCountOfPagesWithPaths(ancestorsPaths);
|
|
|
}
|
|
}
|