From 39b320db5b247b3eaddc77465f791f8a4cb3c810 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 25 Sep 2023 12:30:16 +0000 Subject: [PATCH] Bug 34886: Move patron check onto C4/Reserves.pm Rollback changes in opac-detail.pl Run tests: prove t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t prove t/db_dependent/Reserves.t Bug 15534 changed onshelfholds going from 0/1 circ rule to 0/1/2 But the check in opac-detail.pl still remained checking for just a positive value. Currently, onshelfholds is as follows: 1 - Yes 0 - If any unavailable 2 - If all unavailable I think the check needs to be updated to only when onshelfholds = 1 (Yes), which is effectively done in IsAvailableForItemLevelRequest in C4/Reserves.pm, with the caveat that when onshelfholds = 2, it requires the $patron to exist to do the full check. This patch fixes the issue. But also makes it so that the "Place hold" link only shows for the unauthenticated user if onshelfholds = "Yes", whereas before it showed for the unauthenticated user if onshelfholds = "Yes" OR if onshelfholds = "If all unavailable" Signed-off-by: Martin Renvoize --- C4/Reserves.pm | 4 ++-- opac/opac-detail.pl | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 36257378852..d88626916e4 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1369,7 +1369,7 @@ sub IsAvailableForItemLevelRequest { if ( $on_shelf_holds == 1 ) { return 1; - } elsif ( $on_shelf_holds == 2 ) { + } elsif ( $on_shelf_holds == 2 && $patron) { # These calculations work at the biblio level, and can be expensive # we use the in-memory cache to avoid calling once per item when looping items on a biblio @@ -1424,7 +1424,7 @@ sub ItemsAnyAvailableAndNotRestricted { || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan || $branchitemrule->{holdallowed} eq 'from_home_library' && $param->{patron}->branchcode ne $i->homebranch || $branchitemrule->{holdallowed} eq 'from_local_hold_group' && ! $item_library->validate_hold_sibling( { branchcode => $param->{patron}->branchcode } ) - || CanItemBeReserved( $param->{patron}, $i )->{status} ne 'OK'; + || $param->{patron} && CanItemBeReserved( $param->{patron}, $i )->{status} ne 'OK'; } return 0; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 59eeedcfe12..7191625a31c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -682,12 +682,7 @@ else { $item_info->{holding_library_info} = $opac_info_holding->content if $opac_info_holding; $item_info->{home_library_info} = $opac_info_home->content if $opac_info_home; - if ( $patron ) { - $has_reservable_items = IsAvailableForItemLevelRequest($item, $patron, undef); - } else { - $has_reservable_items = - Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => undef } ); - } + $has_reservable_items = $has_reservable_items || IsAvailableForItemLevelRequest ( $item, $patron, undef ); # get collection code description, too my $ccode = $item->ccode; -- 2.41.0