Merge pull request #5482 from NodeBB/sounds-fix-5476

Upgrade script for new sounds system
v1.18.x
Julian Lam 8 years ago committed by GitHub
commit 4d8bebcd81

@ -110,9 +110,9 @@ module.exports = function (Meta) {
var userSettings = results.userSettings; var userSettings = results.userSettings;
userSettings = { userSettings = {
notification: userSettings.notificationSound || userSettings['notification-sound'], notification: userSettings.notificationSound,
'chat-incoming': userSettings.incomingChatSound || userSettings['chat-incoming-sound'], 'chat-incoming': userSettings.incomingChatSound,
'chat-outgoing': userSettings.outgoingChatSound || userSettings['chat-outgoing-sound'], 'chat-outgoing': userSettings.outgoingChatSound,
}; };
var defaultMapping = results.defaultMapping || {}; var defaultMapping = results.defaultMapping || {};
var soundMapping = {}; var soundMapping = {};

@ -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(2016, 10, 22); var latestSchema = Date.UTC(2017, 1, 25);
Upgrade.check = function (callback) { Upgrade.check = function (callback) {
db.get('schemaDate', function (err, value) { db.get('schemaDate', function (err, value) {
@ -313,6 +313,75 @@ Upgrade.upgrade = function (callback) {
next(); next();
} }
}, },
function (next) {
thisSchemaDate = Date.UTC(2017, 1, 25);
var schemaName = '[2017/2/25] Update global and user sound settings';
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.verbose(schemaName);
var user = require('./user');
var meta = require('./meta');
var batch = require('./batch');
var map = {
'notification.mp3': 'Default | Deedle-dum',
'waterdrop-high.mp3': 'Default | Water drop (high)',
'waterdrop-low.mp3': 'Default | Water drop (low)',
};
async.parallel([
function (cb) {
var keys = ['chat-incoming', 'chat-outgoing', 'notification'];
db.getObject('settings:sounds', function (err, settings) {
if (err) {
return cb(err);
}
keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) {
settings[key] = map[settings[key]] || '';
}
});
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) {
user.getSettings(uid, function (err, settings) {
if (err) {
return next(err);
}
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.verbose(schemaName + ' - done');
Upgrade.update(thisSchemaDate, next);
});
} else {
winston.verbose(schemaName + ' - skipped!');
next();
}
},
// Add new schema updates here // Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!! // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
], function (err) { ], function (err) {

Loading…
Cancel
Save