From 627bb92fba27d3c72239289c6b0c9a0702a3b813 Mon Sep 17 00:00:00 2001 From: Stefan Berndtsson Date: Mon, 17 Oct 2022 16:47:06 +0200 Subject: [PATCH] Bug 31894: Extend after_hold_action hook Hook actions added: after_hold_action adds new actions transfer, waiting and processing How to test: Run tests in t/db_dependent/Koha/Plugins/Holds_hooks.t Sponsored by: Gothenburg University Library --- Koha/Hold.pm | 24 +++++++++++++++++++++++ t/db_dependent/Koha/Plugins/Holds_hooks.t | 20 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index ca261086c7..9738417f75 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -200,6 +200,14 @@ sub set_transfer { $self->found('T'); $self->store(); + Koha::Plugins->call( + 'after_hold_action', + { + action => 'transfer', + payload => { hold => $self->get_from_storage } + } + ); + return $self; } @@ -257,6 +265,14 @@ sub set_waiting { $self->set($values)->store(); + Koha::Plugins->call( + 'after_hold_action', + { + action => 'waiting', + payload => { hold => $self->get_from_storage } + } + ); + return $self; } @@ -345,6 +361,14 @@ sub set_processing { $self->found('P'); $self->store(); + Koha::Plugins->call( + 'after_hold_action', + { + action => 'processing', + payload => { hold => $self->get_from_storage } + } + ); + return $self; } diff --git a/t/db_dependent/Koha/Plugins/Holds_hooks.t b/t/db_dependent/Koha/Plugins/Holds_hooks.t index c259aeb1bc..d1a9dba00d 100755 --- a/t/db_dependent/Koha/Plugins/Holds_hooks.t +++ b/t/db_dependent/Koha/Plugins/Holds_hooks.t @@ -130,7 +130,7 @@ subtest 'after_hold_action (placed) hook tests' => sub { subtest 'Koha::Hold tests' => sub { - plan tests => 4; + plan tests => 7; $schema->storage->txn_begin; @@ -181,6 +181,24 @@ subtest 'Koha::Hold tests' => sub { qr/after_hold_action called with action: resume, ref: Koha::Hold/, '->resume calls the after_hold_action hook'; + warning_like { + $hold->set_transfer; + } + qr/after_hold_action called with action: transfer, ref: Koha::Hold/, + '->set_transfer calls the after_hold_action hook'; + + warning_like { + $hold->set_processing; + } + qr/after_hold_action called with action: processing, ref: Koha::Hold/, + '->set_processing calls the after_hold_action hook'; + + warning_like { + $hold->set_waiting; + } + qr/after_hold_action called with action: waiting, ref: Koha::Hold/, + '->set_waiting calls the after_hold_action hook'; + warning_like { $hold->cancel; } -- 2.37.1