v1.18.x
barisusakli 9 years ago
parent 46d2168918
commit 7269d45e84

@ -179,12 +179,10 @@ function completeConfigSetup(err, config, next) {
function setupDefaultConfigs(next) {
process.stdout.write('Populating database with default configs, if not already set...\n');
var meta = require('./meta'),
defaults = require(path.join(__dirname, '../', 'install/data/defaults.json'));
var meta = require('./meta');
var defaults = require(path.join(__dirname, '../', 'install/data/defaults.json'));
async.eachSeries(Object.keys(defaults), function (key, next) {
meta.configs.setOnEmpty(key, defaults[key], next);
}, function (err) {
meta.configs.setOnEmpty(key, defaults, function (err) {
if (err) {
return next(err);
}

@ -118,14 +118,19 @@ module.exports = function(Meta) {
}
});
Meta.configs.setOnEmpty = function (field, value, callback) {
Meta.configs.get(field, function (err, curValue) {
Meta.configs.setOnEmpty = function (values, callback) {
db.getObject('config', function(err, data) {
if (err) {
return callback(err);
}
if (!curValue) {
Meta.configs.set(field, value, callback);
var empty = {};
Object.keys(values).forEach(function(key) {
if (!data.hasOwnProperty(key)) {
empty[key] = values[key];
}
});
if (Object.keys(empty).length) {
db.setObject('config', empty, callback);
} else {
callback();
}

@ -38,14 +38,20 @@ module.exports = function(Meta) {
db.setObjectField('settings:' + hash, field, value, callback);
};
Meta.settings.setOnEmpty = function (hash, field, value, callback) {
Meta.settings.getOne(hash, field, function (err, curValue) {
Meta.settings.setOnEmpty = function (hash, values, callback) {
db.getObject('settings:' + hash, function(err, settings) {
if (err) {
return callback(err);
}
var empty = {};
Object.keys(values).forEach(function(key) {
if (!settings.hasOwnProperty(key)) {
empty[key] = values[key];
}
});
if (!curValue) {
Meta.settings.setOne(hash, field, value, callback);
if (Object.keys(empty).length) {
db.setObject('settings:' + hash, empty, callback);
} else {
callback();
}

Loading…
Cancel
Save