solved Dependent Listeners

TiG
TiG
@tig
7 years ago
184 posts
I created a module that logically -using an OO metaphor- is a subclass of jrComment. Accordingly I would like the listeners for jrComment to function first before the equivalent listeners in my module (the subclass of jrComment).

My particular concern lies with jrComment_db_search_items_listener. Threaded comments need to be ordered and jrComment_db_search_items_listener embeds the functionality for doing so.

It is of course not appealing for me to replicate the ordering logic (sorting twice) in my db_search_items_listener. I would much rather force my db_search_items_listener to engage after the jrComment_db_search_items_listener.

Thus my question: is there any mechanism for imposing a module dependency on listeners?

------------

( I created my module only to avoid making changes in jrComment. It would be trivial to just add my logic on the tail end of the jrComment listener. )



--
TiG

updated by @tig: 11/29/17 09:06:26AM
brian
@brian
7 years ago
10,148 posts
Each module in Jamroom can be given a "priority" - this determines the load order of the module, and thus determines the order that event listeners are called when multiple modules have registered to listen to a specific event. In this case, if you look in the jrComment/include.php file at the "meta" function that the comment modules priority is set to "250" (which is low). the very lowest priority is 255, so in your custom module meta function just make sure you set your module priority to be 251 - that way your event listener will always run AFTER the comment module listener.

Let me know if that helps.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
TiG
TiG
@tig
7 years ago
184 posts
(2017-08-29T17:37:29+01:00.0.72297300 : 0) ntCommentHierarchy_db_search_items_listener
(2017-08-29T17:37:29+01:00.0.72336300 : 0) jrComment_db_search_items_listener
(2017-08-29T17:37:30+01:00.0.90532900 : 0) ntCommentHierarchy_db_search_items_listener
(2017-08-29T17:37:30+01:00.0.90580800 : 0) jrComment_db_search_items_listener

@brian

The above is an edited cut from fdebug. I simply logged the entry into the functions to see the firing order. Seems no matter what I do with ntCommentHierarchy priority (set at 251 but I did try 249 just to be complete) the ntCommentHierarchy listener always fires before its jrComment counterpart. (I also verified jrComment has priority of 250.)

I have worked out another solution that is not sensitive to order, but for my own future knowledge I would like to exploit priority to emulate method overrides. Can you think of anything obvious that would explain how -ostensibly- a 251 priority listener runs before a 250 priority listener? If not, no worries since I have an alternate approach (albeit less efficient, ... ).

Thanks.


--
TiG
brian
@brian
7 years ago
10,148 posts
Sorry - should have mentioned you need to run an integrity check after making the change - the priority is stored in the module table in the DB, and updates with an integrity check.

Let me know if that helps.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
TiG
TiG
@tig
7 years ago
184 posts
@brian - And with that all is well. The firing order is as desired and my functionality is working per design. Good as it gets, right? :)

Thanks for the tip.


--
TiG

updated by @tig: 08/29/17 10:08:51AM
brian
@brian
7 years ago
10,148 posts
Awesome - glad that it is working now :)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags