|
|
@@ -16,7 +16,9 @@ import {
|
|
|
import {
|
|
|
PageDeleteConfigValue, IPageDeleteConfigValueToProcessValidation,
|
|
|
} from '~/interfaces/page-delete-config';
|
|
|
-import { IPageOperationProcessInfo, IPageOperationProcessData } from '~/interfaces/page-operation';
|
|
|
+import {
|
|
|
+ IPageOperationProcessInfo, IPageOperationProcessData, PageActionStage, PageActionType,
|
|
|
+} from '~/interfaces/page-operation';
|
|
|
import { IUserHasId } from '~/interfaces/user';
|
|
|
import { PageMigrationErrorData, SocketEventName, UpdateDescCountRawData } from '~/interfaces/websocket';
|
|
|
import {
|
|
|
@@ -28,7 +30,7 @@ import { prepareDeleteConfigValuesForCalc } from '~/utils/page-delete-config';
|
|
|
|
|
|
import { ObjectIdLike } from '../interfaces/mongoose-utils';
|
|
|
import { PathAlreadyExistsError } from '../models/errors';
|
|
|
-import PageOperation, { PageActionStage, PageActionType, PageOperationDocument } from '../models/page-operation';
|
|
|
+import PageOperation, { PageOperationDocument } from '../models/page-operation';
|
|
|
import { PageRedirectModel } from '../models/page-redirect';
|
|
|
import { serializePageSecurely } from '../models/serializers/page-serializer';
|
|
|
import Subscription from '../models/subscription';
|
|
|
@@ -417,7 +419,18 @@ class PageService {
|
|
|
logger.error('Failed to create PageOperation document.', err);
|
|
|
throw err;
|
|
|
}
|
|
|
- const renamedPage = await this.renameMainOperation(page, newPagePath, user, options, pageOp._id, activityParameters);
|
|
|
+ let renamedPage: PageDocument | null = null;
|
|
|
+ try {
|
|
|
+ renamedPage = await this.renameMainOperation(page, newPagePath, user, options, pageOp._id, activityParameters);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Error occurred while running renameMainOperation', err);
|
|
|
+
|
|
|
+ // cleanup
|
|
|
+ await PageOperation.deleteOne({ _id: pageOp._id });
|
|
|
+
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
if (!options.isRecursively) {
|
|
|
const parameters = {
|
|
|
targetModel: SupportedTargetModel.MODEL_PAGE,
|
|
|
@@ -426,7 +439,6 @@ class PageService {
|
|
|
};
|
|
|
this.activityEvent.emit('update', activityParameters.activityId, parameters, page);
|
|
|
}
|
|
|
-
|
|
|
return renamedPage;
|
|
|
}
|
|
|
|
|
|
@@ -1029,7 +1041,20 @@ class PageService {
|
|
|
logger.error('Failed to create PageOperation document.', err);
|
|
|
throw err;
|
|
|
}
|
|
|
- this.duplicateRecursivelyMainOperation(page, newPagePath, user, pageOp._id);
|
|
|
+
|
|
|
+ (async() => {
|
|
|
+ try {
|
|
|
+ await this.duplicateRecursivelyMainOperation(page, newPagePath, user, pageOp._id);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Error occurred while running duplicateRecursivelyMainOperation.', err);
|
|
|
+
|
|
|
+ // cleanup
|
|
|
+ await PageOperation.deleteOne({ _id: pageOp._id });
|
|
|
+
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ })();
|
|
|
}
|
|
|
|
|
|
const result = serializePageSecurely(duplicatedTarget);
|
|
|
@@ -1420,7 +1445,19 @@ class PageService {
|
|
|
/*
|
|
|
* Resumable Operation
|
|
|
*/
|
|
|
- this.deleteRecursivelyMainOperation(page, user, pageOp._id);
|
|
|
+ (async() => {
|
|
|
+ try {
|
|
|
+ await this.deleteRecursivelyMainOperation(page, user, pageOp._id);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Error occurred while running deleteRecursivelyMainOperation.', err);
|
|
|
+
|
|
|
+ // cleanup
|
|
|
+ await PageOperation.deleteOne({ _id: pageOp._id });
|
|
|
+
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ })();
|
|
|
}
|
|
|
|
|
|
return deletedPage;
|
|
|
@@ -1736,7 +1773,19 @@ class PageService {
|
|
|
/*
|
|
|
* Main Operation
|
|
|
*/
|
|
|
- this.deleteCompletelyRecursivelyMainOperation(page, user, options, pageOp._id);
|
|
|
+ (async() => {
|
|
|
+ try {
|
|
|
+ await this.deleteCompletelyRecursivelyMainOperation(page, user, options, pageOp._id);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Error occurred while running deleteCompletelyRecursivelyMainOperation.', err);
|
|
|
+
|
|
|
+ // cleanup
|
|
|
+ await PageOperation.deleteOne({ _id: pageOp._id });
|
|
|
+
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ })();
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
@@ -1944,7 +1993,19 @@ class PageService {
|
|
|
/*
|
|
|
* Resumable Operation
|
|
|
*/
|
|
|
- this.revertRecursivelyMainOperation(page, user, options, pageOp._id);
|
|
|
+ (async() => {
|
|
|
+ try {
|
|
|
+ await this.revertRecursivelyMainOperation(page, user, options, pageOp._id);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Error occurred while running revertRecursivelyMainOperation.', err);
|
|
|
+
|
|
|
+ // cleanup
|
|
|
+ await PageOperation.deleteOne({ _id: pageOp._id });
|
|
|
+
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ })();
|
|
|
}
|
|
|
|
|
|
return updatedPage;
|
|
|
@@ -2328,7 +2389,19 @@ class PageService {
|
|
|
throw err;
|
|
|
}
|
|
|
|
|
|
- this.normalizeParentRecursivelyMainOperation(page, user, pageOp._id);
|
|
|
+ (async() => {
|
|
|
+ try {
|
|
|
+ await this.normalizeParentRecursivelyMainOperation(page, user, pageOp._id);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Error occurred while running normalizeParentRecursivelyMainOperation.', err);
|
|
|
+
|
|
|
+ // cleanup
|
|
|
+ await PageOperation.deleteOne({ _id: pageOp._id });
|
|
|
+
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ })();
|
|
|
}
|
|
|
|
|
|
async normalizeParentByPageIdsRecursively(pageIds: ObjectIdLike[], user): Promise<void> {
|
|
|
@@ -2513,7 +2586,11 @@ class PageService {
|
|
|
}
|
|
|
catch (err) {
|
|
|
errorPagePaths.push(page.path);
|
|
|
- logger.err('Failed to run normalizeParentRecursivelyMainOperation.', err);
|
|
|
+ logger.error('Failed to run normalizeParentRecursivelyMainOperation.', err);
|
|
|
+
|
|
|
+ // cleanup
|
|
|
+ await PageOperation.deleteOne({ _id: pageOp._id });
|
|
|
+
|
|
|
throw err;
|
|
|
}
|
|
|
}
|