Taichi Masuyama 3 лет назад
Родитель
Сommit
7915f3fddd

+ 1 - 5
packages/app/src/server/routes/apiv3/import.js

@@ -294,11 +294,7 @@ export default function route(crowi) {
      * import
      */
     try {
-      (async() => {
-        await importService.updateIsV5CompatibleBeforeImport(collections);
-        await importService.import(collections, importSettingsMap);
-        await importService.normalizeAllPublicPagesAfterImport(collections);
-      })();
+      importService.import(collections, importSettingsMap);
 
       const parameters = { action: SupportedAction.ACTION_ADMIN_GROWI_DATA_IMPORTED };
       activityEvent.emit('update', res.locals.activity._id, parameters);

+ 2 - 11
packages/app/src/server/service/g2g-transfer.ts

@@ -600,15 +600,6 @@ export class G2GTransferReceiverService implements Receiver {
     return importSettingsMap;
   }
 
-  private async processImportWithPrePostProcess(
-      collections: string[],
-      importSettingsMap: { [key: string]: ImportSettings; },
-  ): Promise<void> {
-    await this.crowi.importService.updateIsV5CompatibleBeforeImport(collections);
-    await this.crowi.importService.import(collections, importSettingsMap);
-    await this.crowi.importService.normalizeAllPublicPagesAfterImport(collections);
-  }
-
   public async importCollections(
       collections: string[],
       importSettingsMap: { [key: string]: ImportSettings; },
@@ -623,7 +614,7 @@ export class G2GTransferReceiverService implements Receiver {
       const fileUploadConfigs = await this.getFileUploadConfigs();
 
       // import mongo collections(overwrites file uplaod configs)
-      await this.processImportWithPrePostProcess(collections, importSettingsMap);
+      await importService.import(collections, importSettingsMap);
 
       // restore file upload config from cache
       await configManager.removeConfigsInTheSameNamespace('crowi', UPLOAD_CONFIG_KEYS);
@@ -631,7 +622,7 @@ export class G2GTransferReceiverService implements Receiver {
     }
     else {
       // import mongo collections(overwrites file uplaod configs)
-      await this.processImportWithPrePostProcess(collections, importSettingsMap);
+      await importService.import(collections, importSettingsMap);
 
       // update file upload config
       await configManager.updateConfigsInTheSameNamespace('crowi', sourceGROWIUploadConfigs);

+ 8 - 26
packages/app/src/server/service/import.js

@@ -173,37 +173,15 @@ class ImportService {
     };
   }
 
-  /**
-   * Calculate whether page normalization is required
-   *
-   * @param {string} collections MongoDB collection name
-   */
-  async getShouldNormalizePages(collections) {
-    const isV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
-    const isImportPagesCollection = collections.includes('pages');
-    const shouldNormalizePages = isV5Compatible && isImportPagesCollection;
-
-    return shouldNormalizePages;
-  }
-
-  /**
-   * Update the config app:isV5Compatible to false when page normalization is required
-   *
-   * @param {string} collections MongoDB collection name
-   */
-  async updateIsV5CompatibleBeforeImport(collections) {
-    const shouldNormalizePages = this.getShouldNormalizePages(collections);
-
-    if (shouldNormalizePages) await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', { 'app:isV5Compatible': false });
-  }
-
   /**
    * Run pageService.normalizeAllPublicPages when page normalization is required
    *
    * @param {string} collections MongoDB collection name
+   * @param {boolean} isV5Compatible Whether pages are v5 compatible
+   * @param {boolean} isImportPagesCollection Whether importing pages collection
    */
-  async normalizeAllPublicPagesAfterImport(collections) {
-    const shouldNormalizePages = this.getShouldNormalizePages(collections);
+  async _normalizeAllPublicPagesAfterImport(collections, isV5Compatible, isImportPagesCollection) {
+    const shouldNormalizePages = isV5Compatible && isImportPagesCollection;
 
     if (shouldNormalizePages) await this.crowi.pageService.normalizeAllPublicPages();
   }
@@ -239,6 +217,10 @@ class ImportService {
     this.emitTerminateEvent();
 
     await this.crowi.configManager.loadConfigs();
+
+    const currentIsV5Compatible = this.crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
+    const isImportPagesCollection = collections.includes('pages');
+    await this._normalizeAllPublicPagesAfterImport(collections, currentIsV5Compatible, isImportPagesCollection);
   }
 
   /**