From 374fa8dd8c68e57e2eed6f2a1bee45b25672ef23 Mon Sep 17 00:00:00 2001 From: Aziz Khoury Date: Wed, 1 Jun 2016 12:27:36 -0400 Subject: [PATCH] fix: deprecated-message not showing for all hooks (#4714) * fix deprecated hooks params warning + var-cleanup * fix deprecated message --- src/plugins/hooks.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/plugins/hooks.js b/src/plugins/hooks.js index 35eed900c3..005255582f 100644 --- a/src/plugins/hooks.js +++ b/src/plugins/hooks.js @@ -57,14 +57,16 @@ module.exports = function(Plugins) { ); } 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]; + var parts = data.hook.split(':'); + if (parts.length > 2) { + 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 `http-request` or the `socket-request` 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\n'); + delete Plugins.deprecatedHooksParams[hook]; } } @@ -196,4 +198,4 @@ module.exports = function(Plugins) { Plugins.hasListeners = function(hook) { return !!(Plugins.loadedHooks[hook] && Plugins.loadedHooks[hook].length > 0); }; -}; \ No newline at end of file +};