Upgrade script for prepending `/assets` in config

Fix for sound settings upgrade script to upgrade user sound settings even if admin settings weren't set
v1.18.x
Peter Jaszkowiak 8 years ago
parent 2e47cf4db3
commit b96b983552

@ -12,7 +12,7 @@ var schemaDate;
var thisSchemaDate;
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
var latestSchema = Date.UTC(2017, 1, 25);
var latestSchema = Date.UTC(2017, 1, 28);
Upgrade.check = function (callback) {
db.get('schemaDate', function (err, value) {
@ -331,17 +331,14 @@ Upgrade.upgrade = function (callback) {
'waterdrop-low.mp3': 'Default | Water drop (low)',
};
db.getObject('settings:sounds', function (err, settings) {
if (err) {
return next(err);
} else if (!settings) {
winston.info(schemaName + ' - done');
return Upgrade.update(thisSchemaDate, next);
}
async.parallel([
function (cb) {
var keys = ['chat-incoming', 'chat-outgoing', 'notification'];
async.parallel([
function (cb) {
var keys = ['chat-incoming', 'chat-outgoing', 'notification'];
db.getObject('settings:sounds', function (err, settings) {
if (err || !settings) {
return cb(err);
}
keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) {
@ -350,36 +347,76 @@ Upgrade.upgrade = function (callback) {
});
meta.configs.setMultiple(settings, cb);
},
function (cb) {
var keys = ['notificationSound', 'incomingChatSound', 'outgoingChatSound'];
batch.processSortedSet('users:joindate', function (ids, next) {
async.each(ids, function (uid, next) {
db.getObject('user:' + uid + ':settings', function (err, settings) {
if (err || !settings) {
return next(err);
});
},
function (cb) {
var keys = ['notificationSound', 'incomingChatSound', 'outgoingChatSound'];
batch.processSortedSet('users:joindate', function (ids, next) {
async.each(ids, function (uid, next) {
db.getObject('user:' + uid + ':settings', function (err, settings) {
if (err || !settings) {
return next(err);
}
keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) {
settings[key] = map[settings[key]] || '';
}
});
keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) {
settings[key] = map[settings[key]] || '';
}
});
user.saveSettings(uid, settings, next);
});
}, next);
}, cb);
},
], function (err) {
if (err) {
return next(err);
}
winston.info(schemaName + ' - done');
Upgrade.update(thisSchemaDate, next);
});
} else {
winston.info(schemaName + ' - skipped!');
next();
}
},
function (next) {
thisSchemaDate = Date.UTC(2017, 1, 28);
var schemaName = '[2017/2/28] Update urls in config to `/assets`';
user.saveSettings(uid, settings, next);
});
}, next);
}, cb);
},
], function (err) {
if (err) {
return next(err);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info(schemaName);
async.waterfall([
function (cb) {
db.getObject('config', cb);
},
function (config, cb) {
if (!config) {
return cb();
}
var keys = ['brand:favicon', 'brand:touchicon', 'og:image', 'brand:logo:url', 'defaultAvatar', 'profile:defaultCovers'];
keys.forEach(function (key) {
var oldValue = config[key];
if (!oldValue || typeof oldValue !== 'string') {
return;
}
config[key] = oldValue.replace(/(?:\/assets)?\/(images|uploads)\//g, '/assets/$1/');
});
db.setObject('config', config, cb);
},
function (next) {
winston.info(schemaName + ' - done');
Upgrade.update(thisSchemaDate, next);
});
});
},
], next);
} else {
winston.info(schemaName + ' - skipped!');
next();

Loading…
Cancel
Save