Bug 31734 - Hooks for account, recall, indexing and more actions for holds
Summary: Hooks for account, recall, indexing and more actions for holds
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Stefan Berndtsson
QA Contact: Testopia
URL:
Keywords:
Depends on: 31897 31894 31895 31896
Blocks:
  Show dependency treegraph
 
Reported: 2022-10-11 13:13 UTC by Stefan Berndtsson
Modified: 2023-06-11 16:21 UTC (History)
0 users

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 31734: Extend hooks for plugins (16.20 KB, patch)
2022-10-11 13:15 UTC, Stefan Berndtsson
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Berndtsson 2022-10-11 13:13:25 UTC
This patch adds a few more hooks and extensions to an existing hook.

The existing hook "after_hold_action" has been extended with the following actions:
* "transfer" for when a Hold calls "set_transfer()".
* "waiting" for when a Hold calls "set_waiting()".
* "processing" for when a Hold calls "set_processing()".

A new hook "after_account_action" is added with action "add_credit" for when credit is added via for example PAYMENT or WRITEOFF. This is consistent with when UpdateStats is called so that a plugin can be used to log the same kind of data as the normal statistics.

Another new hook "after_recall_action" with action "add_recall" is also added. Also to stay consistent with the UpdateStats usage.

Lastly a hook "before_index_action" with action "update" is added for the Elasticsearch::Indexer function "update_index()" so that the records being indexed can be modified before indexing. This allows for a plugin to add metadata to index or tweak or change it to provide better search results without changing the actual records (something that might be prohibited or discouraged due to centralised cataloging).

Tests are provided in the patch.
Comment 1 Stefan Berndtsson 2022-10-11 13:15:12 UTC
Created attachment 141602 [details] [review]
Bug 31734: Extend hooks for plugins

Hooks added:
after_account_action / add in Koha::Account::add_credit when adding credit for payment or writeoff.
after_hold_action / transfer, waiting and processing in Koha::Hold::set_*
after_recall_action / add in Koha::Recalls::add_recall when adding recall
before_index_action / update in Koha::SearchEngine::Elasticsearch::Indexer::update_index before actually updating the index

Tests added for all new hooks.

How to test:
1) Run tests in t/db_dependent/Koha/Plugins/Account_hooks.t
2) Run tests in t/db_dependent/Koha/Plugins/Elasticsearch_Indexer_hooks.t
3) Run tests in t/db_dependent/Koha/Plugins/Holds_hooks.t
4) Run tests in t/db_dependent/Koha/Plugins/Recall_hooks.t

Sponsored by: Gothenburg University Library
Comment 2 Katrin Fischer 2022-10-16 13:21:33 UTC
Hi Stefan, in general it's recommended to break up work into smaller granular features. They usually go in much faster, the smaller the change is, as a question or problem doesn't cause a hold up so easily.
In this case, I think it would have made sense to have separate bugs for holds, accounts, indexing and recalls.
Comment 3 Stefan Berndtsson 2022-10-20 16:50:24 UTC
I didn't see this as that big of a thing, but ok.

There are now the bugs:

Bug 31894 (Hold)
Bug 31895 (Account)
Bug 31896 (Recall)
Bug 31897 (Index)

I guess this one can be closed then. Should it just be set to resolved, or is there another procedure?
Comment 4 Katrin Fischer 2022-10-28 12:42:05 UTC
Hi Stefan

it looks like the bugs are progressing nicely now :) 

I have linked them to this bug in a way we do for 'omnibus' bugs, that combine several issues about a topic.

Could you please update the wiki page for hooks when these are pushed?
https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks

Thanks!
Comment 5 Katrin Fischer 2022-11-14 23:32:57 UTC
I've updated the wiki with some basic information, but couldn't provide the full descriptions.
Comment 6 Katrin Fischer 2023-06-11 16:21:45 UTC
Only bug 31897 is missing here now!