Bug 31894: Extend after_hold_action hook
authorStefan Berndtsson <stefan.berndtsson@gmail.com>
Mon, 17 Oct 2022 14:47:06 +0000 (16:47 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 9 Nov 2022 13:05:32 +0000 (10:05 -0300)
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 <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Hold.pm
t/db_dependent/Koha/Plugins/Holds_hooks.t

index ee98a6c..a5a9d03 100644 (file)
@@ -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;
 }
 
index c259aeb..d1a9dba 100755 (executable)
@@ -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;
 
@@ -182,6 +182,24 @@ subtest 'Koha::Hold tests' => sub {
       '->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;
     }
     qr/after_hold_action called with action: cancel, ref: Koha::Old::Hold/,