From f47c06279ae1a79a9acbe432b8e6de76e3f6dd53 Mon Sep 17 00:00:00 2001 From: akhoury Date: Tue, 16 Feb 2016 23:07:36 -0500 Subject: [PATCH] added depracation warning --- src/plugins/hooks.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/plugins/hooks.js b/src/plugins/hooks.js index 3330608154..7148654eeb 100644 --- a/src/plugins/hooks.js +++ b/src/plugins/hooks.js @@ -10,6 +10,9 @@ module.exports = function(Plugins) { 'action:user.loggedOut': 'static:user.loggedOut' }; + // todo: remove when breaking all hooks params by removing req/res/socket/uid + Plugins.clsDeprecatedParamsWarnedHooks = {}; + /* `data` is an object consisting of (* is required): `data.hook`*, the name of the NodeBB hook @@ -29,7 +32,7 @@ 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.' @@ -71,6 +74,20 @@ module.exports = function(Plugins) { var hookList = Plugins.loadedHooks[hook]; var hookType = hook.split(':')[0]; + // todo: remove when breaking all hooks params by removing req/res/socket/uid + if (!Plugins.clsDeprecatedParamsWarnedHooks[hook] + && params + && Array.isArray(hookList) + && hookList.length + && (params.req || params.res || params.socket || params.uid)) { + + Plugins.clsDeprecatedParamsWarnedHooks[hook] = true; + + winston.warn('[plugins] hook `' + hook + '` \'s `params.req`, `params.res`, `params.uid` and `params.socket` are being deprecated, ' + + 'plugins should use the `middleware/cls` module instead to get a reference to the http-req/res and socket (which you can get the current `uid`) ' + + '- for more info, visit https://docs.nodebb.org/en/latest/plugins/create.html#getting-a-reference-to-req-res-socket-and-uid-within-any-plugin-hook'); + } + switch (hookType) { case 'filter': fireFilterHook(hook, hookList, params, callback);