You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
4.4 KiB
JavaScript
175 lines
4.4 KiB
JavaScript
10 years ago
|
'use strict';
|
||
|
|
||
8 years ago
|
require('colors');
|
||
8 years ago
|
var path = require('path');
|
||
10 years ago
|
var winston = require('winston');
|
||
9 years ago
|
var async = require('async');
|
||
7 years ago
|
var fs = require('fs');
|
||
10 years ago
|
|
||
7 years ago
|
var db = require('../database');
|
||
|
var events = require('../events');
|
||
|
var meta = require('../meta');
|
||
|
var plugins = require('../plugins');
|
||
|
var widgets = require('../widgets');
|
||
10 years ago
|
|
||
7 years ago
|
var dirname = require('./paths').baseDir;
|
||
10 years ago
|
|
||
7 years ago
|
exports.reset = function (options, callback) {
|
||
|
var map = {
|
||
|
theme: function (next) {
|
||
|
var themeId = options.theme;
|
||
8 years ago
|
if (themeId === true) {
|
||
7 years ago
|
resetThemes(next);
|
||
9 years ago
|
} else {
|
||
7 years ago
|
if (!themeId.startsWith('nodebb-theme-')) {
|
||
8 years ago
|
// Allow omission of `nodebb-theme-`
|
||
|
themeId = 'nodebb-theme-' + themeId;
|
||
|
}
|
||
|
|
||
7 years ago
|
resetTheme(themeId, next);
|
||
9 years ago
|
}
|
||
7 years ago
|
},
|
||
|
plugin: function (next) {
|
||
|
var pluginId = options.plugin;
|
||
8 years ago
|
if (pluginId === true) {
|
||
7 years ago
|
resetPlugins(next);
|
||
10 years ago
|
} else {
|
||
7 years ago
|
if (!pluginId.startsWith('nodebb-plugin-')) {
|
||
8 years ago
|
// Allow omission of `nodebb-plugin-`
|
||
|
pluginId = 'nodebb-plugin-' + pluginId;
|
||
|
}
|
||
|
|
||
7 years ago
|
resetPlugin(pluginId, next);
|
||
10 years ago
|
}
|
||
7 years ago
|
},
|
||
|
widgets: resetWidgets,
|
||
|
settings: resetSettings,
|
||
|
all: function (next) {
|
||
|
async.series([resetWidgets, resetThemes, resetPlugins, resetSettings], next);
|
||
|
},
|
||
|
};
|
||
|
|
||
|
var tasks = Object.keys(map)
|
||
|
.filter(function (x) { return options[x]; })
|
||
|
.map(function (x) { return map[x]; });
|
||
|
|
||
|
if (!tasks.length) {
|
||
|
process.stdout.write('\nNodeBB Reset\n'.bold);
|
||
|
process.stdout.write('No arguments passed in, so nothing was reset.\n\n'.yellow);
|
||
|
process.stdout.write('Use ./nodebb reset ' + '{-t|-p|-w|-s|-a}\n'.red);
|
||
|
process.stdout.write(' -t\tthemes\n');
|
||
|
process.stdout.write(' -p\tplugins\n');
|
||
|
process.stdout.write(' -w\twidgets\n');
|
||
|
process.stdout.write(' -s\tsettings\n');
|
||
|
process.stdout.write(' -a\tall of the above\n');
|
||
|
|
||
|
process.stdout.write('\nPlugin and theme reset flags (-p & -t) can take a single argument\n');
|
||
|
process.stdout.write(' e.g. ./nodebb reset -p nodebb-plugin-mentions, ./nodebb reset -t nodebb-theme-persona\n');
|
||
|
process.stdout.write(' Prefix is optional, e.g. ./nodebb reset -p markdown, ./nodebb reset -t persona\n');
|
||
|
|
||
|
process.exit(0);
|
||
|
}
|
||
|
|
||
|
async.series([db.init].concat(tasks), function (err) {
|
||
|
if (err) {
|
||
|
winston.error('[reset] Errors were encountered during reset', err);
|
||
|
throw err;
|
||
10 years ago
|
}
|
||
7 years ago
|
|
||
|
winston.info('[reset] Reset complete');
|
||
|
callback();
|
||
10 years ago
|
});
|
||
|
};
|
||
|
|
||
|
function resetSettings(callback) {
|
||
8 years ago
|
meta.configs.set('allowLocalLogin', 1, function (err) {
|
||
10 years ago
|
winston.info('[reset] Settings reset to default');
|
||
8 years ago
|
callback(err);
|
||
10 years ago
|
});
|
||
|
}
|
||
|
|
||
8 years ago
|
function resetTheme(themeId, callback) {
|
||
7 years ago
|
fs.access(path.join(dirname, 'node_modules', themeId, 'package.json'), function (err) {
|
||
9 years ago
|
if (err) {
|
||
|
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
|
||
8 years ago
|
callback(new Error('theme-not-found'));
|
||
9 years ago
|
} else {
|
||
|
meta.themes.set({
|
||
|
type: 'local',
|
||
8 years ago
|
id: themeId,
|
||
8 years ago
|
}, function (err) {
|
||
9 years ago
|
if (err) {
|
||
|
winston.warn('[reset] Failed to reset theme to ' + themeId);
|
||
|
} else {
|
||
|
winston.info('[reset] Theme reset to ' + themeId);
|
||
|
}
|
||
|
|
||
8 years ago
|
callback();
|
||
8 years ago
|
});
|
||
9 years ago
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
10 years ago
|
function resetThemes(callback) {
|
||
|
meta.themes.set({
|
||
|
type: 'local',
|
||
8 years ago
|
id: 'nodebb-theme-persona',
|
||
8 years ago
|
}, function (err) {
|
||
10 years ago
|
winston.info('[reset] Theme reset to Persona');
|
||
8 years ago
|
callback(err);
|
||
10 years ago
|
});
|
||
|
}
|
||
|
|
||
8 years ago
|
function resetPlugin(pluginId, callback) {
|
||
9 years ago
|
var active = false;
|
||
|
|
||
|
async.waterfall([
|
||
|
async.apply(db.isSortedSetMember, 'plugins:active', pluginId),
|
||
8 years ago
|
function (isMember, next) {
|
||
9 years ago
|
active = isMember;
|
||
|
|
||
|
if (isMember) {
|
||
|
db.sortedSetRemove('plugins:active', pluginId, next);
|
||
|
} else {
|
||
|
next();
|
||
|
}
|
||
8 years ago
|
},
|
||
8 years ago
|
function (next) {
|
||
|
events.log({
|
||
|
type: 'plugin-deactivate',
|
||
|
text: pluginId,
|
||
|
}, next);
|
||
|
},
|
||
8 years ago
|
], function (err) {
|
||
10 years ago
|
if (err) {
|
||
7 years ago
|
winston.error('[reset] Could not disable plugin: %s encountered error %s', pluginId, err);
|
||
8 years ago
|
} else if (active) {
|
||
|
winston.info('[reset] Plugin `%s` disabled', pluginId);
|
||
10 years ago
|
} else {
|
||
8 years ago
|
winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId);
|
||
|
winston.info('[reset] No action taken.');
|
||
|
err = new Error('plugin-not-active');
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
callback(err);
|
||
10 years ago
|
});
|
||
|
}
|
||
|
|
||
|
function resetPlugins(callback) {
|
||
8 years ago
|
db.delete('plugins:active', function (err) {
|
||
10 years ago
|
winston.info('[reset] All Plugins De-activated');
|
||
8 years ago
|
callback(err);
|
||
10 years ago
|
});
|
||
|
}
|
||
|
|
||
|
function resetWidgets(callback) {
|
||
8 years ago
|
async.waterfall([
|
||
7 years ago
|
plugins.reload,
|
||
|
widgets.reset,
|
||
8 years ago
|
function (next) {
|
||
|
winston.info('[reset] All Widgets moved to Draft Zone');
|
||
|
next();
|
||
|
},
|
||
|
], callback);
|
||
10 years ago
|
}
|