|
|
|
@ -1,61 +1,65 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
require('colors');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var winston = require('winston');
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var fs = require('fs');
|
|
|
|
|
|
|
|
|
|
var db = require('../database');
|
|
|
|
|
var events = require('../events');
|
|
|
|
|
var meta = require('../meta');
|
|
|
|
|
var plugins = require('../plugins');
|
|
|
|
|
var widgets = require('../widgets');
|
|
|
|
|
var privileges = require('../privileges');
|
|
|
|
|
|
|
|
|
|
var dirname = require('./paths').baseDir;
|
|
|
|
|
|
|
|
|
|
var themeNamePattern = /^(@.*?\/)?nodebb-theme-.*$/;
|
|
|
|
|
var pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/;
|
|
|
|
|
|
|
|
|
|
exports.reset = function (options, callback) {
|
|
|
|
|
var map = {
|
|
|
|
|
theme: function (next) {
|
|
|
|
|
var themeId = options.theme;
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const winston = require('winston');
|
|
|
|
|
const async = require('async');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const util = require('util');
|
|
|
|
|
|
|
|
|
|
const fsAccessAsync = util.promisify(fs.access);
|
|
|
|
|
|
|
|
|
|
const db = require('../database');
|
|
|
|
|
const events = require('../events');
|
|
|
|
|
const meta = require('../meta');
|
|
|
|
|
const plugins = require('../plugins');
|
|
|
|
|
const widgets = require('../widgets');
|
|
|
|
|
const privileges = require('../privileges');
|
|
|
|
|
|
|
|
|
|
const dirname = require('./paths').baseDir;
|
|
|
|
|
|
|
|
|
|
const themeNamePattern = /^(@.*?\/)?nodebb-theme-.*$/;
|
|
|
|
|
const pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/;
|
|
|
|
|
|
|
|
|
|
exports.reset = async function (options) {
|
|
|
|
|
const map = {
|
|
|
|
|
theme: async function () {
|
|
|
|
|
let themeId = options.theme;
|
|
|
|
|
if (themeId === true) {
|
|
|
|
|
resetThemes(next);
|
|
|
|
|
await resetThemes();
|
|
|
|
|
} else {
|
|
|
|
|
if (!themeNamePattern.test(themeId)) {
|
|
|
|
|
// Allow omission of `nodebb-theme-`
|
|
|
|
|
themeId = 'nodebb-theme-' + themeId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetTheme(themeId, next);
|
|
|
|
|
await resetTheme(themeId);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
plugin: function (next) {
|
|
|
|
|
var pluginId = options.plugin;
|
|
|
|
|
plugin: async function () {
|
|
|
|
|
let pluginId = options.plugin;
|
|
|
|
|
if (pluginId === true) {
|
|
|
|
|
resetPlugins(next);
|
|
|
|
|
await resetPlugins();
|
|
|
|
|
} else {
|
|
|
|
|
if (!pluginNamePattern.test(pluginId)) {
|
|
|
|
|
// Allow omission of `nodebb-plugin-`
|
|
|
|
|
pluginId = 'nodebb-plugin-' + pluginId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetPlugin(pluginId, next);
|
|
|
|
|
await resetPlugin(pluginId);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
widgets: resetWidgets,
|
|
|
|
|
settings: resetSettings,
|
|
|
|
|
all: function (next) {
|
|
|
|
|
async.series([resetWidgets, resetThemes, resetPlugins, resetSettings], next);
|
|
|
|
|
all: async function () {
|
|
|
|
|
await resetWidgets();
|
|
|
|
|
await resetThemes();
|
|
|
|
|
await resetPlugin();
|
|
|
|
|
await resetSettings();
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var tasks = Object.keys(map)
|
|
|
|
|
.filter(function (x) { return options[x]; })
|
|
|
|
|
.map(function (x) { return map[x]; });
|
|
|
|
|
const tasks = Object.keys(map).filter(x => options[x]).map(x => map[x]);
|
|
|
|
|
|
|
|
|
|
if (!tasks.length) {
|
|
|
|
|
console.log([
|
|
|
|
@ -75,58 +79,48 @@ exports.reset = function (options, callback) {
|
|
|
|
|
process.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.series([db.init].concat(tasks), function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error('[reset] Errors were encountered during reset -- ' + err.message);
|
|
|
|
|
return callback(err);
|
|
|
|
|
try {
|
|
|
|
|
await db.init();
|
|
|
|
|
for (const task of tasks) {
|
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
|
await task();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
winston.info('[reset] Reset complete');
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
await require('../meta/build').buildAll();
|
|
|
|
|
process.exit(0);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
winston.error('[reset] Errors were encountered during reset -- ' + err.message);
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function resetSettings(callback) {
|
|
|
|
|
privileges.global.give(['local:login'], 'registered-users', function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
winston.info('[reset] registered-users given login privilege');
|
|
|
|
|
winston.info('[reset] Settings reset to default');
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
async function resetSettings() {
|
|
|
|
|
await privileges.global.give(['local:login'], 'registered-users');
|
|
|
|
|
winston.info('[reset] registered-users given login privilege');
|
|
|
|
|
winston.info('[reset] Settings reset to default');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetTheme(themeId, callback) {
|
|
|
|
|
fs.access(path.join(dirname, 'node_modules', themeId, 'package.json'), function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
|
|
|
|
|
callback(new Error('theme-not-found'));
|
|
|
|
|
} else {
|
|
|
|
|
meta.themes.set({
|
|
|
|
|
type: 'local',
|
|
|
|
|
id: themeId,
|
|
|
|
|
}, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.warn('[reset] Failed to reset theme to ' + themeId);
|
|
|
|
|
} else {
|
|
|
|
|
winston.info('[reset] Theme reset to ' + themeId);
|
|
|
|
|
}
|
|
|
|
|
async function resetTheme(themeId) {
|
|
|
|
|
try {
|
|
|
|
|
await fsAccessAsync(path.join(dirname, 'node_modules', themeId, 'package.json'));
|
|
|
|
|
} catch (err) {
|
|
|
|
|
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
|
|
|
|
|
throw new Error('theme-not-found');
|
|
|
|
|
}
|
|
|
|
|
await resetThemeTo(themeId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
async function resetThemes() {
|
|
|
|
|
await resetThemeTo('nodebb-theme-persona');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetThemes(callback) {
|
|
|
|
|
meta.themes.set({
|
|
|
|
|
async function resetThemeTo(themeId) {
|
|
|
|
|
await meta.themes.set({
|
|
|
|
|
type: 'local',
|
|
|
|
|
id: 'nodebb-theme-persona',
|
|
|
|
|
}, function (err) {
|
|
|
|
|
winston.info('[reset] Theme reset to Persona');
|
|
|
|
|
callback(err);
|
|
|
|
|
id: themeId,
|
|
|
|
|
});
|
|
|
|
|
await meta.configs.set('bootswatchSkin', '');
|
|
|
|
|
winston.info('[reset] Theme reset to ' + themeId + ' and default skin');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetPlugin(pluginId, callback) {
|
|
|
|
|