From 04a5bbe1a147ba8c20f7c8b8053729b49cac97dc Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 1 Jul 2021 14:13:05 +0000 Subject: [PATCH] Bug 28644: [19.11.x] Fix calling borrowernumber on undefined value If the hold is not found (e.g. already cancelled), we should return earlier without crashing: Can't call method "borrowernumber" on an undefined value at /usr/share/koha/C4/Reserves.pm line 521 (Note: line number from 19.11) Test plan: Run t/db_dependent/Reserves.t Add a hold, go to user menu with holds in OPAC. At the same time, cancel this hold from staff. Now click the Cancel in OPAC. Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens Signed-off-by: Wainui Witika-Park --- C4/Reserves.pm | 2 +- t/db_dependent/Reserves.t | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 624bdf0df1..ba6747a963 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -523,7 +523,7 @@ sub CanReserveBeCanceledFromOpac { my ($reserve_id, $borrowernumber) = @_; return unless $reserve_id and $borrowernumber; - my $reserve = Koha::Holds->find($reserve_id); + my $reserve = Koha::Holds->find($reserve_id) or return; return 0 unless $reserve->borrowernumber == $borrowernumber; return 0 if ( $reserve->found eq 'W' ) or ( $reserve->found eq 'T' ); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index e1f5025bb2..1596a8f858 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 63; +use Test::More tests => 64; use Test::MockModule; use Test::Warn; @@ -485,6 +485,8 @@ $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$br is($cancancel, 0, 'Reserve in transfer status cant be canceled'); $dbh->do('DELETE FROM reserves', undef, ($bibnum)); +is( CanReserveBeCanceledFromOpac($canres->{resserve_id}, $requesters{$branch_1}), undef, + 'Cannot cancel a deleted hold' ); AddReserve($branch_1, $requesters{$branch_1}, $item_bibnum, $bibitems, 1, undef, $expdate, $notes, 'a title', $checkitem, ''); -- 2.39.5