소스 검색

implement executeAllRenameOperationBySystem temp

yohei0125 3 년 전
부모
커밋
ec878f3607
2개의 변경된 파일32개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      packages/app/src/server/crowi/index.js
  2. 23 0
      packages/app/src/server/service/page-operation.ts

+ 9 - 0
packages/app/src/server/crowi/index.js

@@ -150,6 +150,13 @@ Crowi.prototype.init = async function() {
   await this.autoInstall();
   await this.autoInstall();
 };
 };
 
 
+Crowi.prototype.afterInit = async function() {
+  if (this.pageOperationService != null) {
+    await this.pageOperationService.onAfterInit();
+  }
+};
+
+
 Crowi.prototype.isPageId = function(pageId) {
 Crowi.prototype.isPageId = function(pageId) {
   if (!pageId) {
   if (!pageId) {
     return false;
     return false;
@@ -470,6 +477,8 @@ Crowi.prototype.start = async function() {
   // setup Global Error Handlers
   // setup Global Error Handlers
   this.setupGlobalErrorHandlers();
   this.setupGlobalErrorHandlers();
 
 
+  this.afterInit();
+
   return serverListening;
   return serverListening;
 };
 };
 
 

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

@@ -25,6 +25,29 @@ class PageOperationService {
     await PageOperation.deleteByActionTypes(types);
     await PageOperation.deleteByActionTypes(types);
   }
   }
 
 
+  async onAfterInit():Promise<void> {
+    await this.executeAllRenameOperationBySystem();
+  }
+
+  // サーバー起動時にDBに残っている actionType が Rename の PageOperation をすべて、createdAt の古いものから順番に実行
+  async executeAllRenameOperationBySystem(): Promise<void> {
+    const Page = this.crowi.model('Page');
+
+    const pageOps = await PageOperation.find({ actionType: PageActionType.Rename }).sort({ createdAt: 1 });
+    if (pageOps.length === 0) return;
+
+    for await (const pageOp of pageOps) {
+      const {
+        page, toPath, options, user,
+      } = pageOp;
+
+      const renamedPage = await Page.findById(pageOp.page._id);
+
+      // rename 実行
+      await this.crowi.pageService.renameSubOperation(page, toPath, user, options, renamedPage, pageOp._id);
+    }
+  }
+
   /**
   /**
    * Check if the operation is operatable
    * Check if the operation is operatable
    * @param isRecursively Boolean that determines whether the operation is recursive or not
    * @param isRecursively Boolean that determines whether the operation is recursive or not