2015-09-17 21:54:12 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2017-06-01 15:46:35 -04:00
|
|
|
require('colors');
|
2019-10-09 23:58:24 -04:00
|
|
|
const path = require('path');
|
|
|
|
|
const winston = require('winston');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
const db = require('../database');
|
|
|
|
|
const events = require('../events');
|
|
|
|
|
const meta = require('../meta');
|
|
|
|
|
const plugins = require('../plugins');
|
|
|
|
|
const widgets = require('../widgets');
|
|
|
|
|
const privileges = require('../privileges');
|
2020-10-01 21:02:44 -06:00
|
|
|
const { paths, pluginNamePattern, themeNamePattern } = require('../constants');
|
2019-10-09 23:58:24 -04:00
|
|
|
|
|
|
|
|
exports.reset = async function (options) {
|
|
|
|
|
const map = {
|
|
|
|
|
theme: async function () {
|
|
|
|
|
let themeId = options.theme;
|
2017-02-15 09:47:38 -05:00
|
|
|
if (themeId === true) {
|
2019-10-09 23:58:24 -04:00
|
|
|
await resetThemes();
|
2016-03-09 19:53:09 +00:00
|
|
|
} else {
|
2018-06-09 16:26:28 -06:00
|
|
|
if (!themeNamePattern.test(themeId)) {
|
2017-02-15 09:47:38 -05:00
|
|
|
// Allow omission of `nodebb-theme-`
|
|
|
|
|
themeId = 'nodebb-theme-' + themeId;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 23:58:24 -04:00
|
|
|
await resetTheme(themeId);
|
2016-03-09 19:53:09 +00:00
|
|
|
}
|
CLI refactor with commander (#6058)
* CLI refactor with commander
- Modularized the functionality
- All functionality done directly from `./nodebb` now
(still available from `app` for backwards compatibility)
- Moved all CLI code from `./nodebb` to `src/cli`
- Fixed `nodebb.bat` to work from any location, like `./nodebb`, and
also hides command output
- Overwrite some commander methods to add CLI color support
- Added `./nodebb info` for quick info including git hash, NodeBB
version, node version, and some database info
- Refactored `./nodebb reset` to allow multiple resets at once
- Changed `./nodebb restart` to essentially stop and start, as Windows
doesn't support signals
- Added `-l, --log` option which works on `./nodebb start` and `./nodebb
restart` to show logging, like `./nodebb slog`
- Expanded `-d, --dev` option which works on them as well, like
`./nodebb dev`
- Improvements to self-help. `./nodebb build -h` will output all
possible targets
- `./nodebb reset` explains usage better
* Fix some style inconsistencies
* Fix prestart being required before modules installed
* Fix travis failures
* Fix `help` command to output help for subcommands
* Pick steps of the upgrade process to run
* Fix formatting for upgrade help
* Fix web installer
2017-11-23 08:55:03 -07:00
|
|
|
},
|
2019-10-09 23:58:24 -04:00
|
|
|
plugin: async function () {
|
|
|
|
|
let pluginId = options.plugin;
|
2017-02-15 09:47:38 -05:00
|
|
|
if (pluginId === true) {
|
2019-10-09 23:58:24 -04:00
|
|
|
await resetPlugins();
|
2015-09-17 21:54:12 -04:00
|
|
|
} else {
|
2018-06-09 16:26:28 -06:00
|
|
|
if (!pluginNamePattern.test(pluginId)) {
|
2017-02-15 09:47:38 -05:00
|
|
|
// Allow omission of `nodebb-plugin-`
|
|
|
|
|
pluginId = 'nodebb-plugin-' + pluginId;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 23:58:24 -04:00
|
|
|
await resetPlugin(pluginId);
|
2015-09-17 21:54:12 -04:00
|
|
|
}
|
CLI refactor with commander (#6058)
* CLI refactor with commander
- Modularized the functionality
- All functionality done directly from `./nodebb` now
(still available from `app` for backwards compatibility)
- Moved all CLI code from `./nodebb` to `src/cli`
- Fixed `nodebb.bat` to work from any location, like `./nodebb`, and
also hides command output
- Overwrite some commander methods to add CLI color support
- Added `./nodebb info` for quick info including git hash, NodeBB
version, node version, and some database info
- Refactored `./nodebb reset` to allow multiple resets at once
- Changed `./nodebb restart` to essentially stop and start, as Windows
doesn't support signals
- Added `-l, --log` option which works on `./nodebb start` and `./nodebb
restart` to show logging, like `./nodebb slog`
- Expanded `-d, --dev` option which works on them as well, like
`./nodebb dev`
- Improvements to self-help. `./nodebb build -h` will output all
possible targets
- `./nodebb reset` explains usage better
* Fix some style inconsistencies
* Fix prestart being required before modules installed
* Fix travis failures
* Fix `help` command to output help for subcommands
* Pick steps of the upgrade process to run
* Fix formatting for upgrade help
* Fix web installer
2017-11-23 08:55:03 -07:00
|
|
|
},
|
|
|
|
|
widgets: resetWidgets,
|
|
|
|
|
settings: resetSettings,
|
2019-10-09 23:58:24 -04:00
|
|
|
all: async function () {
|
|
|
|
|
await resetWidgets();
|
|
|
|
|
await resetThemes();
|
|
|
|
|
await resetPlugin();
|
|
|
|
|
await resetSettings();
|
CLI refactor with commander (#6058)
* CLI refactor with commander
- Modularized the functionality
- All functionality done directly from `./nodebb` now
(still available from `app` for backwards compatibility)
- Moved all CLI code from `./nodebb` to `src/cli`
- Fixed `nodebb.bat` to work from any location, like `./nodebb`, and
also hides command output
- Overwrite some commander methods to add CLI color support
- Added `./nodebb info` for quick info including git hash, NodeBB
version, node version, and some database info
- Refactored `./nodebb reset` to allow multiple resets at once
- Changed `./nodebb restart` to essentially stop and start, as Windows
doesn't support signals
- Added `-l, --log` option which works on `./nodebb start` and `./nodebb
restart` to show logging, like `./nodebb slog`
- Expanded `-d, --dev` option which works on them as well, like
`./nodebb dev`
- Improvements to self-help. `./nodebb build -h` will output all
possible targets
- `./nodebb reset` explains usage better
* Fix some style inconsistencies
* Fix prestart being required before modules installed
* Fix travis failures
* Fix `help` command to output help for subcommands
* Pick steps of the upgrade process to run
* Fix formatting for upgrade help
* Fix web installer
2017-11-23 08:55:03 -07:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-09 23:58:24 -04:00
|
|
|
const tasks = Object.keys(map).filter(x => options[x]).map(x => map[x]);
|
CLI refactor with commander (#6058)
* CLI refactor with commander
- Modularized the functionality
- All functionality done directly from `./nodebb` now
(still available from `app` for backwards compatibility)
- Moved all CLI code from `./nodebb` to `src/cli`
- Fixed `nodebb.bat` to work from any location, like `./nodebb`, and
also hides command output
- Overwrite some commander methods to add CLI color support
- Added `./nodebb info` for quick info including git hash, NodeBB
version, node version, and some database info
- Refactored `./nodebb reset` to allow multiple resets at once
- Changed `./nodebb restart` to essentially stop and start, as Windows
doesn't support signals
- Added `-l, --log` option which works on `./nodebb start` and `./nodebb
restart` to show logging, like `./nodebb slog`
- Expanded `-d, --dev` option which works on them as well, like
`./nodebb dev`
- Improvements to self-help. `./nodebb build -h` will output all
possible targets
- `./nodebb reset` explains usage better
* Fix some style inconsistencies
* Fix prestart being required before modules installed
* Fix travis failures
* Fix `help` command to output help for subcommands
* Pick steps of the upgrade process to run
* Fix formatting for upgrade help
* Fix web installer
2017-11-23 08:55:03 -07:00
|
|
|
|
|
|
|
|
if (!tasks.length) {
|
2017-11-27 13:44:30 -07:00
|
|
|
console.log([
|
|
|
|
|
'No arguments passed in, so nothing was reset.\n'.yellow,
|
|
|
|
|
'Use ./nodebb reset ' + '{-t|-p|-w|-s|-a}'.red,
|
|
|
|
|
' -t\tthemes',
|
|
|
|
|
' -p\tplugins',
|
|
|
|
|
' -w\twidgets',
|
|
|
|
|
' -s\tsettings',
|
|
|
|
|
' -a\tall of the above',
|
|
|
|
|
'',
|
|
|
|
|
'Plugin and theme reset flags (-p & -t) can take a single argument',
|
|
|
|
|
' e.g. ./nodebb reset -p nodebb-plugin-mentions, ./nodebb reset -t nodebb-theme-persona',
|
|
|
|
|
' Prefix is optional, e.g. ./nodebb reset -p markdown, ./nodebb reset -t persona',
|
|
|
|
|
].join('\n'));
|
CLI refactor with commander (#6058)
* CLI refactor with commander
- Modularized the functionality
- All functionality done directly from `./nodebb` now
(still available from `app` for backwards compatibility)
- Moved all CLI code from `./nodebb` to `src/cli`
- Fixed `nodebb.bat` to work from any location, like `./nodebb`, and
also hides command output
- Overwrite some commander methods to add CLI color support
- Added `./nodebb info` for quick info including git hash, NodeBB
version, node version, and some database info
- Refactored `./nodebb reset` to allow multiple resets at once
- Changed `./nodebb restart` to essentially stop and start, as Windows
doesn't support signals
- Added `-l, --log` option which works on `./nodebb start` and `./nodebb
restart` to show logging, like `./nodebb slog`
- Expanded `-d, --dev` option which works on them as well, like
`./nodebb dev`
- Improvements to self-help. `./nodebb build -h` will output all
possible targets
- `./nodebb reset` explains usage better
* Fix some style inconsistencies
* Fix prestart being required before modules installed
* Fix travis failures
* Fix `help` command to output help for subcommands
* Pick steps of the upgrade process to run
* Fix formatting for upgrade help
* Fix web installer
2017-11-23 08:55:03 -07:00
|
|
|
|
|
|
|
|
process.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 23:58:24 -04:00
|
|
|
try {
|
|
|
|
|
await db.init();
|
|
|
|
|
for (const task of tasks) {
|
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
|
await task();
|
2015-09-17 21:54:12 -04:00
|
|
|
}
|
2019-11-20 13:45:29 -05:00
|
|
|
winston.info('[reset] Reset complete. Please run `./nodebb build` to rebuild assets.');
|
2019-10-09 23:58:24 -04:00
|
|
|
process.exit(0);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
winston.error('[reset] Errors were encountered during reset -- ' + err.message);
|
2019-11-20 13:45:29 -05:00
|
|
|
process.exit(1);
|
2019-10-09 23:58:24 -04:00
|
|
|
}
|
2015-09-17 21:54:12 -04:00
|
|
|
};
|
|
|
|
|
|
2019-10-09 23:58:24 -04:00
|
|
|
async function resetSettings() {
|
2020-05-26 21:57:38 -04:00
|
|
|
await privileges.global.give(['groups:local:login'], 'registered-users');
|
2019-10-09 23:58:24 -04:00
|
|
|
winston.info('[reset] registered-users given login privilege');
|
|
|
|
|
winston.info('[reset] Settings reset to default');
|
2015-09-17 21:54:12 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-09 23:58:24 -04:00
|
|
|
async function resetTheme(themeId) {
|
|
|
|
|
try {
|
2020-10-01 21:02:44 -06:00
|
|
|
await fs.promises.access(path.join(paths.nodeModules, themeId, 'package.json'));
|
2019-10-09 23:58:24 -04:00
|
|
|
} catch (err) {
|
|
|
|
|
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
|
|
|
|
|
throw new Error('theme-not-found');
|
|
|
|
|
}
|
|
|
|
|
await resetThemeTo(themeId);
|
|
|
|
|
}
|
2016-08-16 19:46:59 +02:00
|
|
|
|
2019-10-09 23:58:24 -04:00
|
|
|
async function resetThemes() {
|
|
|
|
|
await resetThemeTo('nodebb-theme-persona');
|
2016-03-09 19:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-09 23:58:24 -04:00
|
|
|
async function resetThemeTo(themeId) {
|
|
|
|
|
await meta.themes.set({
|
2015-09-17 21:54:12 -04:00
|
|
|
type: 'local',
|
2019-10-09 23:58:24 -04:00
|
|
|
id: themeId,
|
2015-09-17 21:54:12 -04:00
|
|
|
});
|
2019-10-09 23:58:24 -04:00
|
|
|
await meta.configs.set('bootswatchSkin', '');
|
|
|
|
|
winston.info('[reset] Theme reset to ' + themeId + ' and default skin');
|
2015-09-17 21:54:12 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-16 20:50:38 -04:00
|
|
|
async function resetPlugin(pluginId) {
|
|
|
|
|
try {
|
|
|
|
|
const isActive = await db.isSortedSetMember('plugins:active', pluginId);
|
|
|
|
|
if (isActive) {
|
|
|
|
|
await db.sortedSetRemove('plugins:active', pluginId);
|
|
|
|
|
}
|
2015-11-28 23:22:39 -05:00
|
|
|
|
2019-10-16 20:50:38 -04:00
|
|
|
await events.log({
|
|
|
|
|
type: 'plugin-deactivate',
|
|
|
|
|
text: pluginId,
|
|
|
|
|
});
|
2015-11-28 23:22:39 -05:00
|
|
|
|
2019-10-16 20:50:38 -04:00
|
|
|
if (isActive) {
|
2017-02-18 14:32:35 -07:00
|
|
|
winston.info('[reset] Plugin `%s` disabled', pluginId);
|
2015-09-17 21:54:12 -04:00
|
|
|
} else {
|
2017-02-18 14:32:35 -07:00
|
|
|
winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId);
|
|
|
|
|
winston.info('[reset] No action taken.');
|
2015-09-17 21:54:12 -04:00
|
|
|
}
|
2019-10-16 20:50:38 -04:00
|
|
|
} catch (err) {
|
2020-11-26 13:56:34 -05:00
|
|
|
winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s\n' + err.stack);
|
2019-10-16 20:50:38 -04:00
|
|
|
throw err;
|
|
|
|
|
}
|
2015-09-17 21:54:12 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-16 20:50:38 -04:00
|
|
|
async function resetPlugins() {
|
|
|
|
|
await db.delete('plugins:active');
|
|
|
|
|
winston.info('[reset] All Plugins De-activated');
|
2015-09-17 21:54:12 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-16 20:50:38 -04:00
|
|
|
async function resetWidgets() {
|
|
|
|
|
await plugins.reload();
|
|
|
|
|
await widgets.reset();
|
|
|
|
|
winston.info('[reset] All Widgets moved to Draft Zone');
|
2015-09-17 22:15:28 -04:00
|
|
|
}
|