Bug 24031

Summary: Add plugin hook after_hold_create
Product: Koha Reporter: Julian Maurice <julian.maurice>
Component: Plugin architectureAssignee: Julian Maurice <julian.maurice>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: jonathan.druart, katrin.fischer, kyle, lucas, m.de.rooy
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
20.11.00
Bug Depends on:    
Bug Blocks: 25712, 26063    
Attachments: Bug 24031: Add plugin hook after_hold_create
Bug 24031: Add plugin hook after_hold_create
Bug 24031: Fix warnings
Bug 24031: Add plugin hook after_hold_create
Bug 24031: Fix warnings
Bug 24031: Remove check for syspref UseKohaPlugins
Bug 24031: Add safety checks in Koha::Plugins::call
Bug 24031: Add plugin hook after_hold_create
Bug 24031: Add plugin hook after_hold_create
Bug 24031: Fix warnings
Bug 24031: Remove check for syspref UseKohaPlugins
Bug 24031: Add safety checks in Koha::Plugins::call
Bug 24031: Add hook to test plugin with unit test
Bug 24031: (QA follow-up) Add tests for the AddReserve intervention

Description Julian Maurice 2019-11-13 10:10:14 UTC
This hook will be called after a hold has been placed.

The need behind that is to create a plugin that will send a mail to the patron that has borrowed the reserved item, saying something like "Someone has requested this item, please return it as soon as you can"
Comment 1 Julian Maurice 2019-11-13 10:15:12 UTC
Created attachment 95358 [details] [review]
Bug 24031: Add plugin hook after_hold_create

It is called after a hold has been placed

Test plan:
1. Write a plugin that implements only after_hold_create (see
   `perldoc Koha::Plugins` for implementation details). Install it and
   enable it
2. Place a hold and verify that your plugin method has been called with
   the right parameters
Comment 2 Kyle M Hall 2019-11-21 13:10:35 UTC
Created attachment 95657 [details] [review]
Bug 24031: Add plugin hook after_hold_create

It is called after a hold has been placed

Test plan:
1. Write a plugin that implements only after_hold_create (see
   `perldoc Koha::Plugins` for implementation details). Install it and
   enable it
2. Place a hold and verify that your plugin method has been called with
   the right parameters

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 3 Kyle M Hall 2019-11-21 13:10:45 UTC
Created attachment 95658 [details] [review]
Bug 24031: Fix warnings

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 4 Katrin Fischer 2019-11-24 14:48:57 UTC
Please remember to add the new hook to the wiki once pushed:
https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks
Comment 5 paxed 2020-02-13 06:37:54 UTC
Created attachment 98788 [details] [review]
Bug 24031: Add plugin hook after_hold_create

It is called after a hold has been placed

Test plan:
1. Write a plugin that implements only after_hold_create (see
   `perldoc Koha::Plugins` for implementation details). Install it and
   enable it
2. Place a hold and verify that your plugin method has been called with
   the right parameters

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Pasi Kallinen <pasi.kallinen@koha-suomi.fi>
Comment 6 paxed 2020-02-13 06:37:57 UTC
Created attachment 98789 [details] [review]
Bug 24031: Fix warnings

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Pasi Kallinen <pasi.kallinen@koha-suomi.fi>
Comment 7 Marcel de Rooy 2020-03-06 11:24:20 UTC
if (C4::Context->preference('UseKohaPlugins') && C4::Context->config('enable_plugins')) {
+        my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({ method => $method });
+        my @responses;
+        foreach my $plugin (@plugins) {
+            my $response = $plugin->$method(@args);
+            push @responses, $response;
+        }
+
+        return @responses;
+    }

No error checking?
What if one of the plugins fails, should you continue? Should you use eval?
Should $method be checked somehow before calling it rightaway?
Comment 8 Marcel de Rooy 2020-05-01 06:20:47 UTC
No reply to earlier questions. No update for bug 20415.
Changing status.
Comment 9 Julian Maurice 2020-05-22 10:33:34 UTC
Created attachment 105256 [details] [review]
Bug 24031: Remove check for syspref UseKohaPlugins

UseKohaPlugins has been removed by bug 20415
Comment 10 Julian Maurice 2020-05-22 10:33:38 UTC
Created attachment 105257 [details] [review]
Bug 24031: Add safety checks in Koha::Plugins::call

- Check that the plugin has the method before calling it
- Call the method in an eval block to prevent fatal errors
Comment 11 Kyle M Hall 2020-06-10 13:54:21 UTC
Created attachment 105693 [details] [review]
Bug 24031: Add plugin hook after_hold_create

It is called after a hold has been placed

Test plan:
1. Write a plugin that implements only after_hold_create (see
   `perldoc Koha::Plugins` for implementation details). Install it and
   enable it
2. Place a hold and verify that your plugin method has been called with
   the right parameters

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Pasi Kallinen <pasi.kallinen@koha-suomi.fi>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 12 Kyle M Hall 2020-06-10 13:55:28 UTC
Created attachment 105694 [details] [review]
Bug 24031: Add plugin hook after_hold_create

It is called after a hold has been placed

Test plan:
1. Write a plugin that implements only after_hold_create (see
   `perldoc Koha::Plugins` for implementation details). Install it and
   enable it
2. Place a hold and verify that your plugin method has been called with
   the right parameters

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Pasi Kallinen <pasi.kallinen@koha-suomi.fi>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 13 Kyle M Hall 2020-06-10 13:55:37 UTC
Created attachment 105695 [details] [review]
Bug 24031: Fix warnings

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Pasi Kallinen <pasi.kallinen@koha-suomi.fi>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 14 Kyle M Hall 2020-06-10 13:55:40 UTC
Created attachment 105696 [details] [review]
Bug 24031: Remove check for syspref UseKohaPlugins

UseKohaPlugins has been removed by bug 20415

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 15 Kyle M Hall 2020-06-10 13:55:43 UTC
Created attachment 105697 [details] [review]
Bug 24031: Add safety checks in Koha::Plugins::call

- Check that the plugin has the method before calling it
- Call the method in an eval block to prevent fatal errors

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 16 Kyle M Hall 2020-06-11 12:34:29 UTC
Needs hook listed in Koha::Plugin::Test with corresponding unit tests.
Comment 17 Kyle M Hall 2020-07-17 15:33:13 UTC
Created attachment 107042 [details] [review]
Bug 24031: Add hook to test plugin with unit test
Comment 18 Tomás Cohen Arazi 2020-07-24 18:44:44 UTC
Created attachment 107365 [details] [review]
Bug 24031: (QA follow-up) Add tests for the AddReserve intervention

This patch adds tests for AddReserve

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 19 Jonathan Druart 2020-07-29 13:12:51 UTC
Julian, can you have a look at bug 26063 and tell us if it's what you had in mind with Koha::Plugins->call please?
Comment 20 Julian Maurice 2020-07-30 07:26:31 UTC
(In reply to Jonathan Druart from comment #19)
> Julian, can you have a look at bug 26063 and tell us if it's what you had in
> mind with Koha::Plugins->call please?

This is exactly what I had in mind :)
Comment 21 Jonathan Druart 2020-07-30 15:46:37 UTC
Pushed to master for 20.11, thanks to everybody involved!
Comment 22 Lucas Gass 2020-07-31 21:34:49 UTC
enhancement not backported to 20.05.x series