added new hook filter:app.load, and deprecated action:app.load, hopefully fixes #1822

v1.18.x
Julian Lam 11 years ago
parent 67d5307a8f
commit 645eb051ec

@ -266,7 +266,6 @@ var fs = require('fs'),
`data` is an object consisting of (* is required): `data` is an object consisting of (* is required):
`data.hook`*, the name of the NodeBB hook `data.hook`*, the name of the NodeBB hook
`data.method`*, the method called in that plugin `data.method`*, the method called in that plugin
`data.callbacked`, whether or not the hook expects a callback (true), or a return (false). Only used for filters. (Default: false)
`data.priority`, the relative priority of the method when it is eventually called (default: 10) `data.priority`, the relative priority of the method when it is eventually called (default: 10)
*/ */
@ -327,6 +326,10 @@ var fs = require('fs'),
next(arguments[0], Array.prototype.slice.call(arguments, 1)); next(arguments[0], Array.prototype.slice.call(arguments, 1));
})); }));
/*
Backwards compatibility block for v0.5.0
Remove this once NodeBB enters v0.5.0-1
*/
if (value !== undefined && value !== callback) { if (value !== undefined && value !== callback) {
winston.warn('[plugins/' + hookObj.id + '] "callbacked" deprecated as of 0.4x. Use asynchronous method instead for hook: ' + hook); winston.warn('[plugins/' + hookObj.id + '] "callbacked" deprecated as of 0.4x. Use asynchronous method instead for hook: ' + hook);
next(null, [value]); next(null, [value]);
@ -353,7 +356,17 @@ var fs = require('fs'),
}); });
break; break;
case 'action': case 'action':
async.each(hookList, function(hookObj) { var deprecationWarn = [];
async.each(hookList, function(hookObj, next) {
/*
Backwards compatibility block for v0.5.0
Remove this once NodeBB enters v0.5.0-1
*/
if (hook === 'action:app.load') {
deprecationWarn.push(hookObj.id);
}
/* End backwards compatibility block */
if (hookObj.method) { if (hookObj.method) {
hookObj.method.apply(Plugins, args); hookObj.method.apply(Plugins, args);
} else { } else {
@ -361,6 +374,15 @@ var fs = require('fs'),
winston.info('[plugins] Expected method \'' + hookObj.method + '\' in plugin \'' + hookObj.id + '\' not found, skipping.'); winston.info('[plugins] Expected method \'' + hookObj.method + '\' in plugin \'' + hookObj.id + '\' not found, skipping.');
} }
} }
next();
}, function() {
if (deprecationWarn.length) {
winston.warn('[plugins] The `action:app.load` hook is deprecated in favour of `filter:app.load`, please notify the developers of the following plugins:');
for(var x=0,numDeprec=deprecationWarn.length;x<numDeprec;x++) {
process.stdout.write(' * ' + deprecationWarn[x] + '\n');
}
}
}); });
break; break;
default: default:

@ -164,6 +164,7 @@ module.exports = function(app, middleware) {
router.all('/admin/*', middleware.admin.isAdmin); router.all('/admin/*', middleware.admin.isAdmin);
router.get('/admin', middleware.admin.isAdmin); router.get('/admin', middleware.admin.isAdmin);
// Deprecated as of v0.5.0, remove this hook call for NodeBB v0.6.0-1
plugins.fireHook('action:app.load', app, middleware, controllers); plugins.fireHook('action:app.load', app, middleware, controllers);
adminRoutes(router, middleware, controllers); adminRoutes(router, middleware, controllers);
@ -186,6 +187,7 @@ module.exports = function(app, middleware) {
userRoutes(router, middleware, controllers); userRoutes(router, middleware, controllers);
groupRoutes(router, middleware, controllers); groupRoutes(router, middleware, controllers);
plugins.fireHook('filter:app.load', app, middleware, controllers, function() {
app.use(nconf.get('relative_path'), router); app.use(nconf.get('relative_path'), router);
app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../../', 'public'), { app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../../', 'public'), {
@ -194,6 +196,7 @@ module.exports = function(app, middleware) {
app.use(catch404); app.use(catch404);
app.use(handleErrors); app.use(handleErrors);
}); });
});
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
require('./debug')(app, middleware, controllers); require('./debug')(app, middleware, controllers);

Loading…
Cancel
Save