[OPS] How to trigger an action in publication's relations changing

Greetings

I’m developing a plugin for OPS that needs to be executed whenever a publication is published. When this occurs, the plugin collects the publication’s data and generates a cover sheet for the galley.

However, the publication’s relations can be changed after the publication, so it is necessary to update the cover sheet. Therefore, my plugin needs to catch this changing in order to perform its work.

How can I set this? (in a way similar to how a hook works)

Hi @BonjourJhon,

Have a look at the hooks that are listed in lib/pkp/classes/services/PKPPublicationService.inc.php, e.g.:

HookRegistry::call('Publication::edit', [$newPublication, $publication, $params, $request]);

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher

Unfortunately, none of these hooks were useful to my task. The method used by the relation changing is the relate method in classes/services/PublicationService.inc.php.

However, it doesn’t have any hook that I can use to catch this method. I think it would be a good idea to add a hook in this, since it’s a important change.

Let me know what you think about it.

Hi @BonjourJhon,

Ah, this goes through PublicationDAO rather than a QueryBuilder. (We currently have two active means of making database queries – an old one using ADODB and DAO classes, and a new one using PDO and QueryBuilder classes. We are gradually moving over to the new style; this is an example of the old style.)

The DAOs do offer hooks – they’re assembled from low-budget PHP introspection in the DAO class. See e.g. the update function there:

if (HookRegistry::call(strtolower_codesafe($trace[1]['class'] . '::_' . $trace[1]['function']), array(&$sql, &$params, &$value))) {
   return $value;
}

In your case, the hook you’re watching for will be schemadao::_updateobject (SchemaDAO is a superclass of PublicationDAO). However, a hook with this name will be called for any subclass of SchemaDAO, so you’ll have to avoid intervening in cases where another use case is involved.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher

Indeed, there’s a call for the updateObject method in SchemaDAO.inc.php that calls the update method in DAO.inc.php. However, the relationStatus is one of the publication settings, so it is updated by the replace method in DAO.inc.php (you can see the call in this line)

However, there isn’t a hook in the replace method, so I can’t capture this db change.

Thanks @BonjourJhon. I’ve filed an issue to modify how the PublicationService::relate() method works so that the change is passed through the PublicationService::edit hook.

If you have the time, would you be able to provide a PR to make the change described in that issue?