Merge remote-tracking branch 'refs/remotes/origin/master' into chat-permission

v1.18.x
Baris Usakli 7 years ago
commit 63b9255fa1

@ -157,7 +157,7 @@ define('forum/topic', [
components.get('topic').on('click', '[component="post/parent"]', function (e) { components.get('topic').on('click', '[component="post/parent"]', function (e) {
var toPid = $(this).attr('data-topid'); 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) { if (toPost.length) {
e.preventDefault(); e.preventDefault();
navigator.scrollToIndex(toPost.attr('data-index'), true); navigator.scrollToIndex(toPost.attr('data-index'), true);

@ -38,53 +38,49 @@ function getInstalledPlugins(callback) {
async.parallel({ async.parallel({
files: async.apply(fs.readdir, path.join(dirname, 'node_modules')), files: async.apply(fs.readdir, path.join(dirname, 'node_modules')),
deps: async.apply(fs.readFile, path.join(dirname, 'package.json'), { encoding: 'utf-8' }), 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) { }, function (err, payload) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
var isNbbModule = /^nodebb-(?:plugin|theme|widget|rewards)-[\w-]+$/; var isNbbModule = /^nodebb-(?:plugin|theme|widget|rewards)-[\w-]+$/;
var moduleName; var checklist;
var isGitRepo;
payload.files = payload.files.filter(function (file) { payload.files = payload.files.filter(function (file) {
return isNbbModule.test(file); return isNbbModule.test(file);
}); });
try { try {
payload.deps = JSON.parse(payload.deps).dependencies; payload.deps = Object.keys(JSON.parse(payload.deps).dependencies);
payload.bundled = []; payload.bundled = Object.keys(JSON.parse(payload.bundled).dependencies);
payload.installed = [];
} catch (err) { } catch (err) {
return callback(err); return callback(err);
} }
for (moduleName in payload.deps) { payload.bundled = payload.bundled.filter(function (pkgName) {
if (isNbbModule.test(moduleName)) { return isNbbModule.test(pkgName);
payload.bundled.push(moduleName); });
} payload.deps = payload.deps.filter(function (pkgName) {
} return isNbbModule.test(pkgName);
});
// Whittle down deps to send back only extraneously installed plugins/themes/etc // Whittle down deps to send back only extraneously installed plugins/themes/etc
payload.files.forEach(function (moduleName) { checklist = payload.deps.filter(function (pkgName) {
try { if (payload.bundled.includes(pkgName)) {
fs.accessSync(path.join(dirname, 'node_modules', moduleName, '.git')); return false;
isGitRepo = true;
} catch (e) {
isGitRepo = false;
} }
if ( // Ignore git repositories
payload.files.indexOf(moduleName) !== -1 && // found in `node_modules/` try {
payload.bundled.indexOf(moduleName) === -1 && // not found in `package.json` fs.accessSync(path.join(dirname, 'node_modules', pkgName, '.git'));
!fs.lstatSync(path.join(dirname, 'node_modules', moduleName)).isSymbolicLink() && // is not a symlink return false;
!isGitRepo // .git/ does not exist, so it is not a git repository } catch (e) {
) { return true;
payload.installed.push(moduleName);
} }
}); });
getModuleVersions(payload.installed, callback); getModuleVersions(checklist, callback);
}); });
} }
@ -105,7 +101,7 @@ function getCurrentVersion(callback) {
function checkPlugins(standalone, callback) { function checkPlugins(standalone, callback) {
if (standalone) { if (standalone) {
console.log('Checking installed plugins and themes for updates... '); process.stdout.write('Checking installed plugins and themes for updates... ');
} }
async.waterfall([ async.waterfall([
@ -117,7 +113,7 @@ function checkPlugins(standalone, callback) {
var toCheck = Object.keys(payload.plugins); var toCheck = Object.keys(payload.plugins);
if (!toCheck.length) { if (!toCheck.length) {
console.log('OK'.green + ''.reset); process.stdout.write(' OK'.green + ''.reset);
return next(null, []); // no extraneous plugins installed return next(null, []); // no extraneous plugins installed
} }
@ -127,10 +123,10 @@ function checkPlugins(standalone, callback) {
json: true, json: true,
}, function (err, res, body) { }, function (err, res, body) {
if (err) { if (err) {
console.log('error'.red + ''.reset); process.stdout.write('error'.red + ''.reset);
return next(err); return next(err);
} }
console.log('OK'.green + ''.reset); process.stdout.write(' OK'.green + ''.reset);
if (!Array.isArray(body) && toCheck.length === 1) { if (!Array.isArray(body) && toCheck.length === 1) {
body = [body]; body = [body];
@ -172,11 +168,10 @@ function upgradePlugins(callback) {
} }
if (found && found.length) { 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) { 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 { } else {
if (standalone) { if (standalone) {
console.log('\nAll packages up-to-date!'.green + ''.reset); console.log('\nAll packages up-to-date!'.green + ''.reset);
@ -190,7 +185,7 @@ function upgradePlugins(callback) {
prompt.start(); prompt.start();
prompt.get({ prompt.get({
name: 'upgrade', name: 'upgrade',
description: 'Proceed with upgrade (y|n)?'.reset, description: '\nProceed with upgrade (y|n)?'.reset,
type: 'string', type: 'string',
}, function (err, result) { }, function (err, result) {
if (err) { if (err) {
@ -204,10 +199,12 @@ function upgradePlugins(callback) {
args.push(suggestObj.name + '@' + suggestObj.suggested); 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 { } else {
console.log('Package upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade-plugins'.green + '".'.reset); console.log('Package upgrades skipped'.yellow + '. Check for upgrades at any time by running "'.reset + './nodebb upgrade -p'.green + '".'.reset);
callback(); callback(null, true);
} }
}); });
}); });

@ -53,10 +53,12 @@ var steps = {
function runSteps(tasks) { function runSteps(tasks) {
tasks = tasks.map(function (key, i) { tasks = tasks.map(function (key, i) {
return function (next) { return function (next) {
console.log(((i + 1) + '. ').bold + steps[key].message.yellow); process.stdout.write('\n' + ((i + 1) + '. ').bold + steps[key].message.yellow);
return steps[key].handler(function (err) { return steps[key].handler(function (err, inhibitOk) {
if (err) { return next(err); } if (err) { return next(err); }
console.log(' OK'.green); if (!inhibitOk) {
process.stdout.write(' OK'.green + '\n'.reset);
}
next(); next();
}); });
}; };
@ -73,7 +75,7 @@ function runSteps(tasks) {
var columns = process.stdout.columns; var columns = process.stdout.columns;
var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : ' '; 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(); process.exit();
}); });

@ -199,14 +199,17 @@ function addTags(categoryData, res) {
} }
res.locals.linkTags = [ res.locals.linkTags = [
{
rel: 'alternate',
type: 'application/rss+xml',
href: categoryData.rssFeedUrl,
},
{ {
rel: 'up', rel: 'up',
href: nconf.get('url'), href: nconf.get('url'),
}, },
]; ];
if (!categoryData['feeds:disableRSS']) {
res.locals.linkTags.push({
rel: 'alternate',
type: 'application/rss+xml',
href: categoryData.rssFeedUrl,
});
}
} }

@ -257,17 +257,20 @@ function addTags(topicData, req, res) {
addOGImageTags(res, topicData, postAtIndex); addOGImageTags(res, topicData, postAtIndex);
res.locals.linkTags = [ res.locals.linkTags = [
{
rel: 'alternate',
type: 'application/rss+xml',
href: topicData.rssFeedUrl,
},
{ {
rel: 'canonical', rel: 'canonical',
href: nconf.get('url') + '/topic/' + topicData.slug, 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) { if (topicData.category) {
res.locals.linkTags.push({ res.locals.linkTags.push({
rel: 'up', rel: 'up',

@ -66,7 +66,7 @@ module.exports = function (db, module) {
if (!key) { if (!key) {
return callback(); return callback();
} }
module.getObjectField(key, 'value', callback); module.getObjectField(key, 'data', callback);
}; };
module.set = function (key, value, callback) { module.set = function (key, value, callback) {
@ -74,7 +74,7 @@ module.exports = function (db, module) {
if (!key) { if (!key) {
return callback(); return callback();
} }
var data = { value: value }; var data = { data: value };
module.setObject(key, data, callback); module.setObject(key, data, callback);
}; };
@ -115,7 +115,7 @@ module.exports = function (db, module) {
return callback(null, 'set'); return callback(null, 'set');
} else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('array')) { } else if (keys.length === 3 && data.hasOwnProperty('_key') && data.hasOwnProperty('array')) {
return callback(null, 'list'); 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'); return callback(null, 'string');
} }
callback(null, 'hash'); callback(null, 'hash');

@ -99,6 +99,8 @@ function beforeBuild(targets, callback) {
var plugins = require('../plugins'); var plugins = require('../plugins');
meta = require('../meta'); meta = require('../meta');
process.stdout.write(' started'.green + '\n'.reset);
async.series([ async.series([
db.init, db.init,
meta.themes.setupPaths, meta.themes.setupPaths,
@ -210,7 +212,7 @@ function build(targets, callback) {
} }
winston.info('[build] Asset compilation successful. Completed in ' + totalTime + 'sec.'); winston.info('[build] Asset compilation successful. Completed in ' + totalTime + 'sec.');
callback(); callback(null, true);
}); });
} }

@ -30,6 +30,7 @@ function updatePackageFile() {
exports.updatePackageFile = updatePackageFile; exports.updatePackageFile = updatePackageFile;
function npmInstallProduction() { function npmInstallProduction() {
process.stdout.write('\n');
cproc.execSync('npm i --production', { cproc.execSync('npm i --production', {
cwd: path.join(__dirname, '../../'), cwd: path.join(__dirname, '../../'),
stdio: [0, 1, 2], stdio: [0, 1, 2],

@ -189,7 +189,7 @@ Upgrade.process = function (files, skipCount, callback) {
}, next); }, next);
}, },
function (next) { function (next) {
console.log('Upgrade complete!\n'.green); console.log('Schema update complete!\n'.green);
setImmediate(next); setImmediate(next);
}, },
], callback); ], callback);
@ -205,7 +205,7 @@ Upgrade.incrementProgress = function (value) {
if (this.total) { if (this.total) {
percentage = Math.floor((this.current / this.total) * 100) + '%'; percentage = Math.floor((this.current / this.total) * 100) + '%';
filled = Math.floor((this.current / this.total) * 15); filled = Math.floor((this.current / this.total) * 15);
unfilled = 15 - filled; unfilled = Math.min(0, 15 - filled);
} }
readline.cursorTo(process.stdout, 0); readline.cursorTo(process.stdout, 0);

@ -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);
},
};
Loading…
Cancel
Save