diff --git a/src/events.js b/src/events.js index b2e6ed6d37..a9babcc5e3 100644 --- a/src/events.js +++ b/src/events.js @@ -14,6 +14,8 @@ const events = module.exports; events.types = [ 'plugin-activate', 'plugin-deactivate', + 'plugin-install', + 'plugin-uninstall', 'restart', 'build', 'config-change', diff --git a/src/plugins/install.js b/src/plugins/install.js index f5888fa9df..eebb384b90 100644 --- a/src/plugins/install.js +++ b/src/plugins/install.js @@ -11,7 +11,6 @@ const util = require('util'); const db = require('../database'); const meta = require('../meta'); const pubsub = require('../pubsub'); -const events = require('../events'); const statAsync = util.promisify(fs.stat); @@ -57,10 +56,6 @@ module.exports = function (Plugins) { } meta.reloadRequired = true; Plugins.fireHook(isActive ? 'action:plugin.deactivate' : 'action:plugin.activate', { id: id }); - await events.log({ - type: 'plugin-' + (isActive ? 'deactivate' : 'activate'), - text: id, - }); return { id: id, active: !isActive }; }; diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index eee514384d..0f3433e434 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -129,14 +129,27 @@ SocketAdmin.themes.set = function (socket, data, callback) { ], callback); }; -SocketAdmin.plugins.toggleActive = function (socket, plugin_id, callback) { +SocketAdmin.plugins.toggleActive = async function (socket, plugin_id) { require('../posts/cache').reset(); - plugins.toggleActive(plugin_id, callback); + const data = await plugins.toggleActive(plugin_id); + await events.log({ + type: 'plugin-' + (data.active ? 'activate' : 'deactivate'), + text: plugin_id, + uid: socket.uid, + }); + return data; }; -SocketAdmin.plugins.toggleInstall = function (socket, data, callback) { +SocketAdmin.plugins.toggleInstall = async function (socket, data) { require('../posts/cache').reset(); - plugins.toggleInstall(data.id, data.version, callback); + const pluginData = await plugins.toggleInstall(data.id, data.version); + await events.log({ + type: 'plugin-' + (pluginData.installed ? 'install' : 'uninstall'), + text: data.id, + version: data.version, + uid: socket.uid, + }); + return pluginData; }; SocketAdmin.plugins.getActive = function (socket, data, callback) { @@ -398,3 +411,5 @@ SocketAdmin.uploads.delete = function (socket, pathToFile, callback) { }; module.exports = SocketAdmin; + +require('../promisify')(SocketAdmin);