Skip to content

Commit

Permalink
fix: cli/reset.js (#7979)
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Oct 17, 2019
1 parent 95a372d commit f9f85fc
Showing 1 changed file with 23 additions and 41 deletions.
64 changes: 23 additions & 41 deletions src/cli/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require('colors');
const path = require('path');
const winston = require('winston');
const async = require('async');
const fs = require('fs');
const util = require('util');

Expand Down Expand Up @@ -123,55 +122,38 @@ async function resetThemeTo(themeId) {
winston.info('[reset] Theme reset to ' + themeId + ' and default skin');
}

function resetPlugin(pluginId, callback) {
var active = false;
async function resetPlugin(pluginId) {
try {
const isActive = await db.isSortedSetMember('plugins:active', pluginId);
if (isActive) {
await db.sortedSetRemove('plugins:active', pluginId);
}

async.waterfall([
async.apply(db.isSortedSetMember, 'plugins:active', pluginId),
function (isMember, next) {
active = isMember;
await events.log({
type: 'plugin-deactivate',
text: pluginId,
});

if (isMember) {
db.sortedSetRemove('plugins:active', pluginId, next);
} else {
next();
}
},
function (next) {
events.log({
type: 'plugin-deactivate',
text: pluginId,
}, next);
},
], function (err) {
if (err) {
winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s', err);
} else if (active) {
if (isActive) {
winston.info('[reset] Plugin `%s` disabled', pluginId);
} else {
winston.warn('[reset] Plugin `%s` was not active on this forum', pluginId);
winston.info('[reset] No action taken.');
err = new Error('plugin-not-active');
throw new Error('plugin-not-active');
}

callback(err);
});
} catch (err) {
winston.error('[reset] Could not disable plugin: ' + pluginId + ' encountered error %s', err);
throw err;
}
}

function resetPlugins(callback) {
db.delete('plugins:active', function (err) {
winston.info('[reset] All Plugins De-activated');
callback(err);
});
async function resetPlugins() {
await db.delete('plugins:active');
winston.info('[reset] All Plugins De-activated');
}

function resetWidgets(callback) {
async.waterfall([
plugins.reload,
widgets.reset,
function (next) {
winston.info('[reset] All Widgets moved to Draft Zone');
next();
},
], callback);
async function resetWidgets() {
await plugins.reload();
await widgets.reset();
winston.info('[reset] All Widgets moved to Draft Zone');
}

0 comments on commit f9f85fc

Please sign in to comment.