Преглед изворни кода

add cleanup and mark methods for PageOperation

yohei0125 пре 4 година
родитељ
комит
3256bc788f

+ 13 - 2
packages/app/src/server/crowi/index.js

@@ -17,6 +17,7 @@ import loggerFactory from '~/utils/logger';
 import { projectRoot } from '~/utils/project-dir-utils';
 
 import Activity from '../models/activity';
+import PageOperation, { PageActionType } from '../models/page-operation';
 import PageRedirect from '../models/page-redirect';
 import UserGroup from '../models/user-group';
 import AclService from '../service/acl';
@@ -424,6 +425,9 @@ Crowi.prototype.start = async function() {
 
   await this.init();
   await this.buildServer();
+  // cleanup if PageOperationDocuments exist
+  await this.cleanupPageOperation();
+
 
   const { express, configManager } = this;
 
@@ -681,8 +685,6 @@ Crowi.prototype.setupPageService = async function() {
   }
   if (this.pageOperationService == null) {
     this.pageOperationService = new PageOperationService(this);
-    // TODO: Remove this code when resuming feature is implemented
-    await this.pageOperationService.init();
   }
 };
 
@@ -730,4 +732,13 @@ Crowi.prototype.setupSlackIntegrationService = async function() {
   }
 };
 
+Crowi.prototype.cleanupPageOperation = async function() {
+  if (PageOperation == null) return;
+
+  const excludeList = [PageActionType.Rename]; // list of ActionType to avoid being cleaned up
+  await PageOperation.cleanup(excludeList);
+  await PageOperation.markAsFailure();
+  logger.info('PageOperation cleaned up');
+};
+
 export default Crowi;

+ 8 - 0
packages/app/src/server/models/page-operation.ts

@@ -119,4 +119,12 @@ schema.statics.findMainOps = async function(
   );
 };
 
+schema.statics.cleanup = async function(excludeList: PageActionType[]): Promise<void> {
+  await this.deleteMany({ actionType: { $nin: excludeList } });
+};
+
+schema.statics.markAsFailure = async function(): Promise<void> {
+  await this.updateMany({}, { isFailure: true });
+};
+
 export default getOrCreateModel<PageOperationDocument, PageOperationModel>('PageOperation', schema);

+ 0 - 5
packages/app/src/server/service/page-operation.ts

@@ -12,11 +12,6 @@ class PageOperationService {
     this.crowi = crowi;
   }
 
-  // TODO: Remove this code when resuming feature is implemented
-  async init():Promise<void> {
-    await PageOperation.deleteMany({ actionType: { $ne: PageActionType.Rename } });
-  }
-
   /**
    * Check if the operation is operatable
    * @param isRecursively Boolean that determines whether the operation is recursive or not