Kaynağa Gözat

initDB, isDBInitialized => appService

mizozobu 6 yıl önce
ebeveyn
işleme
f96e118d28

+ 1 - 1
src/server/models/config.js

@@ -165,7 +165,7 @@ module.exports = function(crowi) {
   }
 
   /**
-   * It is deprecated to use this for anything other than ConfigManager#isDBInitialized.
+   * It is deprecated to use this for anything other than AppService#isDBInitialized.
    */
   configSchema.statics.getConfigsObjectForInstalling = function() {
     return getConfigsForInstalling();

+ 2 - 2
src/server/routes/installer.js

@@ -4,7 +4,7 @@ module.exports = function(crowi, app) {
   const fs = require('graceful-fs');
 
   const models = crowi.models;
-  const configManager = crowi.configManager;
+  const { appService } = crowi;
 
   const User = models.User;
   const Page = models.Page;
@@ -67,7 +67,7 @@ module.exports = function(crowi, app) {
     const password = registerForm.password;
     const language = registerForm['app:globalLang'] || 'en-US';
 
-    await configManager.initDB(language);
+    await appService.initDB(language);
 
     // create first admin user
     let adminUser;

+ 14 - 0
src/server/service/app.js

@@ -35,6 +35,20 @@ class AppService {
   }
   /* eslint-enable no-else-return */
 
+  /**
+   * Execute only once for installing application
+   */
+  async initDB(globalLang) {
+    const initialConfig = this.configModel.getConfigsObjectForInstalling();
+    initialConfig['app:globalLang'] = globalLang;
+    await this.updateConfigsInTheSameNamespace('crowi', initialConfig);
+  }
+
+  async isDBInitialized() {
+    const appInstalled = await this.getConfigFromDB('crowi', 'app:installed');
+    return appInstalled;
+  }
+
 }
 
 module.exports = AppService;

+ 0 - 14
src/server/service/config-manager.js

@@ -180,20 +180,6 @@ class ConfigManager {
     await this.loadConfigs();
   }
 
-  /**
-   * Execute only once for installing application
-   */
-  async initDB(globalLang) {
-    const initialConfig = this.configModel.getConfigsObjectForInstalling();
-    initialConfig['app:globalLang'] = globalLang;
-    await this.updateConfigsInTheSameNamespace('crowi', initialConfig);
-  }
-
-  async isDBInitialized() {
-    const appInstalled = await this.getConfigFromDB('crowi', 'app:installed');
-    return appInstalled;
-  }
-
   /*
    * All of the methods below are private APIs.
    */

+ 3 - 2
src/server/util/middlewares.js

@@ -5,6 +5,7 @@ const md5 = require('md5');
 const entities = require('entities');
 
 module.exports = (crowi, app) => {
+  const { appService } = crowi;
 
   const middlewares = {};
 
@@ -274,7 +275,7 @@ module.exports = (crowi, app) => {
 
   // this is for Installer
   middlewares.applicationNotInstalled = async function(req, res, next) {
-    const isInstalled = await crowi.configManager.isDBInitialized();
+    const isInstalled = await appService.isDBInitialized();
 
     if (isInstalled) {
       req.flash('errorMessage', 'Application already installed.');
@@ -285,7 +286,7 @@ module.exports = (crowi, app) => {
   };
 
   middlewares.applicationInstalled = async function(req, res, next) {
-    const isInstalled = await crowi.configManager.isDBInitialized();
+    const isInstalled = await appService.isDBInitialized();
 
     if (!isInstalled) {
       return res.redirect('/installer');