mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
Merge pull request #4162 from akhoury/master
add continuation-local-storage (CLS) support
This commit is contained in:
@@ -8,6 +8,28 @@ module.exports = function(Plugins) {
|
||||
'filter:user.custom_fields': null // remove in v1.1.0
|
||||
};
|
||||
|
||||
Plugins.deprecatedHooksParams = {
|
||||
'action:homepage.get': '{req, res}',
|
||||
'filter:register.check': '{req, res}',
|
||||
'action:user.loggedOut': '{req, res}',
|
||||
'static:user.loggedOut': '{req, res}',
|
||||
'filter:categories.build': '{req, res}',
|
||||
'filter:category.build': '{req, res}',
|
||||
'filter:group.build': '{req, res}',
|
||||
'filter:register.build': '{req, res}',
|
||||
'filter:composer.build': '{req, res}',
|
||||
'filter:popular.build': '{req, res}',
|
||||
'filter:recent.build': '{req, res}',
|
||||
'filter:topic.build': '{req, res}',
|
||||
'filter:users.build': '{req, res}',
|
||||
'filter:admin.category.get': '{req, res}',
|
||||
'filter:middleware.renderHeader': '{req, res}',
|
||||
'filter:widget.render': '{req, res}',
|
||||
'filter:middleware.buildHeader': '{req, locals}',
|
||||
'action:middleware.pageView': '{req}',
|
||||
'action:meta.override404': '{req}'
|
||||
};
|
||||
|
||||
/*
|
||||
`data` is an object consisting of (* is required):
|
||||
`data.hook`*, the name of the NodeBB hook
|
||||
@@ -27,12 +49,23 @@ module.exports = function(Plugins) {
|
||||
var method;
|
||||
|
||||
if (Object.keys(Plugins.deprecatedHooks).indexOf(data.hook) !== -1) {
|
||||
winston.warn('[plugins/' + id + '] Hook `' + data.hook + '` is deprecated, ' +
|
||||
winston.warn('[plugins/' + id + '] Hook `' + data.hook + '` is deprecated, ' +
|
||||
(Plugins.deprecatedHooks[data.hook] ?
|
||||
'please use `' + Plugins.deprecatedHooks[data.hook] + '` instead.' :
|
||||
'there is no alternative.'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// handle hook's startsWith, i.e. action:homepage.get
|
||||
var _parts = data.hook.split(':');
|
||||
_parts.pop();
|
||||
var _hook = _parts.join(':');
|
||||
if (Plugins.deprecatedHooksParams[_hook]) {
|
||||
winston.warn('[plugins/' + id + '] Hook `' + _hook + '` parameters: `' + Plugins.deprecatedHooksParams[_hook] + '`, are being deprecated, '
|
||||
+ 'all plugins should now use the `middleware/cls` module instead of hook\'s arguments to get a reference to the `req`, `res` and/or `socket` object(s) (from which you can get the current `uid` if you need to.) '
|
||||
+ '- for more info, visit https://docs.nodebb.org/en/latest/plugins/create.html#getting-a-reference-to-each-request-from-within-any-plugin-hook');
|
||||
delete Plugins.deprecatedHooksParams[_hook];
|
||||
}
|
||||
}
|
||||
|
||||
if (data.hook && data.method) {
|
||||
|
||||
Reference in New Issue
Block a user