From ea8cf6545c170e8811ba018e6d8e682cc2fc7d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 18 Dec 2017 20:21:38 -0500 Subject: [PATCH 1/7] change db.set/get to use data field instead of value --- src/database/mongo/main.js | 6 +- src/upgrades/1.7.3/key_value_schema_change.js | 67 +++++++++++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/upgrades/1.7.3/key_value_schema_change.js diff --git a/src/database/mongo/main.js b/src/database/mongo/main.js index eff7459a69..278ae6c413 100644 --- a/src/database/mongo/main.js +++ b/src/database/mongo/main.js @@ -66,7 +66,7 @@ module.exports = function (db, module) { if (!key) { return callback(); } - module.getObjectField(key, 'value', callback); + module.getObjectField(key, 'data', callback); }; module.set = function (key, value, callback) { @@ -74,7 +74,7 @@ module.exports = function (db, module) { if (!key) { return callback(); } - var data = { value: value }; + var data = { data: value }; module.setObject(key, data, callback); }; @@ -115,7 +115,7 @@ module.exports = function (db, module) { return callback(null, 'set'); } else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('array')) { return callback(null, 'list'); - } else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('value')) { + } else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('data')) { return callback(null, 'string'); } callback(null, 'hash'); diff --git a/src/upgrades/1.7.3/key_value_schema_change.js b/src/upgrades/1.7.3/key_value_schema_change.js new file mode 100644 index 0000000000..4e747f6846 --- /dev/null +++ b/src/upgrades/1.7.3/key_value_schema_change.js @@ -0,0 +1,67 @@ +'use strict'; + +var async = require('async'); + +var db = require('../../database'); + +module.exports = { + name: 'Change the schema of simple keys so they don\'t use value field (mongodb only)', + timestamp: Date.UTC(2017, 11, 18), + method: function (callback) { + var configJSON = require('../../../config.json'); + var isMongo = configJSON.hasOwnProperty('mongo') && configJSON.database === 'mongo'; + var progress = this.progress; + if (!isMongo) { + return callback(); + } + var client = db.client; + var cursor; + async.waterfall([ + function (next) { + client.collection('objects').count({ + _key: { $exists: true }, + value: { $exists: true }, + score: { $exists: false }, + }, next); + }, + function (count, next) { + progress.total = count; + cursor = client.collection('objects').find({ + _key: { $exists: true }, + value: { $exists: true }, + score: { $exists: false }, + }).batchSize(1000); + + var done = false; + async.whilst( + function () { + return !done; + }, + function (next) { + async.waterfall([ + function (next) { + cursor.next(next); + }, + function (item, next) { + progress.incr(); + if (item === null) { + done = true; + return next(); + } + + if (Object.keys(item).length === 3 && item.hasOwnProperty('_key') && item.hasOwnProperty('value')) { + client.collection('objects').update({ _key: item._key }, { $rename: { value: 'data' } }, next); + } else { + next(); + } + }, + ], function (err) { + next(err); + }); + }, + next + ); + }, + ], callback); + }, +}; From 13e56ad5f3e02d40b63bc402c4584738b1aa5c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 18 Dec 2017 21:00:49 -0500 Subject: [PATCH 2/7] make sure unfilled is not negative --- src/upgrade.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/upgrade.js b/src/upgrade.js index a0ceb5b7df..b4d9f4751c 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -205,7 +205,7 @@ Upgrade.incrementProgress = function (value) { if (this.total) { percentage = Math.floor((this.current / this.total) * 100) + '%'; filled = Math.floor((this.current / this.total) * 15); - unfilled = 15 - filled; + unfilled = Math.min(0, 15 - filled); } readline.cursorTo(process.stdout, 0); From 3196311f1516dabfab6eea19c10f439c169d36d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 19 Dec 2017 11:47:13 -0500 Subject: [PATCH 3/7] closes #6184 --- src/controllers/category.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/controllers/category.js b/src/controllers/category.js index f231349a49..89f924e479 100644 --- a/src/controllers/category.js +++ b/src/controllers/category.js @@ -199,14 +199,17 @@ function addTags(categoryData, res) { } res.locals.linkTags = [ - { - rel: 'alternate', - type: 'application/rss+xml', - href: categoryData.rssFeedUrl, - }, { rel: 'up', href: nconf.get('url'), }, ]; + + if (!categoryData['feeds:disableRSS']) { + res.locals.linkTags.push({ + rel: 'alternate', + type: 'application/rss+xml', + href: categoryData.rssFeedUrl, + }); + } } From acc58d707c2860d37ce54b07a4750e25eb5c3575 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 19 Dec 2017 12:06:56 -0500 Subject: [PATCH 4/7] Updated plugin checking logic * Fixes #6183 * Also changed a bunch of console.logs to process.stdout.write, so the command line output is cleaner --- src/cli/upgrade-plugins.js | 67 ++++++++++++++++++------------------- src/cli/upgrade.js | 10 +++--- src/meta/build.js | 4 ++- src/meta/package-install.js | 1 + src/upgrade.js | 2 +- 5 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/cli/upgrade-plugins.js b/src/cli/upgrade-plugins.js index 4011546fd3..e67f634f31 100644 --- a/src/cli/upgrade-plugins.js +++ b/src/cli/upgrade-plugins.js @@ -38,53 +38,49 @@ function getInstalledPlugins(callback) { async.parallel({ files: async.apply(fs.readdir, path.join(dirname, 'node_modules')), deps: async.apply(fs.readFile, path.join(dirname, 'package.json'), { encoding: 'utf-8' }), + bundled: async.apply(fs.readFile, path.join(dirname, 'install/package.json'), { encoding: 'utf-8' }), }, function (err, payload) { if (err) { return callback(err); } var isNbbModule = /^nodebb-(?:plugin|theme|widget|rewards)-[\w-]+$/; - var moduleName; - var isGitRepo; + var checklist; payload.files = payload.files.filter(function (file) { return isNbbModule.test(file); }); try { - payload.deps = JSON.parse(payload.deps).dependencies; - payload.bundled = []; - payload.installed = []; + payload.deps = Object.keys(JSON.parse(payload.deps).dependencies); + payload.bundled = Object.keys(JSON.parse(payload.bundled).dependencies); } catch (err) { return callback(err); } - for (moduleName in payload.deps) { - if (isNbbModule.test(moduleName)) { - payload.bundled.push(moduleName); - } - } + payload.bundled = payload.bundled.filter(function (pkgName) { + return isNbbModule.test(pkgName); + }); + payload.deps = payload.deps.filter(function (pkgName) { + return isNbbModule.test(pkgName); + }); // Whittle down deps to send back only extraneously installed plugins/themes/etc - payload.files.forEach(function (moduleName) { - try { - fs.accessSync(path.join(dirname, 'node_modules', moduleName, '.git')); - isGitRepo = true; - } catch (e) { - isGitRepo = false; + checklist = payload.deps.filter(function (pkgName) { + if (payload.bundled.includes(pkgName)) { + return false; } - if ( - payload.files.indexOf(moduleName) !== -1 && // found in `node_modules/` - payload.bundled.indexOf(moduleName) === -1 && // not found in `package.json` - !fs.lstatSync(path.join(dirname, 'node_modules', moduleName)).isSymbolicLink() && // is not a symlink - !isGitRepo // .git/ does not exist, so it is not a git repository - ) { - payload.installed.push(moduleName); + // Ignore git repositories + try { + fs.accessSync(path.join(dirname, 'node_modules', pkgName, '.git')); + return false; + } catch (e) { + return true; } }); - getModuleVersions(payload.installed, callback); + getModuleVersions(checklist, callback); }); } @@ -105,7 +101,7 @@ function getCurrentVersion(callback) { function checkPlugins(standalone, callback) { if (standalone) { - console.log('Checking installed plugins and themes for updates... '); + process.stdout.write('Checking installed plugins and themes for updates... '); } async.waterfall([ @@ -117,7 +113,7 @@ function checkPlugins(standalone, callback) { var toCheck = Object.keys(payload.plugins); if (!toCheck.length) { - console.log('OK'.green + ''.reset); + process.stdout.write(' OK'.green + ''.reset); return next(null, []); // no extraneous plugins installed } @@ -127,10 +123,10 @@ function checkPlugins(standalone, callback) { json: true, }, function (err, res, body) { if (err) { - console.log('error'.red + ''.reset); + process.stdout.write('error'.red + ''.reset); return next(err); } - console.log('OK'.green + ''.reset); + process.stdout.write(' OK'.green + ''.reset); if (!Array.isArray(body) && toCheck.length === 1) { body = [body]; @@ -172,11 +168,10 @@ function upgradePlugins(callback) { } if (found && found.length) { - console.log('\nA total of ' + String(found.length).bold + ' package(s) can be upgraded:'); + process.stdout.write('\n\nA total of ' + String(found.length).bold + ' package(s) can be upgraded:\n\n'); found.forEach(function (suggestObj) { - console.log(' * '.yellow + suggestObj.name.reset + ' (' + suggestObj.current.yellow + ' -> '.reset + suggestObj.suggested.green + ')\n'.reset); + process.stdout.write(' * '.yellow + suggestObj.name.reset + ' (' + suggestObj.current.yellow + ' -> '.reset + suggestObj.suggested.green + ')\n'.reset); }); - console.log(''); } else { if (standalone) { console.log('\nAll packages up-to-date!'.green + ''.reset); @@ -190,7 +185,7 @@ function upgradePlugins(callback) { prompt.start(); prompt.get({ name: 'upgrade', - description: 'Proceed with upgrade (y|n)?'.reset, + description: '\nProceed with upgrade (y|n)?'.reset, type: 'string', }, function (err, result) { if (err) { @@ -204,10 +199,12 @@ function upgradePlugins(callback) { args.push(suggestObj.name + '@' + suggestObj.suggested); }); - cproc.execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', args, { stdio: 'ignore' }, callback); + cproc.execFile((process.platform === 'win32') ? 'npm.cmd' : 'npm', args, { stdio: 'ignore' }, function (err) { + callback(err, true); + }); } else { - console.log('Package upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade-plugins'.green + '".'.reset); - callback(); + console.log('Package upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade -p'.green + '".'.reset); + callback(null, true); } }); }); diff --git a/src/cli/upgrade.js b/src/cli/upgrade.js index 026a104c30..783681bb10 100644 --- a/src/cli/upgrade.js +++ b/src/cli/upgrade.js @@ -53,10 +53,12 @@ var steps = { function runSteps(tasks) { tasks = tasks.map(function (key, i) { return function (next) { - console.log(((i + 1) + '. ').bold + steps[key].message.yellow); - return steps[key].handler(function (err) { + process.stdout.write('\n' + ((i + 1) + '. ').bold + steps[key].message.yellow); + return steps[key].handler(function (err, inhibitOk) { if (err) { return next(err); } - console.log(' OK'.green); + if (!inhibitOk) { + process.stdout.write(' OK'.green + '\n'.reset); + } next(); }); }; @@ -73,7 +75,7 @@ function runSteps(tasks) { var columns = process.stdout.columns; var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' '; - console.log('\n' + spaces + message.green.bold + '\n'.reset); + console.log('\n\n' + spaces + message.green.bold + '\n'.reset); process.exit(); }); diff --git a/src/meta/build.js b/src/meta/build.js index df68e93375..2beb5f8af9 100644 --- a/src/meta/build.js +++ b/src/meta/build.js @@ -99,6 +99,8 @@ function beforeBuild(targets, callback) { var plugins = require('../plugins'); meta = require('../meta'); + process.stdout.write(' started'.green + '\n'.reset); + async.series([ db.init, meta.themes.setupPaths, @@ -210,7 +212,7 @@ function build(targets, callback) { } winston.info('[build] Asset compilation successful. Completed in ' + totalTime + 'sec.'); - callback(); + callback(null, true); }); } diff --git a/src/meta/package-install.js b/src/meta/package-install.js index 2ae93612a0..4dba482b70 100644 --- a/src/meta/package-install.js +++ b/src/meta/package-install.js @@ -30,6 +30,7 @@ function updatePackageFile() { exports.updatePackageFile = updatePackageFile; function npmInstallProduction() { + process.stdout.write('\n'); cproc.execSync('npm i --production', { cwd: path.join(__dirname, '../../'), stdio: [0, 1, 2], diff --git a/src/upgrade.js b/src/upgrade.js index b4d9f4751c..63750f5248 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -189,7 +189,7 @@ Upgrade.process = function (files, skipCount, callback) { }, next); }, function (next) { - console.log('Upgrade complete!\n'.green); + console.log('Schema update(s) complete!\n'.green); setImmediate(next); }, ], callback); From 50cc62e2aafa6bf249407e2ced17d35e1139a3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 19 Dec 2017 12:27:19 -0500 Subject: [PATCH 5/7] fix rss feed on topic #6184 --- src/controllers/topics.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 4ecaf7486e..13228f5779 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -257,17 +257,20 @@ function addTags(topicData, req, res) { addOGImageTags(res, topicData, postAtIndex); res.locals.linkTags = [ - { - rel: 'alternate', - type: 'application/rss+xml', - href: topicData.rssFeedUrl, - }, { rel: 'canonical', href: nconf.get('url') + '/topic/' + topicData.slug, }, ]; + if (!topicData['feeds:disableRSS']) { + res.locals.linkTags.push({ + rel: 'alternate', + type: 'application/rss+xml', + href: topicData.rssFeedUrl, + }); + } + if (topicData.category) { res.locals.linkTags.push({ rel: 'up', From 6d15861a552646620db1bc48a3b135e254344a22 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 19 Dec 2017 14:21:15 -0500 Subject: [PATCH 6/7] removed pluralisation @pitaj --- src/upgrade.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/upgrade.js b/src/upgrade.js index 63750f5248..ae0d70a4c0 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -189,7 +189,7 @@ Upgrade.process = function (files, skipCount, callback) { }, next); }, function (next) { - console.log('Schema update(s) complete!\n'.green); + console.log('Schema update complete!\n'.green); setImmediate(next); }, ], callback); From 96084340ad86cf8bbe1d47a3fe48f9a6dadc4515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 19 Dec 2017 16:03:05 -0500 Subject: [PATCH 7/7] closes #6186 --- public/src/client/topic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/client/topic.js b/public/src/client/topic.js index b3fa02b509..54052d47c1 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -157,7 +157,7 @@ define('forum/topic', [ components.get('topic').on('click', '[component="post/parent"]', function (e) { var toPid = $(this).attr('data-topid'); - var toPost = $('[component="post"][data-pid="' + toPid + '"]'); + var toPost = $('[component="topic"]>[component="post"][data-pid="' + toPid + '"]'); if (toPost.length) { e.preventDefault(); navigator.scrollToIndex(toPost.attr('data-index'), true);