Bug 26108: (bug 25855 follow-up) Call after_circ_action hook only if issue exists
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 31 Jul 2020 07:49:06 +0000 (09:49 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 31 Jul 2020 07:49:06 +0000 (09:49 +0200)
AddReturn can be called on an item even if it's not checked out (to
trigger holds for instance).
The hook should (?) not be called in that situation

Test plan:
Confirm the above and that the following tests are now passing:
 t/db_dependent/SIP/Message.t
 t/db_dependent/Reserves.t
 t/db_dependent/Circulation/issue.t
 t/db_dependent/SIP/Transaction.t
 t/db_dependent/Circulation.t

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Circulation.pm

index bda4b00..4b468f8 100644 (file)
@@ -2206,14 +2206,16 @@ sub AddReturn {
         }
     }
 
-    my $checkin = Koha::Old::Checkouts->find($issue->id);
+    if ( $issue ) {
+        my $checkin = Koha::Old::Checkouts->find($issue->id);
 
-    Koha::Plugins->call('after_circ_action', {
-        action  => 'checkin',
-        payload => {
-            checkout=> $checkin
-        }
-    });
+        Koha::Plugins->call('after_circ_action', {
+            action  => 'checkin',
+            payload => {
+                checkout=> $checkin
+            }
+        });
+    }
 
     return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ));
 }