From 116d17d7019867613fe12ab758afa644ba598864 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 Signed-off-by: David Nind Signed-off-by: Tomas Cohen Arazi --- 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 ee98a6cc49..a5a9d03003 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.39.5