Skip to content

Node.js based forum software built for the modern web

Merge branch 'master' into develop

Julian Lam58cbf441439d
diff --cc src/upgrade.js
index 01c767315e,b000a524b2..9ed3b6daac
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@@ -313,100 -313,75 +313,169 @@@ Upgrade.upgrade = function (callback)
next();
}
},
+ function (next) {
+ thisSchemaDate = Date.UTC(2016, 11, 7);
+
+ if (schemaDate < thisSchemaDate) {
+ updatesMade = true;
+ winston.info('[2016/12/07] Migrating flags to new schema (#5232)');
+
+ var batch = require('./batch');
+ var posts = require('./posts');
+ var flags = require('./flags');
+
+ batch.processSortedSet('posts:pid', function (ids, next) {
+ posts.getPostsByPids(ids, 1, function (err, posts) {
+ if (err) {
+ return next(err);
+ }
+
+ posts = posts.filter(function (post) {
+ return post.hasOwnProperty('flags');
+ });
+
+ async.each(posts, function (post, next) {
+ async.parallel({
+ uids: async.apply(db.getSortedSetRangeWithScores, 'pid:' + post.pid + ':flag:uids', 0, -1),
+ reasons: async.apply(db.getSortedSetRange, 'pid:' + post.pid + ':flag:uid:reason', 0, -1),
+ }, function (err, data) {
+ if (err) {
+ return next(err);
+ }
+
+ // Adding in another check here in case a post was improperly dismissed (flag count > 1 but no flags in db)
+ if (!data.uids.length || !data.reasons.length) {
+ return setImmediate(next);
+ }
+
+ // Just take the first entry
+ var datetime = data.uids[0].score;
+ var reason = data.reasons[0].split(':')[1];
+ var flagObj;
+
+ async.waterfall([
+ async.apply(flags.create, 'post', post.pid, data.uids[0].value, reason, datetime),
+ function (_flagObj, next) {
+ flagObj = _flagObj;
+ if (post['flag:state'] || post['flag:assignee']) {
+ flags.update(flagObj.flagId, 1, {
+ state: post['flag:state'],
+ assignee: post['flag:assignee'],
+ datetime: datetime,
+ }, next);
+ } else {
+ setImmediate(next);
+ }
+ },
+ function (next) {
+ if (post.hasOwnProperty('flag:notes') && post['flag:notes'].length) {
+ try {
+ var history = JSON.parse(post['flag:history']);
+ history = history.filter(function (event) {
+ return event.type === 'notes';
+ })[0];
+
+ flags.appendNote(flagObj.flagId, history.uid, post['flag:notes'], history.timestamp, next);
+ } catch (e) {
+ next(e);
+ }
+ } else {
+ setImmediate(next);
+ }
+ },
+ ], function (err) {
+ if (err && err.message === '[[error:already-flagged]]') {
+ // Already flagged, no need to parse, but not an error
+ next();
+ } else {
+ next(err);
+ }
+ });
+ });
+ }, next);
+ });
+ }, function (err) {
+ if (err) {
+ return next(err);
+ }
+
+ winston.info('[2016/12/07] Migrating flags to new schema (#5232) - done');
+ Upgrade.update(thisSchemaDate, next);
+ });
+ } else {
+ winston.info('[2016/12/07] Migrating flags to new schema (#5232) - skipped!');
+ 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
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
], function (err) {