[Bug 40984] New: Synchronise before_ and after_authority_action hook signatures with biblio action hooks
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 Bug ID: 40984 Summary: Synchronise before_ and after_authority_action hook signatures with biblio action hooks Change sponsored?: --- Product: Koha Version: Main Hardware: All OS: All Status: NEW Keywords: Hackfest Severity: minor Priority: P5 - low Component: Plugin architecture Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org CC: fridolin.somers@biblibre.com, kyle@bywatersolutions.com, m.de.rooy@rijksmuseum.nl, pedro.amorim@openfifth.co.uk, tomascohen@gmail.com, wainuiwitikapark@catalyst.net.nz Following the work on bug 36343, which standardized the signatures for before_biblio_action and after_biblio_action hooks to include a payload parameter, a similar inconsistency exists within the authority hooks. To improve the consistency and predictability of the plugin hook system, we should align the authority action hooks with the syntax established for biblios. This bug covers two related issues: Update after_authority_action hook signature: An after_authority_action hook already exists, but its signature is missing the payload parameter. We should update this hook to include the payload, bringing it in line with after_biblio_action. A deprecation period and warning should be introduced for the older signature to ensure backward compatibility for existing plugins. Create before_authority_action hook: There is currently no equivalent before_authority_action hook. We should create this new hook to allow plugins to interact with authority records before an action (like saving) is completed. This new hook should be implemented with a signature that is consistent with before_biblio_action from the outset, including the payload parameter. Completing this work will provide a more coherent and powerful interface for plugins that interact with both bibliographic and authority records. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 187653 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=187653&action=edit Bug 40984: Synchronize before_ and after_authority_action hooks with biblio action hooks This patch updates the authority action plugin hooks to match the signature and behavior of the biblio action hooks: 1. Created before_authority_action hook that is called before authority records are saved, allowing plugins to modify records before they are stored in the database 2. Updated after_authority_action hook to use a payload parameter containing authority, authority_id, and record, matching the pattern used by after_biblio_action hook 3. Maintained backward compatibility by passing both old parameters (authority, authority_id) and new payload parameter, with deprecation warnings logged when plugins implement the hook 4. Updated test plugin to use new payload-based signatures for both hooks 5. Added test coverage for before_authority_action hook Test plan: 1. Run: prove t/db_dependent/Koha/Plugins/authority_hooks.t 2. Run: prove t/db_dependent/Koha/Plugins/ 3. All tests should pass -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|testopia@bugs.koha-communit |m.de.rooy@rijksmuseum.nl |y.org | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |IMPORTANT: The authority release notes| |and authority_id parameters | |of | |after_authority_action_hook | |s plugins have been | |deprecated! Please switch | |to using the payload hash. | |The old parameters will be | |removed in a future version | |of Koha. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the|IMPORTANT: The authority |IMPORTANT: The authority release notes|and authority_id parameters |and authority_id parameters |of |of |after_authority_action_hook |after_authority_action_hook |s plugins have been |s plugins have been |deprecated! Please switch |deprecated! Please switch |to using the payload hash. |to using the payload hash. |The old parameters will be |The old parameters will be |removed in a future version |removed in a future version |of Koha. |of Koha. | | | |Note that this report also | |adds | |before_authority_action_hoo | |ks allowing you modify | |authority records before | |saving. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the|IMPORTANT: The authority |IMPORTANT: The authority release notes|and authority_id parameters |and authority_id parameters |of |of |after_authority_action_hook |after_authority_action_hook |s plugins have been |s plugins have been |deprecated! Please switch |deprecated! Please switch |to using the payload hash. |to using the payload hash. |The old parameters will be |The old parameters will be |removed in a future version |removed in a future version |of Koha. |of Koha. | | |Note that this report also |Note that this report also |adds |adds |before_authority_action_hoo |before_authority_action_hoo |ks allowing you modify |ks allowing you to modify |authority records before |authority records before |saving. |saving. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 --- Comment #2 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- I am not so sure about this: + # Log deprecation warning if any plugin is still using the old signature + my @plugins = Koha::Plugins->get_enabled_plugins( { verbose => 0 } ); + @plugins = grep { $_->can('after_authority_action') } @plugins; + if (@plugins) { + Koha::Logger->get->warn( + "after_authority_action hook: The old signature (with authority and authority_id as direct parameters) " + . "is deprecated and will be removed in a future release. " + . "Please update your plugin to use the 'payload' parameter instead." ); + } -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 --- Comment #3 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Potentially flooding the logs with deprecation warns and not even checking if we use the old or the new syntax? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Failed QA --- Comment #4 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- # Call before hook _before_authority_action_hooks( { action => 'save', authority_id => $authid, record => $record } ); Not sure about the exact place we should add this call. It is a bit in the middle of various changes in AddAuthority now. For MARC21 we did already update fields like leader, 003, 005, 008. But did not yet update 001 and heading. Comparing with the biblio action, we do the before call after record changes in ModBiblioMarc and just before saving to biblio_metadata. Could you explain why we do it here? Shouldnt we better move it after the heading change just before the $authority->update? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 --- Comment #5 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- (In reply to Marcel de Rooy from comment #2)
I am not so sure about this:
+ # Log deprecation warning if any plugin is still using the old signature + my @plugins = Koha::Plugins->get_enabled_plugins( { verbose => 0 } ); + @plugins = grep { $_->can('after_authority_action') } @plugins; + if (@plugins) { + Koha::Logger->get->warn( + "after_authority_action hook: The old signature (with authority and authority_id as direct parameters) " + . "is deprecated and will be removed in a future release. " + . "Please update your plugin to use the 'payload' parameter instead." ); + }
Hmm.. seems I mis-remembered how we added a deprecation to the other bug.. just a DB update. That feels too quiet to me really but you are right, this approach could be noisy -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=40984 --- Comment #6 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- I just stumbled over the need of this patch in 24.11 again. But I need the authtypecode in the delete message. And I am seeing this: + my $authority = $action ne 'delete' ? Koha::Authorities->find($authority_id) : undef; So we still pass only the authid to the plugin. And I need at least the type. But even better would be passing the auth object (that we already have in DelAuthority btw) to _after_authority_action_hooks. We could do similar in AddAuthority which removes the need of looking it up again in _after_authority_action_hooks itself. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org