Skip to content

Node.js based forum software built for the modern web

closes #5585

Julian Lam29e868b00283
diff --git a/app.js b/app.js
index edb8565559..90f5ef046e 100644
--- a/app.js
+++ b/app.js
@@ -90,6 +90,11 @@ if (nconf.get('setup') || nconf.get('install')) {
listPlugins();
} else if (nconf.get('build')) {
require('./src/meta/build').build(nconf.get('build'));
+} else if (nconf.get('events')) {
+ async.series([
+ async.apply(require('./src/database').init),
+ async.apply(require('./src/events').output),
+ ]);
} else {
require('./src/start').start();
}
@@ -218,6 +223,7 @@ function upgrade() {
function activate() {
var db = require('./src/database');
var plugins = require('./src/plugins');
+ var events = require('./src/events');
var plugin = nconf.get('activate');
async.waterfall([
function (next) {
@@ -238,6 +244,12 @@ function activate() {
winston.info('Activating plugin `%s`', plugin);
db.sortedSetAdd('plugins:active', 0, plugin, next);
},
+ function (next) {
+ events.log({
+ type: 'plugin-activate',
+ text: plugin,
+ }, next);
+ },
], function (err) {
if (err) {
winston.error(err.message);
diff --git a/nodebb b/nodebb
index 2b71185d4e..45e0ebaec3 100755
--- a/nodebb
+++ b/nodebb
@@ -495,6 +495,13 @@ var commands = {
upgradePlugins();
},
},
+ events: {
+ description: 'Outputs the last ten (10) administrative events recorded by NodeBB',
+ usage: 'Usage: ' + './nodebb events'.yellow,
+ handler: function () {
+ fork(['--events']);
+ },
+ },
help: {
description: 'Display the help message for a given command',
usage: 'Usage: ' + './nodebb help <command>'.yellow,
diff --git a/src/events.js b/src/events.js
index 48307b868d..ffce83beb4 100644
--- a/src/events.js
+++ b/src/events.js
@@ -138,3 +138,19 @@ events.deleteAll = function (callback) {
events.deleteEvents(eids, next);
}, { alwaysStartAt: 0 }, callback);
};
+
+events.output = function () {
+ process.stdout.write('\nDisplaying last ten administrative events...\n'.bold);
+ events.getEvents(0, 9, function (err, events) {
+ if (err) {
+ process.stdout.write(' Error '.red + String(err.message).reset);
+ process.exit(1);
+ }
+
+ events.forEach(function (event) {
+ process.stdout.write(' * ' + String(event.timestampISO).green + ' ' + String(event.type).yellow + (event.text ? ' ' + event.text : '') + ' (uid: '.reset + (event.uid ? event.uid : 0) + ')\n');
+ });
+
+ process.exit(0);
+ });
+};
diff --git a/src/plugins/install.js b/src/plugins/install.js
index a5ba2db1dd..011fe2db11 100644
--- a/src/plugins/install.js
+++ b/src/plugins/install.js
@@ -10,7 +10,7 @@ var os = require('os');
var db = require('../database');
var meta = require('../meta');
var pubsub = require('../pubsub');
-
+var events = require('../events');
module.exports = function (Plugins) {
if (nconf.get('isPrimary') === 'true') {
@@ -52,6 +52,12 @@ module.exports = function (Plugins) {
Plugins.fireHook(isActive ? 'action:plugin.deactivate' : 'action:plugin.activate', { id: id });
setImmediate(next);
},
+ function (next) {
+ events.log({
+ type: 'plugin-' + (isActive ? 'deactivate' : 'activate'),
+ text: id,
+ }, next);
+ },
], function (err) {
if (err) {
winston.warn('[plugins] Could not toggle active state on plugin \'' + id + '\'');
diff --git a/src/reset.js b/src/reset.js
index 2e5fcd421c..4b45821ddf 100644
--- a/src/reset.js
+++ b/src/reset.js
@@ -6,6 +6,7 @@ var winston = require('winston');
var nconf = require('nconf');
var async = require('async');
var db = require('./database');
+var events = require('./events');
var Reset = {};
@@ -133,6 +134,12 @@ function resetPlugin(pluginId, callback) {
next();
}
},
+ function (next) {
+ events.log({
+ type: 'plugin-deactivate',
+ text: pluginId,
+ }, next);
+ },
], function (err) {
if (err) {
winston.error('[reset] Could not disable plugin: %s encountered error %s', pluginId, err.message);