From 1eb2c4337b736cc53a72b76a4b2f6700c410b915 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 Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Kyle M Hall 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 97e0becff0..4ba8812888 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -344,11 +344,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.39.5