OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



DAO::update hook

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

DAO::update hook

Postby Horscht » Mon Sep 17, 2012 3:46 pm

According to the Tech Manual Hook List any DAO function calling DAO::update will trigger a hook called "[Anything]DAO::​[Any function calling DAO::​update]".

ArticleDAO::updateArticle(&$article) calls DAO::update but no hook called ArticleDAO::updateArticle is triggered as I expected.
I tried my code with other randomly chosen hooks and was able to get calls to my callback function, so how do I get it to work with DAO::update?
Horscht
 
Posts: 5
Joined: Mon Sep 17, 2012 3:24 pm

Re: DAO::update hook

Postby Horscht » Tue Sep 18, 2012 3:23 pm

I found the comment in the source that pointed out the hook is called articledao::_updatearticle( why lower case? why the underscore?).
The underscore makes me curious. Am I not supposed to use this hook? I can register it for my plugin, but when it should be triggered it gets unregistered and my callback function is never called.
Weird stuff... what's going on here?
Horscht
 
Posts: 5
Joined: Mon Sep 17, 2012 3:24 pm

Re: DAO::update hook

Postby asmecher » Tue Sep 18, 2012 4:14 pm

Hi Horscht,

The tech reference is unfortunately a little out of date. I'd be happy to help you out here.

The hook names for implicitly-named hooks (like the one you're looking for) are all dropped to lower case because different versions of PHP have different case sensitivities (PHP4 is lower case, IIRC, and PHP5 is not). To make them all behave the same way WRT hook names we convert them to lower case.

The "_" is there because we wanted to disambiguate between implicitly-named hooks (ones where the name is generated by looking at the debug_backtrace, such as the one you're looking for) and explicitly-named ones (where we've named the hooks ourselves), to avoid clashes.

Could you describe what you're using the hook to do? What category is your plugin loading in?

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 7710
Joined: Wed Aug 10, 2005 12:56 pm

Re: DAO::update hook

Postby Horscht » Tue Sep 18, 2012 11:30 pm

RIght now the plugin extends GenericPlugin and the hook is supposed to be used to keep a repository up to date. Basically it takes the article and supplementary files and stuffs everything into a .tar.gz.
Horscht
 
Posts: 5
Joined: Mon Sep 17, 2012 3:24 pm

Re: DAO::update hook

Postby asmecher » Wed Sep 19, 2012 7:58 am

Hi Horscht,

It sounds like you're on the right track. When you say that the hook gets unregistered, do you mean that it's just never called when you expect it to be? I tend to debug by dropping "echo" or "die" statements in -- there are two places to start with this. One is in your plugin registration function, where you register for the hook, to make sure it's getting registered before the article update is called. If that looks OK, the next place is perhaps in DAO.inc.php where you expect the hook to be called -- it sounds like you've already tried dumping the hook name there. A third is in the HookRegistry::call function to list out hooks when they're called. If this doesn't make sense, or you've already tried this, let me know and I'll walk you through more.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 7710
Joined: Wed Aug 10, 2005 12:56 pm

Re: DAO::update hook

Postby Horscht » Wed Sep 19, 2012 10:44 am

Well registering the Plugin works. Right after I enable it in the journals plugin menu the hook is listed in Hookregistry::getHooks().

Then I try to trigger the hook but when ArticleDAO::updateArticle() is called my hook isn't listed anymore in HookRegistry::getHooks().

I checked for HookRegistry::clear() and HookRegistry::setHooks() calls between the registering of my plugin and the call to updateArticle() and there are none.
What other functions modify the list of registered hooks?
Horscht
 
Posts: 5
Joined: Mon Sep 17, 2012 3:24 pm

Re: DAO::update hook

Postby asmecher » Wed Sep 19, 2012 10:53 am

Hi Horscht,

I'll bet the plugin isn't installed in the database. Is there an entry for it in the "versions" table?

If not, you should be able to get it added by running the upgrade script (php tools/upgrade.php upgrade). Please back up your database before doing this, just in case some prior problem left it in an uncertain state. Alternately, use another plugin's entry as an example.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 7710
Joined: Wed Aug 10, 2005 12:56 pm

Re: DAO::update hook

Postby Horscht » Wed Sep 19, 2012 11:27 am

Hi.

Wow, that did the trick.
Thanks for your help. I really appreciate it.
Horscht
 
Posts: 5
Joined: Mon Sep 17, 2012 3:24 pm

Re: DAO::update hook

Postby asmecher » Wed Sep 19, 2012 11:30 am

Hi Horscht,

No problem, and good luck. If you think the plugin might be broadly useful, please consider posting it to the plugin gallery. (Also, since you mentioned keeping a repository up to date -- have you seen the SWORD plugin?)

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 7710
Joined: Wed Aug 10, 2005 12:56 pm


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 2 guests