Bug 29517: Check if agerestriction field is mapped before fetching biblio

This patch simply adds a check of cached values to see if agerestriction enabled before
fetching the biblio object

To test:
1 - prove -v t/db_dependent/Holds.t

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2021-11-18 12:03:36 +00:00 committed by Kyle Hall
parent 6f574f6747
commit bcd73fbdae
1 changed files with 9 additions and 6 deletions

View File

@ -24,6 +24,7 @@ package C4::Reserves;
use Modern::Perl;
use C4::Accounts;
use C4::Biblio qw( GetMarcFromKohaField );
use C4::Circulation qw( CheckIfIssuedToPatron GetAgeRestriction GetBranchItemRule );
use C4::Context;
use C4::Items qw( CartToShelf get_hostitemnumbers_of );
@ -381,7 +382,6 @@ sub CanItemBeReserved {
# we retrieve borrowers and items informations #
# item->{itype} will come for biblioitems if necessery
my $item = Koha::Items->find($itemnumber);
my $biblio = $item->biblio;
my $patron = Koha::Patrons->find( $borrowernumber );
my $borrower = $patron->unblessed;
@ -390,10 +390,13 @@ sub CanItemBeReserved {
if ( $item->damaged
&& !C4::Context->preference('AllowHoldsOnDamagedItems') );
# Check for the age restriction
my ( $ageRestriction, $daysToAgeRestriction ) =
C4::Circulation::GetAgeRestriction( $biblio->biblioitem->agerestriction, $borrower );
return { status => 'ageRestricted' } if $daysToAgeRestriction && $daysToAgeRestriction > 0;
if( GetMarcFromKohaField('biblioitems.agerestriction') ){
my $biblio = $item->biblio;
# Check for the age restriction
my ( $ageRestriction, $daysToAgeRestriction ) =
C4::Circulation::GetAgeRestriction( $biblio->biblioitem->agerestriction, $borrower );
return { status => 'ageRestricted' } if $daysToAgeRestriction && $daysToAgeRestriction > 0;
}
# Check that the patron doesn't have an item level hold on this item already
return { status =>'itemAlreadyOnHold' }
@ -401,7 +404,7 @@ sub CanItemBeReserved {
# Check that patron have not checked out this biblio (if AllowHoldsOnPatronsPossessions set)
if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
&& C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $biblio->biblionumber ) ) {
&& C4::Circulation::CheckIfIssuedToPatron( $patron->borrowernumber, $item->biblionumber ) ) {
return { status =>'alreadypossession' };
}