From 43e7873637c9d235a0c18ebc9ac6656f07b2aa61 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 1 Jul 2021 14:13:05 +0000 Subject: [PATCH] Bug 28644: 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: Jonathan Druart Signed-off-by: Kyle M Hall --- C4/Reserves.pm | 2 +- t/db_dependent/Reserves.t | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 83222dc1c5..dfd0c70568 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -602,7 +602,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 $reserve->is_cancelable_from_opac; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 9f408629d9..93e1799191 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 67; +use Test::More tests => 68; use Test::MockModule; use Test::Warn; @@ -555,6 +555,9 @@ $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( { branchcode => $branch_1, -- 2.39.5