|
@@ -1,7 +1,16 @@
|
|
|
|
|
+const ConfigLoader = require('../service/config-loader')
|
|
|
|
|
+ , debug = require('debug')('growi:models:config');
|
|
|
|
|
+
|
|
|
class ConfigManager {
|
|
class ConfigManager {
|
|
|
|
|
|
|
|
- constructor(configObject) {
|
|
|
|
|
- this.configObject = configObject;
|
|
|
|
|
|
|
+ constructor(configModel) {
|
|
|
|
|
+ this.configModel = configModel;
|
|
|
|
|
+ this.configLoader = new ConfigLoader(this.configModel);
|
|
|
|
|
+ this.configObject = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async loadConfigs() {
|
|
|
|
|
+ this.configObject = await this.configLoader.load();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
getConfig(namespace, key) {
|
|
getConfig(namespace, key) {
|
|
@@ -9,13 +18,27 @@ class ConfigManager {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
defaultSearch(namespace, key) {
|
|
defaultSearch(namespace, key) {
|
|
|
- if (this.configObject['fromDB'][namespace][key] !== undefined) {
|
|
|
|
|
- return this.configObject['fromDB'][namespace][key];
|
|
|
|
|
|
|
+ if (this.configObject.fromDB[namespace][key] !== undefined) {
|
|
|
|
|
+ return this.configObject.fromDB[namespace][key];
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- return this.configObject['fromEnvVars'][namespace][key];
|
|
|
|
|
|
|
+ return this.configObject.fromEnvVars[namespace][key];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ async updateConfigs(configs) {
|
|
|
|
|
+ for (const config of configs) {
|
|
|
|
|
+ this.configModel.findOneAndUpdate(
|
|
|
|
|
+ { ns: config.ns, key: config.key },
|
|
|
|
|
+ { ns: config.ns, key: config.key, value: JSON.stringify(config.value) },
|
|
|
|
|
+ { upsert: true, },
|
|
|
|
|
+ function(err, config) {
|
|
|
|
|
+ debug('Config.findAndUpdate', err, config);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ await this.loadConfigs();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
module.exports = ConfigManager;
|
|
module.exports = ConfigManager;
|