From 8729675104cfc01d564dae6a7ebcb80a97b1696c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 23 Nov 2020 15:52:56 +0100 Subject: [PATCH] Bug 27071: Code simplification Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit c6606d4a6567a00f2defd72a32ff466c01a54e96) Signed-off-by: Fridolin Somers (cherry picked from commit 9104c191f3c3f5a77c7648e167cc5c344feea026) Signed-off-by: Andrew Fuerste-Henry --- C4/Reserves.pm | 4 ++-- Koha/Library.pm | 18 ++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 0c24a55cfa..d4fc4422e4 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -546,10 +546,10 @@ sub CanItemBeReserved { unless ($item->can_be_transferred({ to => $destination })) { return { status => 'cannotBeTransferred' }; } - unless ($branchitemrule->{hold_fulfillment_policy} ne 'holdgroup' || $item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} )) { + if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup' && !$item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} )) { return { status => 'pickupNotInHoldGroup' }; } - unless ($branchitemrule->{hold_fulfillment_policy} ne 'patrongroup' || Koha::Libraries->find({branchcode => $borrower->{branchcode}})->validate_hold_sibling({branchcode => $pickup_branchcode})) { + if ($branchitemrule->{hold_fulfillment_policy} eq 'patrongroup' && !Koha::Libraries->find({branchcode => $borrower->{branchcode}})->validate_hold_sibling({branchcode => $pickup_branchcode})) { return { status => 'pickupNotInHoldGroup' }; } } diff --git a/Koha/Library.pm b/Koha/Library.pm index f1f910e366..32e7d0f46b 100644 --- a/Koha/Library.pm +++ b/Koha/Library.pm @@ -174,23 +174,9 @@ sub validate_hold_sibling { return 1 if $params->{branchcode} eq $self->id; + my $branchcode = $params->{branchcode}; my @hold_libraries = $self->get_hold_libraries; - - foreach (@hold_libraries) { - my $hold_library = $_; - my $is_valid = 0; - foreach my $key (keys %$params) { - if ($hold_library->$key eq $params->{$key}) { - $is_valid=1; - last; - } - } - if($is_valid) { - #Found one library that meets all search parameters - return 1; - } - } - return 0; + return grep {$_->branchcode eq $branchcode} @hold_libraries; } =head2 Internal methods -- 2.39.5