Browse Source

refactor installation

Yuki Takei 4 years ago
parent
commit
99242f4f57

+ 2 - 15
packages/app/src/server/service/app.ts

@@ -2,8 +2,6 @@ import { pathUtils } from '@growi/core';
 
 
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
-import { generateConfigsForInstalling } from '../models/config';
-
 import S2sMessage from '../models/vo/s2s-message';
 import S2sMessage from '../models/vo/s2s-message';
 import { S2sMessageHandlable } from './s2s-messaging/handlable';
 import { S2sMessageHandlable } from './s2s-messaging/handlable';
 import { S2sMessagingService } from './s2s-messaging/base';
 import { S2sMessagingService } from './s2s-messaging/base';
@@ -101,15 +99,6 @@ export default class AppService implements S2sMessageHandlable {
     return this.configManager.getConfig('crowi', 'app:confidential');
     return this.configManager.getConfig('crowi', 'app:confidential');
   }
   }
 
 
-  /**
-   * Execute only once for installing application
-   */
-  async initDB(globalLang) {
-    const initialConfig = generateConfigsForInstalling();
-    initialConfig['app:globalLang'] = globalLang;
-    await this.configManager.updateConfigsInTheSameNamespace('crowi', initialConfig, true);
-  }
-
   async isDBInitialized(forceReload) {
   async isDBInitialized(forceReload) {
     if (forceReload) {
     if (forceReload) {
       // load configs
       // load configs
@@ -118,10 +107,8 @@ export default class AppService implements S2sMessageHandlable {
     return this.configManager.getConfigFromDB('crowi', 'app:installed');
     return this.configManager.getConfigFromDB('crowi', 'app:installed');
   }
   }
 
 
-  async setupAfterInstall() {
-    await this.crowi.pluginService.autoDetectAndLoadPlugins();
-    this.crowi.setupRoutesAtLast();
-    this.crowi.setupGlobalErrorHandlers();
+  setupAfterInstall() {
+    this.publishPostInstallationMessage();
 
 
     // remove message handler
     // remove message handler
     const { s2sMessagingService } = this;
     const { s2sMessagingService } = this;

+ 22 - 4
packages/app/src/server/service/installer.ts

@@ -7,8 +7,11 @@ import { IPage } from '~/interfaces/page';
 import { IUser } from '~/interfaces/user';
 import { IUser } from '~/interfaces/user';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
+import { generateConfigsForInstalling } from '../models/config';
+
 import AppService from './app';
 import AppService from './app';
 import SearchService from './search';
 import SearchService from './search';
+import ConfigManager from './config-manager';
 
 
 const logger = loggerFactory('growi:service:installer');
 const logger = loggerFactory('growi:service:installer');
 
 
@@ -74,10 +77,19 @@ export class InstallerService {
     }
     }
   }
   }
 
 
-  async install(firstAdminUserToSave: IUser, language: string): Promise<IUser> {
-    const appService: AppService = this.crowi.appService;
+  /**
+   * Execute only once for installing application
+   */
+  private async initDB(globalLang: string): Promise<void> {
+    const configManager: ConfigManager = this.crowi.configManager;
 
 
-    await appService.initDB(language);
+    const initialConfig = generateConfigsForInstalling();
+    initialConfig['app:globalLang'] = globalLang;
+    return configManager.updateConfigsInTheSameNamespace('crowi', initialConfig, true);
+  }
+
+  async install(firstAdminUserToSave: IUser, language: string): Promise<IUser> {
+    await this.initDB(language);
 
 
     // TODO typescriptize models/user.js and remove eslint-disable-next-line
     // TODO typescriptize models/user.js and remove eslint-disable-next-line
     // eslint-disable-next-line @typescript-eslint/no-explicit-any
     // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -100,8 +112,14 @@ export class InstallerService {
     // create initial pages
     // create initial pages
     await this.createInitialPages(adminUser, language);
     await this.createInitialPages(adminUser, language);
 
 
+    const pluginService = this.crowi.pluginService;
+    await pluginService.autoDetectAndLoadPlugins();
+
+    this.crowi.setupRoutesAtLast();
+    this.crowi.setupGlobalErrorHandlers();
+
+    const appService: AppService = this.crowi.appService;
     appService.setupAfterInstall();
     appService.setupAfterInstall();
-    appService.publishPostInstallationMessage();
 
 
     return adminUser;
     return adminUser;
   }
   }