Node.js based forum software built for the modern web
fix: removed methods
Barış Soner Uşaklı647d3ba81072
diff --git a/src/plugins/hooks.js b/src/plugins/hooks.jsindex 82d4993d13..f88a081e8e 100644--- a/src/plugins/hooks.js+++ b/src/plugins/hooks.js@@ -5,8 +5,7 @@ const async = require('async');const utils = require('../utils');const plugins = require('.');-const Hooks = {};-module.exports = Hooks;+const Hooks = module.exports;Hooks.deprecatedHooks = {'filter:router.page': 'response:router.page', // 👋 @ 2.0.0diff --git a/src/routes/write/index.js b/src/routes/write/index.jsindex b2689cc586..3c80fdf641 100644--- a/src/routes/write/index.js+++ b/src/routes/write/index.js@@ -12,7 +12,7 @@ const Write = module.exports;Write.reload = async (params) => {const router = params.router;let apiSettings = await meta.settings.get('core.api');- plugins.registerHook('core', {+ plugins.hooks.register('core', {hook: 'action:settings.set',method: async (data) => {if (data.plugin === 'core.api') {diff --git a/test/api.js b/test/api.jsindex 7401b152ea..022e31a112 100644--- a/test/api.js+++ b/test/api.js@@ -85,8 +85,8 @@ describe('API', async () => {}after(async function () {- plugins.unregisterHook('core', 'filter:search.query', dummySearchHook);- plugins.unregisterHook('emailer-test', 'filter:email.send');+ plugins.hooks.unregister('core', 'filter:search.query', dummySearchHook);+ plugins.hooks.unregister('emailer-test', 'filter:email.send');});async function setupData() {@@ -163,12 +163,12 @@ describe('API', async () => {await wait(5000);// Attach a search hook so /api/search is enabled- plugins.registerHook('core', {+ plugins.hooks.register('core', {hook: 'filter:search.query',method: dummySearchHook,});// Attach an emailer hook so related requests do not error- plugins.registerHook('emailer-test', {+ plugins.hooks.register('emailer-test', {hook: 'filter:email.send',method: dummyEmailerHook,});diff --git a/test/categories.js b/test/categories.jsindex f717052b5b..de01068137 100644--- a/test/categories.js+++ b/test/categories.js@@ -895,7 +895,7 @@ describe('Categories', function () {callback(null, data);}- plugins.registerHook('my-test-plugin', {+ plugins.hooks.register('my-test-plugin', {hook: 'filter:categories.getTopicIds',method: method,});@@ -907,7 +907,7 @@ describe('Categories', function () {}, function (err, tids) {assert.ifError(err);assert.deepEqual(tids, [1, 2, 3]);- plugins.unregisterHook('my-test-plugin', 'filter:categories.getTopicIds', method);+ plugins.hooks.unregister('my-test-plugin', 'filter:categories.getTopicIds', method);done();});});diff --git a/test/controllers-admin.js b/test/controllers-admin.jsindex 3befc0367c..3a37bbea51 100644--- a/test/controllers-admin.js+++ b/test/controllers-admin.js@@ -649,7 +649,7 @@ describe('Admin Controllers', function () {config.script = '</script>';callback(null, config);}- plugins.registerHook('somePlugin', { hook: 'filter:config.get', method: onConfigGet });+ plugins.hooks.register('somePlugin', { hook: 'filter:config.get', method: onConfigGet });request(nconf.get('url') + '/admin', { jar: jar }, function (err, res, body) {assert.ifError(err);assert.equal(res.statusCode, 200);@@ -664,7 +664,7 @@ describe('Admin Controllers', function () {assert(body.includes('"someValue":"\\\\"foo\\\\""'));assert(body.includes('"otherValue":"\\\'123\\\'"'));assert(body.includes('"script":"<\\/script>"'));- plugins.unregisterHook('somePlugin', 'filter:config.get', onConfigGet);+ plugins.hooks.unregister('somePlugin', 'filter:config.get', onConfigGet);done();});});diff --git a/test/controllers.js b/test/controllers.jsindex 382e1ccd62..1ea4e8370d 100644--- a/test/controllers.js+++ b/test/controllers.js@@ -104,7 +104,7 @@ describe('Controllers', function () {var tplPath = path.join(nconf.get('views_dir'), name);before(async () => {- plugins.registerHook('myTestPlugin', {+ plugins.hooks.register('myTestPlugin', {hook: 'action:homepage.get:mycustompage',method: hookMethod,});@@ -255,7 +255,7 @@ describe('Controllers', function () {});after(function () {- plugins.unregisterHook('myTestPlugin', 'action:homepage.get:custom', hookMethod);+ plugins.hooks.unregister('myTestPlugin', 'action:homepage.get:custom', hookMethod);fs.unlinkSync(tplPath);fs.unlinkSync(tplPath.replace(/\.tpl$/, '.js'));});@@ -303,7 +303,7 @@ describe('Controllers', function () {next(null, data);}- plugins.registerHook('myTestPlugin', {+ plugins.hooks.register('myTestPlugin', {hook: 'filter:register.interstitial',method: hookMethod,});@@ -343,7 +343,7 @@ describe('Controllers', function () {assert(body.sections);assert(body.errors);assert(body.title);- plugins.unregisterHook('myTestPlugin', 'filter:register.interstitial', hookMethod);+ plugins.hooks.unregister('myTestPlugin', 'filter:register.interstitial', hookMethod);done();});});@@ -2244,7 +2244,7 @@ describe('Controllers', function () {callback(null, hookData);}- plugins.registerHook('myTestPlugin', {+ plugins.hooks.register('myTestPlugin', {hook: 'filter:composer.build',method: hookMethod,});@@ -2256,7 +2256,7 @@ describe('Controllers', function () {assert.strictEqual(body.template.name, '');assert.strictEqual(body.url, nconf.get('relative_path') + '/compose');- plugins.unregisterHook('myTestPlugin', 'filter:composer.build', hookMethod);+ plugins.hooks.unregister('myTestPlugin', 'filter:composer.build', hookMethod);done();});});@@ -2266,7 +2266,7 @@ describe('Controllers', function () {hookData.next();}- plugins.registerHook('myTestPlugin', {+ plugins.hooks.register('myTestPlugin', {hook: 'filter:composer.build',method: hookMethod,});@@ -2275,7 +2275,7 @@ describe('Controllers', function () {assert.ifError(err);assert.equal(res.statusCode, 404);- plugins.unregisterHook('myTestPlugin', 'filter:composer.build', hookMethod);+ plugins.hooks.unregister('myTestPlugin', 'filter:composer.build', hookMethod);done();});});diff --git a/test/emailer.js b/test/emailer.jsindex 86f96997c5..ed446a1029 100644--- a/test/emailer.js+++ b/test/emailer.js@@ -48,7 +48,7 @@ describe('emailer', function () {it('plugin hook should work', function (done) {var error = new Error();- Plugins.registerHook('emailer-test', {+ Plugins.hooks.register('emailer-test', {hook: 'filter:email.send',method: function (data, next) {assert(data);@@ -62,7 +62,7 @@ describe('emailer', function () {Emailer.sendToEmail(template, email, language, params, function (err) {assert.equal(err, error);- Plugins.unregisterHook('emailer-test', 'filter:email.send');+ Plugins.hooks.unregister('emailer-test', 'filter:email.send');done();});});diff --git a/test/plugins.js b/test/plugins.jsindex a029d06c06..6af4dc774f 100644--- a/test/plugins.js+++ b/test/plugins.js@@ -23,7 +23,7 @@ describe('Plugins', function () {});it('should return true if hook has listeners', function (done) {- assert(plugins.hasListeners('filter:parse.post'));+ assert(plugins.hooks.hasListeners('filter:parse.post'));done();});@@ -37,10 +37,10 @@ describe('Plugins', function () {callback(null, data);}- plugins.registerHook('test-plugin', { hook: 'filter:test.hook', method: filterMethod1 });- plugins.registerHook('test-plugin', { hook: 'filter:test.hook', method: filterMethod2 });+ plugins.hooks.register('test-plugin', { hook: 'filter:test.hook', method: filterMethod1 });+ plugins.hooks.register('test-plugin', { hook: 'filter:test.hook', method: filterMethod2 });- plugins.fireHook('filter:test.hook', { foo: 1 }, function (err, data) {+ plugins.hooks.fire('filter:test.hook', { foo: 1 }, function (err, data) {assert.ifError(err);assert.equal(data.foo, 7);done();@@ -59,10 +59,10 @@ describe('Plugins', function () {});}- plugins.registerHook('test-plugin', { hook: 'filter:test.hook2', method: method1 });- plugins.registerHook('test-plugin', { hook: 'filter:test.hook2', method: method2 });+ plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method1 });+ plugins.hooks.register('test-plugin', { hook: 'filter:test.hook2', method: method2 });- plugins.fireHook('filter:test.hook2', { foo: 1 }, function (err, data) {+ plugins.hooks.fire('filter:test.hook2', { foo: 1 }, function (err, data) {assert.ifError(err);assert.equal(data.foo, 7);done();@@ -76,8 +76,8 @@ describe('Plugins', function () {reject(new Error('nope'));});}- plugins.registerHook('test-plugin', { hook: 'filter:test.hook3', method: method });- plugins.fireHook('filter:test.hook3', { foo: 1 }, function (err) {+ plugins.hooks.register('test-plugin', { hook: 'filter:test.hook3', method: method });+ plugins.hooks.fire('filter:test.hook3', { foo: 1 }, function (err) {assert(err);done();});@@ -89,8 +89,8 @@ describe('Plugins', function () {done();}- plugins.registerHook('test-plugin', { hook: 'action:test.hook', method: actionMethod });- plugins.fireHook('action:test.hook', { bar: 'test' });+ plugins.hooks.register('test-plugin', { hook: 'action:test.hook', method: actionMethod });+ plugins.hooks.fire('action:test.hook', { bar: 'test' });});it('should register and fire a static hook', function (done) {@@ -99,8 +99,8 @@ describe('Plugins', function () {callback();}- plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: actionMethod });- plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {+ plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: actionMethod });+ plugins.hooks.fire('static:test.hook', { bar: 'test' }, function (err) {assert.ifError(err);done();});@@ -113,8 +113,8 @@ describe('Plugins', function () {resolve();});}- plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: method });- plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {+ plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method });+ plugins.hooks.fire('static:test.hook', { bar: 'test' }, function (err) {assert.ifError(err);done();});@@ -127,10 +127,10 @@ describe('Plugins', function () {reject(new Error('just because'));});}- plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: method });- plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {+ plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method });+ plugins.hooks.fire('static:test.hook', { bar: 'test' }, function (err) {assert.strictEqual(err.message, 'just because');- plugins.unregisterHook('test-plugin', 'static:test.hook', method);+ plugins.hooks.unregister('test-plugin', 'static:test.hook', method);done();});});@@ -142,10 +142,10 @@ describe('Plugins', function () {setTimeout(resolve, 6000);});}- plugins.registerHook('test-plugin', { hook: 'static:test.hook', method: method });- plugins.fireHook('static:test.hook', { bar: 'test' }, function (err) {+ plugins.hooks.register('test-plugin', { hook: 'static:test.hook', method: method });+ plugins.hooks.fire('static:test.hook', { bar: 'test' }, function (err) {assert.ifError(err);- plugins.unregisterHook('test-plugin', 'static:test.hook', method);+ plugins.hooks.unregister('test-plugin', 'static:test.hook', method);done();});});diff --git a/test/socket.io.js b/test/socket.io.jsindex 8a4e7fa432..8af832cb83 100644--- a/test/socket.io.js+++ b/test/socket.io.js@@ -247,13 +247,13 @@ describe('socket.io', function () {}before(function () {// Attach an emailer hook so related requests do not error- plugins.registerHook('emailer-test', {+ plugins.hooks.register('emailer-test', {hook: 'filter:email.send',method: dummyEmailerHook,});});after(function () {- plugins.unregisterHook('emailer-test', 'filter:email.send');+ plugins.hooks.unregister('emailer-test', 'filter:email.send');});it('should validate emails', function (done) {diff --git a/test/topics.js b/test/topics.jsindex 855612b1e1..3cbca7be5d 100644--- a/test/topics.js+++ b/test/topics.js@@ -2165,7 +2165,7 @@ describe('Topic\'s', function () {it('should return results', function (done) {var plugins = require('../src/plugins');- plugins.registerHook('myTestPlugin', {+ plugins.hooks.register('myTestPlugin', {hook: 'filter:topic.search',method: function (data, callback) {callback(null, [1, 2, 3]);diff --git a/test/user.js b/test/user.jsindex 22fd744f66..303afdcb20 100644--- a/test/user.js+++ b/test/user.js@@ -32,7 +32,7 @@ describe('User', function () {}before(function (done) {// Attach an emailer hook so related requests do not error- plugins.registerHook('emailer-test', {+ plugins.hooks.register('emailer-test', {hook: 'filter:email.send',method: dummyEmailerHook,});@@ -51,7 +51,7 @@ describe('User', function () {});});after(function () {- plugins.unregisterHook('emailer-test', 'filter:email.send');+ plugins.hooks.unregister('emailer-test', 'filter:email.send');});beforeEach(function () {@@ -743,12 +743,12 @@ describe('User', function () {callback(null, data);}- plugins.registerHook('test-plugin', { hook: 'filter:user.whitelistFields', method: filterMethod });+ plugins.hooks.register('test-plugin', { hook: 'filter:user.whitelistFields', method: filterMethod });User.getUserData(testUid, function (err, userData) {assert.ifError(err);assert(!userData.hasOwnProperty('fb_token'));assert.equal(userData.another_secret, 'abcde');- plugins.unregisterHook('test-plugin', 'filter:user.whitelistFields', filterMethod);+ plugins.hooks.unregister('test-plugin', 'filter:user.whitelistFields', filterMethod);done();});});