From b37d52c089b29204eacb6c1dcf75166666f2dab9 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 31 Jan 2017 18:38:01 +0300 Subject: [PATCH] closes #5407 --- src/plugins/hooks.js | 4 +++- src/plugins/install.js | 20 ++++++++++++-------- src/plugins/load.js | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/plugins/hooks.js b/src/plugins/hooks.js index b5a32ba1b7..a6a014e776 100644 --- a/src/plugins/hooks.js +++ b/src/plugins/hooks.js @@ -8,7 +8,9 @@ module.exports = function (Plugins) { 'filter:user.custom_fields': null, // remove in v1.1.0 'filter:post.save': 'filter:post.create', 'filter:user.profileLinks': 'filter:user.profileMenu', - 'action:post.flag': 'action:flag.create' + 'action:post.flag': 'action:flag.create', + 'action:plugin.activate': null, + 'action:plugin.install': null }; /* `data` is an object consisting of (* is required): diff --git a/src/plugins/install.js b/src/plugins/install.js index 5c6e4dddac..927316a21c 100644 --- a/src/plugins/install.js +++ b/src/plugins/install.js @@ -50,8 +50,11 @@ module.exports = function (Plugins) { }, function (next) { meta.reloadRequired = true; - Plugins.fireHook(isActive ? 'action:plugin.deactivate' : 'action:plugin.activate', {id: id}); - next(); + if (isActive) { + Plugins.fireHook('action:plugin.deactivate', {id: id}); + } + + setImmediate(next); } ], function (err) { if (err) { @@ -68,7 +71,6 @@ module.exports = function (Plugins) { }; function toggleInstall(id, version, callback) { - var type; var installed; async.waterfall([ function (next) { @@ -76,7 +78,6 @@ module.exports = function (Plugins) { }, function (_installed, next) { installed = _installed; - type = installed ? 'uninstall' : 'install'; Plugins.isActive(id, next); }, function (active, next) { @@ -86,17 +87,20 @@ module.exports = function (Plugins) { }); return; } - next(); + setImmediate(next); }, function (next) { - runNpmCommand(type, id, version || 'latest', next); + runNpmCommand(installed ? 'uninstall' : 'install', id, version || 'latest', next); }, function (next) { Plugins.get(id, next); }, function (pluginData, next) { - Plugins.fireHook('action:plugin.' + type, {id: id, version: version}); - next(null, pluginData); + if (installed) { + Plugins.fireHook('action:plugin.uninstall', {id: id, version: version}); + } + + setImmediate(next, null, pluginData); } ], callback); } diff --git a/src/plugins/load.js b/src/plugins/load.js index 43c3d96f4c..c1d1edf6eb 100644 --- a/src/plugins/load.js +++ b/src/plugins/load.js @@ -88,7 +88,7 @@ module.exports = function (Plugins) { }, function (next) { mapClientModules(pluginData, next); - }, + } ], function (err) { if (err) { winston.verbose('[plugins] Could not load plugin : ' + pluginData.id);