fix: cli/reset.js (#7979)

v1.18.x
Barış Soner Uşaklı 6 years ago committed by GitHub
parent 95a372df85
commit f9f85fc425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,6 @@
require('colors'); require('colors');
const path = require('path'); const path = require('path');
const winston = require('winston'); const winston = require('winston');
const async = require('async');
const fs = require('fs'); const fs = require('fs');
const util = require('util'); const util = require('util');
@ -123,55 +122,38 @@ async function resetThemeTo(themeId) {
winston.info('[reset] Theme reset to ' + themeId + ' and default skin'); winston.info('[reset] Theme reset to ' + themeId + ' and default skin');
} }
function resetPlugin(pluginId, callback) { async function resetPlugin(pluginId) {
var active = false; try {
const isActive = await db.isSortedSetMember('plugins:active', pluginId);
async.waterfall([ if (isActive) {
async.apply(db.isSortedSetMember, 'plugins:active', pluginId), await db.sortedSetRemove('plugins:active', pluginId);
function (isMember, next) {
active = isMember;
if (isMember) {
db.sortedSetRemove('plugins:active', pluginId, next);
} else {
next();
} }
},
function (next) { await events.log({
events.log({
type: 'plugin-deactivate', type: 'plugin-deactivate',
text: pluginId, text: pluginId,
}, next); });
},
], function (err) { if (isActive) {
if (err) {
winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s', err);
} else if (active) {
winston.info('[reset] Plugin `%s` disabled', pluginId); winston.info('[reset] Plugin `%s` disabled', pluginId);
} else { } else {
winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId); winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId);
winston.info('[reset] No action taken.'); winston.info('[reset] No action taken.');
err = new Error('plugin-not-active'); throw new Error('plugin-not-active');
}
} catch (err) {
winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s', err);
throw err;
} }
callback(err);
});
} }
function resetPlugins(callback) { async function resetPlugins() {
db.delete('plugins:active', function (err) { await db.delete('plugins:active');
winston.info('[reset] All Plugins De-activated'); winston.info('[reset] All Plugins De-activated');
callback(err);
});
} }
function resetWidgets(callback) { async function resetWidgets() {
async.waterfall([ await plugins.reload();
plugins.reload, await widgets.reset();
widgets.reset,
function (next) {
winston.info('[reset] All Widgets moved to Draft Zone'); winston.info('[reset] All Widgets moved to Draft Zone');
next();
},
], callback);
} }

Loading…
Cancel
Save