Summary: | Add hooks to notify plugins of biblio and item changes | ||
---|---|---|---|
Product: | Koha | Reporter: | Tomás Cohen Arazi (tcohen) <tomascohen> |
Component: | Plugin architecture | Assignee: | Tomás Cohen Arazi (tcohen) <tomascohen> |
Status: | CLOSED FIXED | QA Contact: | Josef Moravec <josef.moravec> |
Severity: | new feature | ||
Priority: | P5 - low | CC: | dcook, fridolin.somers, jonathan.druart, josef.moravec, kyle, martin.renvoize, nick |
Version: | Main | ||
Hardware: | All | ||
OS: | All | ||
See Also: |
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29273 https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36542 |
||
Change sponsored?: | --- | Patch complexity: | --- |
Documentation contact: | Documentation submission: | ||
Text to go in the release notes: |
This new feature allows plugin authors to implement `after_biblio_action` and `after_item_action` methods which may be used to take various actions upon biblio and item creations, modifications and deletions.
**Warning**: Care should be taken when installing any plugins and only plugins you trust should be used.
|
Version(s) released in: |
19.11.00
|
Circulation function: | |||
Bug Depends on: | |||
Bug Blocks: | 23395, 34786, 26470, 29274 | ||
Attachments: |
Bug 22709: Unit tests
Bug 22709: Add after biblio/item action hooks Bug 22709: (follow-up) Mock enable_plugins config entry Bug 22709: Unit tests Bug 22709: Add after biblio/item action hooks Bug 22709: (follow-up) Mock enable_plugins config entry Bug 22709: (follow-up) Move new test file into a Plugins subdirectory Bug 22709: Unit tests Bug 22709: Add after biblio/item action hooks Bug 22709: (follow-up) Mock enable_plugins config entry Bug 22709: (follow-up) Move new test file into a Plugins subdirectory |
Description
Tomás Cohen Arazi (tcohen)
2019-04-15 16:17:25 UTC
This could be easily implemented by reusing the zebraqueue table, but adding new targets based on configured notifiable plugins. Hmmm Created attachment 90950 [details] [review] Bug 22709: Unit tests This patch introduces tests for new plugin hooks added to C4::Biblio::{Add|Mod|Del}Biblio and C4::Items::{Add|Mod|Del}Item. They are tested together as for creating an item you need to first create a biblio and tests looks basically the same. The testing strategy is - Make sure the plugin is passed the right params - Throw an exception at plugin-level, to be trapped by the C4::Biblio and C4::Items lib, and converted into a warning. So we test for the warning. - Also, the fact that C4::Biblio and C4::Items warns, means the exception was cought, and then Koha won't break on faulty plugins or fatal errors from plugins. Created attachment 90951 [details] [review] Bug 22709: Add after biblio/item action hooks This patch introduces after-action hooks for - C4::Biblio::{Add|Mod|Del}Biblio - C4::Items::{Add|Mod|Del}Biblio After the action has taken place, a call to a helper method is done, which loops through all plugins implementing the hooks, and calls the plugin method. The related object is passed, along with an 'action' string specifying the action that took place, and the object id (which is specially important for the 'Del' case). To test: - Apply this patchset - Run: $ kshell k$ prove t/db_dependent/Biblio_and_Items_plugin_hooks.t => SUCCESS: Tests pass! - Sign off :-D Unit tests are failing. Created attachment 91186 [details] [review] Bug 22709: (follow-up) Mock enable_plugins config entry Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> (In reply to Kyle M Hall from comment #4) > Unit tests are failing. Thanks for testing! I've added a follow-up to fix the issue. I didn't notice I forgot to mock the enable_plugins config entry. Created attachment 91223 [details] [review] Bug 22709: Unit tests This patch introduces tests for new plugin hooks added to C4::Biblio::{Add|Mod|Del}Biblio and C4::Items::{Add|Mod|Del}Item. They are tested together as for creating an item you need to first create a biblio and tests looks basically the same. The testing strategy is - Make sure the plugin is passed the right params - Throw an exception at plugin-level, to be trapped by the C4::Biblio and C4::Items lib, and converted into a warning. So we test for the warning. - Also, the fact that C4::Biblio and C4::Items warns, means the exception was cought, and then Koha won't break on faulty plugins or fatal errors from plugins. Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 91224 [details] [review] Bug 22709: Add after biblio/item action hooks This patch introduces after-action hooks for - C4::Biblio::{Add|Mod|Del}Biblio - C4::Items::{Add|Mod|Del}Biblio After the action has taken place, a call to a helper method is done, which loops through all plugins implementing the hooks, and calls the plugin method. The related object is passed, along with an 'action' string specifying the action that took place, and the object id (which is specially important for the 'Del' case). To test: - Apply this patchset - Run: $ kshell k$ prove t/db_dependent/Biblio_and_Items_plugin_hooks.t => SUCCESS: Tests pass! - Sign off :-D Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 91225 [details] [review] Bug 22709: (follow-up) Mock enable_plugins config entry Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Created attachment 91226 [details] [review] Bug 22709: (follow-up) Move new test file into a Plugins subdirectory Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> (In reply to Kyle M Hall from comment #10) > Created attachment 91226 [details] [review] [review] > Bug 22709: (follow-up) Move new test file into a Plugins subdirectory > > Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Good idea! Created attachment 91244 [details] [review] Bug 22709: Unit tests This patch introduces tests for new plugin hooks added to C4::Biblio::{Add|Mod|Del}Biblio and C4::Items::{Add|Mod|Del}Item. They are tested together as for creating an item you need to first create a biblio and tests looks basically the same. The testing strategy is - Make sure the plugin is passed the right params - Throw an exception at plugin-level, to be trapped by the C4::Biblio and C4::Items lib, and converted into a warning. So we test for the warning. - Also, the fact that C4::Biblio and C4::Items warns, means the exception was cought, and then Koha won't break on faulty plugins or fatal errors from plugins. Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Created attachment 91245 [details] [review] Bug 22709: Add after biblio/item action hooks This patch introduces after-action hooks for - C4::Biblio::{Add|Mod|Del}Biblio - C4::Items::{Add|Mod|Del}Biblio After the action has taken place, a call to a helper method is done, which loops through all plugins implementing the hooks, and calls the plugin method. The related object is passed, along with an 'action' string specifying the action that took place, and the object id (which is specially important for the 'Del' case). To test: - Apply this patchset - Run: $ kshell k$ prove t/db_dependent/Biblio_and_Items_plugin_hooks.t => SUCCESS: Tests pass! - Sign off :-D Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Created attachment 91246 [details] [review] Bug 22709: (follow-up) Mock enable_plugins config entry Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Created attachment 91247 [details] [review] Bug 22709: (follow-up) Move new test file into a Plugins subdirectory Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Nice work! Pushed to master for 19.11.00 Do we have documentation for this and other new hooks? Should this be added to the kitchen sink plugin? (In reply to Katrin Fischer from comment #17) > Do we have documentation for this and other new hooks? Should this be added > to the kitchen sink plugin? Good point. Will add them to KitchenSink ASAP. Started a wiki page too... content to be added ;) https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks Nice work! Pushed to master for 19.11.00 Nice work! Pushed to master for 19.11.00 Awesome \o/ Nice! A few years ago, I was thinking it would be great to add hooks like this, but never got around to doing it. I could backport to stable but maybe this needs the plugins performance patch. (In reply to Fridolin SOMERS from comment #24) > I could backport to stable but maybe this needs the plugins performance > patch. Indeed. And we noticed a slight performance hit we need to address. (In reply to Tomás Cohen Arazi from comment #25) > (In reply to Fridolin SOMERS from comment #24) > > I could backport to stable but maybe this needs the plugins performance > > patch. > > Indeed. And we noticed a slight performance hit we need to address. Agreed, with the performance patch, the addition time is essentially negligible. |