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; var thisSchemaDate;
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema // 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) { Upgrade.check = function (callback) {
db.get('schemaDate', function (err, value) { db.get('schemaDate', function (err, value) {
@ -331,17 +331,14 @@ Upgrade.upgrade = function (callback) {
'waterdrop-low.mp3': 'Default | Water drop (low)', 'waterdrop-low.mp3': 'Default | Water drop (low)',
}; };
db.getObject('settings:sounds', function (err, settings) { async.parallel([
if (err) { function (cb) {
return next(err); var keys = ['chat-incoming', 'chat-outgoing', 'notification'];
} else if (!settings) {
winston.info(schemaName + ' - done');
return Upgrade.update(thisSchemaDate, next);
}
async.parallel([ db.getObject('settings:sounds', function (err, settings) {
function (cb) { if (err || !settings) {
var keys = ['chat-incoming', 'chat-outgoing', 'notification']; return cb(err);
}
keys.forEach(function (key) { keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) { if (settings[key] && settings[key].indexOf(' | ') === -1) {
@ -350,36 +347,76 @@ Upgrade.upgrade = function (callback) {
}); });
meta.configs.setMultiple(settings, cb); meta.configs.setMultiple(settings, cb);
}, });
function (cb) { },
var keys = ['notificationSound', 'incomingChatSound', 'outgoingChatSound']; function (cb) {
var keys = ['notificationSound', 'incomingChatSound', 'outgoingChatSound'];
batch.processSortedSet('users:joindate', function (ids, next) {
async.each(ids, function (uid, next) { batch.processSortedSet('users:joindate', function (ids, next) {
db.getObject('user:' + uid + ':settings', function (err, settings) { async.each(ids, function (uid, next) {
if (err || !settings) { db.getObject('user:' + uid + ':settings', function (err, settings) {
return next(err); 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) { user.saveSettings(uid, settings, next);
if (settings[key] && settings[key].indexOf(' | ') === -1) { });
settings[key] = map[settings[key]] || ''; }, 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); if (schemaDate < thisSchemaDate) {
}); updatesMade = true;
}, next); winston.info(schemaName);
}, cb); async.waterfall([
}, function (cb) {
], function (err) { db.getObject('config', cb);
if (err) { },
return next(err); 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'); winston.info(schemaName + ' - done');
Upgrade.update(thisSchemaDate, next); Upgrade.update(thisSchemaDate, next);
}); },
}); ], next);
} else { } else {
winston.info(schemaName + ' - skipped!'); winston.info(schemaName + ' - skipped!');
next(); next();

Loading…
Cancel
Save