From b96b983552c831d728cda18005602204873aabc0 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Tue, 28 Feb 2017 13:57:24 -0700
Subject: [PATCH 1/4] 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
---
src/upgrade.js | 107 +++++++++++++++++++++++++++++++++----------------
1 file changed, 72 insertions(+), 35 deletions(-)
diff --git a/src/upgrade.js b/src/upgrade.js
index a96cdf508e..bab54be08a 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -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();
From ac84e447dce5017f3493cb39872c15a3306bfdd0 Mon Sep 17 00:00:00 2001
From: barisusakli
Date: Wed, 1 Mar 2017 17:37:17 +0300
Subject: [PATCH 2/4] closes #5492
---
src/upgrade.js | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/upgrade.js b/src/upgrade.js
index a96cdf508e..7f14d211d3 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -321,7 +321,6 @@ Upgrade.upgrade = function (callback) {
updatesMade = true;
winston.verbose(schemaName);
- var user = require('./user');
var meta = require('./meta');
var batch = require('./batch');
@@ -360,14 +359,18 @@ Upgrade.upgrade = function (callback) {
if (err || !settings) {
return next(err);
}
-
+ var newSettings = {};
keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) {
- settings[key] = map[settings[key]] || '';
+ newSettings[key] = map[settings[key]] || '';
}
});
- user.saveSettings(uid, settings, next);
+ if (Object.keys(newSettings).length) {
+ db.setObject('user:' + uid + ':settings', newSettings, next);
+ } else {
+ setImmediate(next);
+ }
});
}, next);
}, cb);
From c5f40e3cf5cf0f40ceee6336e113ef160dd4083c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?=
Date: Wed, 1 Mar 2017 17:42:50 +0200
Subject: [PATCH 3/4] fix indents
---
src/upgrade.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/upgrade.js b/src/upgrade.js
index 5453952979..e3fe9be44a 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -357,18 +357,18 @@ Upgrade.upgrade = function (callback) {
if (err || !settings) {
return next(err);
}
- var newSettings = {};
+ var newSettings = {};
keys.forEach(function (key) {
if (settings[key] && settings[key].indexOf(' | ') === -1) {
newSettings[key] = map[settings[key]] || '';
}
});
- if (Object.keys(newSettings).length) {
- user.saveSettings(uid, settings, next);
- } else {
- setImmediate(next);
- }
+ if (Object.keys(newSettings).length) {
+ user.saveSettings(uid, settings, next);
+ } else {
+ setImmediate(next);
+ }
});
}, next);
}, cb);
From fecdbc969f89f7fb0cc3b11e5c0f095c264fce9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?=
Date: Wed, 1 Mar 2017 17:47:59 +0200
Subject: [PATCH 4/4] fix set call
---
src/upgrade.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/upgrade.js b/src/upgrade.js
index e3fe9be44a..690b3465ee 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -365,7 +365,7 @@ Upgrade.upgrade = function (callback) {
});
if (Object.keys(newSettings).length) {
- user.saveSettings(uid, settings, next);
+ db.setObject('user:' + uid + ':settings', newSettings, next);
} else {
setImmediate(next);
}