From 6dace1b29efcd37756f4f045f6e1bc4d78ad4544 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 18 Aug 2022 14:00:54 -0300 Subject: [PATCH] Bug 31395: Only try to cancel holds if item found This patch makes the code dealing with waiting holds with cancellation requests be dependent on the fact an item has been found. The returns.pl controller is a bit messy as the real return takes place outside the main `if ($item)` block. This should be refactored and probably run inside a transaction... In the meantime this patch will make the job. To test: 1. Try to return an invalid barcode (e.g. ASDQWE) => FAIL: Things explode 2. Apply this patch 3. Repeat 1 => SUCCESS: Doesn't explode! 4. Verify that returning an item with a waiting hold with cancellation requests still cancells the hold. => SUCCESS: It does! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- circ/returns.pl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/circ/returns.pl b/circ/returns.pl index ac3260a5e92..108d7bf68cd 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -348,11 +348,11 @@ if ($barcode) { # is there a waiting hold for the item, for which cancellation # has been requested? - my $waiting_holds_to_be_cancelled = - Koha::Holds->waiting->search( { itemnumber => $item->id } ) - ->filter_by_has_cancellation_requests; - while ( my $hold = $waiting_holds_to_be_cancelled->next ) { - $hold->cancel; + if ($item) { + my $waiting_holds_to_be_cancelled = $item->holds->waiting->filter_by_has_cancellation_requests; + while ( my $hold = $waiting_holds_to_be_cancelled->next ) { + $hold->cancel; + } } # do the return -- 2.37.2