Bugzilla – Attachment 105693 Details for
Bug 24031
Add plugin hook after_hold_create
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24031: Add plugin hook after_hold_create
Bug-24031-Add-plugin-hook-afterholdcreate.patch (text/plain), 4.18 KB, created by
Kyle M Hall (khall)
on 2020-06-10 13:54:21 UTC
(
hide
)
Description:
Bug 24031: Add plugin hook after_hold_create
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2020-06-10 13:54:21 UTC
Size:
4.18 KB
patch
obsolete
>From 24042011e8b5095e29cf773501e4babbd0f250cf Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 13 Nov 2019 11:11:54 +0100 >Subject: [PATCH] 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> >--- > C4/Reserves.pm | 3 ++ > Koha/Plugins.pm | 47 +++++++++++++++++++++++++++ > t/db_dependent/Koha/Plugins/Plugins.t | 29 ++++++++++++++++- > 3 files changed, 78 insertions(+), 1 deletion(-) > >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index d328773b01..6e2eb69e1b 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -45,6 +45,7 @@ use Koha::Items; > use Koha::Libraries; > use Koha::Old::Hold; > use Koha::Patrons; >+use Koha::Plugins; > > use Carp; > use Data::Dumper; >@@ -296,6 +297,8 @@ sub AddReserve { > } > } > >+ Koha::Plugins->call('after_hold_create', $hold); >+ > return $reserve_id; > } > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index 9dc42c5155..4e7926b359 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -52,6 +52,29 @@ sub new { > return bless( $args, $class ); > } > >+=head2 call >+ >+Calls a plugin method for all enabled plugins >+ >+ @responses = Koha::Plugins->call($method, @args) >+ >+=cut >+ >+sub call { >+ my ($class, $method, @args) = @_; >+ >+ 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; >+ } >+} >+ > =head2 GetPlugins > > This will return a list of all available plugins, optionally limited by >@@ -161,6 +184,30 @@ sub InstallPlugins { > 1; > __END__ > >+=head1 AVAILABLE HOOKS >+ >+=head2 after_hold_create >+ >+=head3 Parameters >+ >+=over >+ >+=item * C<$hold> - A Koha::Hold object that has just been inserted in database >+ >+=back >+ >+=head3 Return value >+ >+None >+ >+=head3 Example >+ >+ sub after_hold_create { >+ my ($self, $hold) = @_; >+ >+ warn "New hold for borrower " . $hold->borrower->borrowernumber; >+ } >+ > =head1 AUTHOR > > Kyle M Hall <kyle.m.hall@gmail.com> >diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t >index 178c5447f0..ed19ecf204 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -25,7 +25,7 @@ use File::Temp qw( tempdir tempfile ); > use FindBin qw($Bin); > use Module::Load::Conditional qw(can_load); > use Test::MockModule; >-use Test::More tests => 51; >+use Test::More tests => 52; > > use C4::Context; > use Koha::Database; >@@ -46,6 +46,33 @@ BEGIN { > > my $schema = Koha::Database->new->schema; > >+subtest 'call() tests' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ # Temporarily remove any installed plugins data >+ Koha::Plugins::Methods->delete; >+ >+ my $plugins = Koha::Plugins->new({ enable_plugins => 1 }); >+ my @plugins = $plugins->InstallPlugins; >+ foreach my $plugin (@plugins) { >+ $plugin->enable(); >+ } >+ >+ my @responses = Koha::Plugins->call('check_password', { password => 'foo' }); >+ >+ my $expected = [ { error => 1, msg => 'PIN should be four digits' } ]; >+ is_deeply(\@responses, $expected, 'call() should return all responses from plugins'); >+ >+ # Make sure parameters are correctly passed to the plugin method >+ my @responses = Koha::Plugins->call('check_password', { password => '1234' }); >+ >+ my $expected = [ { error => 0 } ]; >+ is_deeply(\@responses, $expected, 'call() should return all responses from plugins'); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'GetPlugins() tests' => sub { > > plan tests => 2; >-- >2.24.1 (Apple Git-126)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24031
:
95358
|
95657
|
95658
|
98788
|
98789
|
105256
|
105257
|
105693
|
105694
|
105695
|
105696
|
105697
|
107042
|
107365