Bug 26108: Only call the plugin hook if a return took place
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 31 Jul 2020 12:52:10 +0000 (09:52 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 31 Jul 2020 13:04:44 +0000 (15:04 +0200)
This patch makes the hooks be called only if the checkin is effective
(i.e. if it is not rejected for some reason.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Plugins/Circulation_hooks.t
=> FAIL: Tests fail
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

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

C4/Circulation.pm

index 4b468f8..a9cf02c 100644 (file)
@@ -2124,7 +2124,7 @@ sub AddReturn {
     my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
     ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->itemnumber, undef, $lookahead ) unless ( $item->withdrawn );
     # if a hold is found and is waiting at another branch, change the priority back to 1 and trigger the hold (this will trigger a transfer and update the hold status properly)
-    if ( $resfound eq "Waiting" and $branch ne $resrec->{branchcode} ) {
+    if ( $resfound and $resfound eq "Waiting" and $branch ne $resrec->{branchcode} ) {
         my $hold = C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
         $resfound = 'Reserved';
         $resrec = $hold->unblessed;
@@ -2206,7 +2206,7 @@ sub AddReturn {
         }
     }
 
-    if ( $issue ) {
+    if ( $doreturn and $issue ) {
         my $checkin = Koha::Old::Checkouts->find($issue->id);
 
         Koha::Plugins->call('after_circ_action', {