|
|
@@ -1,33 +1,36 @@
|
|
|
+import pathlib from 'path';
|
|
|
+import { Readable, Writable } from 'stream';
|
|
|
+
|
|
|
import { pagePathUtils, pathUtils } from '@growi/core';
|
|
|
-import mongoose, { ObjectId, QueryCursor } from 'mongoose';
|
|
|
import escapeStringRegexp from 'escape-string-regexp';
|
|
|
+import mongoose, { ObjectId, QueryCursor } from 'mongoose';
|
|
|
import streamToPromise from 'stream-to-promise';
|
|
|
-import pathlib from 'path';
|
|
|
-import { Readable, Writable } from 'stream';
|
|
|
|
|
|
-import { createBatchStream } from '~/server/util/batch-stream';
|
|
|
-import loggerFactory from '~/utils/logger';
|
|
|
-import {
|
|
|
- CreateMethod, PageCreateOptions, PageModel, PageDocument,
|
|
|
-} from '~/server/models/page';
|
|
|
-import { stringifySnapshot } from '~/models/serializers/in-app-notification-snapshot/page';
|
|
|
+import { Ref } from '~/interfaces/common';
|
|
|
+import { HasObjectId } from '~/interfaces/has-object-id';
|
|
|
import {
|
|
|
IPage, IPageInfo, IPageInfoForEntity, IPageWithMeta,
|
|
|
} from '~/interfaces/page';
|
|
|
-import { serializePageSecurely } from '../models/serializers/page-serializer';
|
|
|
-import { PageRedirectModel } from '../models/page-redirect';
|
|
|
-import Subscription from '../models/subscription';
|
|
|
-import { ObjectIdLike } from '../interfaces/mongoose-utils';
|
|
|
-import { IUserHasId } from '~/interfaces/user';
|
|
|
-import { Ref } from '~/interfaces/common';
|
|
|
-import { HasObjectId } from '~/interfaces/has-object-id';
|
|
|
-import { SocketEventName, UpdateDescCountRawData } from '~/interfaces/websocket';
|
|
|
import {
|
|
|
PageDeleteConfigValue, IPageDeleteConfigValueToProcessValidation,
|
|
|
} from '~/interfaces/page-delete-config';
|
|
|
+import { IUserHasId } from '~/interfaces/user';
|
|
|
+import { SocketEventName, UpdateDescCountRawData } from '~/interfaces/websocket';
|
|
|
+import { stringifySnapshot } from '~/models/serializers/in-app-notification-snapshot/page';
|
|
|
+import {
|
|
|
+ CreateMethod, PageCreateOptions, PageModel, PageDocument,
|
|
|
+} from '~/server/models/page';
|
|
|
+import { createBatchStream } from '~/server/util/batch-stream';
|
|
|
+import loggerFactory from '~/utils/logger';
|
|
|
+import { prepareDeleteConfigValuesForCalc } from '~/utils/page-delete-config';
|
|
|
+
|
|
|
+import { ObjectIdLike } from '../interfaces/mongoose-utils';
|
|
|
import PageOperation, { PageActionStage, PageActionType } from '../models/page-operation';
|
|
|
+import { PageRedirectModel } from '../models/page-redirect';
|
|
|
+import { serializePageSecurely } from '../models/serializers/page-serializer';
|
|
|
+import Subscription from '../models/subscription';
|
|
|
import ActivityDefine from '../util/activityDefine';
|
|
|
-import { prepareDeleteConfigValuesForCalc } from '~/utils/page-delete-config';
|
|
|
+
|
|
|
|
|
|
const debug = require('debug')('growi:services:page');
|
|
|
|
|
|
@@ -559,6 +562,25 @@ class PageService {
|
|
|
await PageOperation.findByIdAndDelete(pageOpId);
|
|
|
}
|
|
|
|
|
|
+ async restartPageRenameOperation(operator: IUserHasId, pageId: ObjectIdLike): Promise<void> {
|
|
|
+
|
|
|
+ if (operator == null) {
|
|
|
+ throw new Error('This operation is not allowed for guest users');
|
|
|
+ }
|
|
|
+
|
|
|
+ const pageOp = await PageOperation.findOne({ 'page.id': pageId });
|
|
|
+ if (pageOp == null || pageOp.toPath == null) throw Error('PageRenameOperation is not executable');
|
|
|
+
|
|
|
+ pageOp.actionStage = PageActionStage.Main; // to restart from the beginning
|
|
|
+ const page = pageOp.page;
|
|
|
+ const newPagePath = pageOp.toPath;
|
|
|
+ const user = pageOp.user;
|
|
|
+ const options = pageOp.options;
|
|
|
+ const pageOpId = pageOp._id;
|
|
|
+
|
|
|
+ await this.renameMainOperation(page, newPagePath, user, options, pageOpId);
|
|
|
+ }
|
|
|
+
|
|
|
private isRenamingToUnderTarget(fromPath: string, toPath: string): boolean {
|
|
|
const pathToTest = escapeStringRegexp(addTrailingSlash(fromPath));
|
|
|
const pathToBeTested = toPath;
|