Bug 24031 - Add plugin hook after_hold_create
Summary: Add plugin hook after_hold_create
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Julian Maurice
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 25712 26063
  Show dependency treegraph
 
Reported: 2019-11-13 10:10 UTC by Julian Maurice
Modified: 2022-06-06 20:24 UTC (History)
4 users (show)

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


Attachments
Bug 24031: Add plugin hook after_hold_create (3.99 KB, patch)
2019-11-13 10:15 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 24031: Add plugin hook after_hold_create (4.07 KB, patch)
2019-11-21 13:10 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 24031: Fix warnings (1.16 KB, patch)
2019-11-21 13:10 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 24031: Add plugin hook after_hold_create (4.12 KB, patch)
2020-02-13 06:37 UTC, paxed
Details | Diff | Splinter Review
Bug 24031: Fix warnings (1.20 KB, patch)
2020-02-13 06:37 UTC, paxed
Details | Diff | Splinter Review
Bug 24031: Remove check for syspref UseKohaPlugins (910 bytes, patch)
2020-05-22 10:33 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 24031: Add safety checks in Koha::Plugins::call (1.16 KB, patch)
2020-05-22 10:33 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 24031: Add plugin hook after_hold_create (4.18 KB, patch)
2020-06-10 13:54 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 24031: Add plugin hook after_hold_create (4.18 KB, patch)
2020-06-10 13:55 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 24031: Fix warnings (1.27 KB, patch)
2020-06-10 13:55 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 24031: Remove check for syspref UseKohaPlugins (982 bytes, patch)
2020-06-10 13:55 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 24031: Add safety checks in Koha::Plugins::call (1.23 KB, patch)
2020-06-10 13:55 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 24031: Add hook to test plugin with unit test (1.99 KB, patch)
2020-07-17 15:33 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 24031: (QA follow-up) Add tests for the AddReserve intervention (3.74 KB, patch)
2020-07-24 18:44 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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 (khall) 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 (khall) 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 (khall) 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 (khall) 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 (khall) 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 (khall) 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 (khall) 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 (khall) 2020-06-11 12:34:29 UTC
Needs hook listed in Koha::Plugin::Test with corresponding unit tests.
Comment 17 Kyle M Hall (khall) 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 (tcohen) 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 (lukeg) 2020-07-31 21:34:49 UTC
enhancement not backported to 20.05.x series