From 821f9d813755412ace93411cca9e5fcad9053da3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 10 Dec 2020 09:50:17 +0100 Subject: [PATCH] Bug 27160: Prevent 500 when checking an item in if ReservesMaxPickUpDelay has been deleted We could default to 0 if the syspref does not exist. However I don't think we should deal with that kind of issue, sysprefs must be in DB. Test plan: Delete ReservesMaxPickUpDelay from the DB Place an item on hold Check it in Confirm the hold Without this patch you get: "Validation failed for type named Defined declared in package Specio::Library::Builtins" (see the relevant part of the trace at comment 3) --- Koha/Hold.pm | 2 +- t/db_dependent/Koha/Holds.t | 41 ++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 7754691238..176b7bdf7f 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -191,7 +191,7 @@ sub set_waiting { $requested_expiration = dt_from_string($self->expirationdate); } - my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); + my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay") || 0; my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays'); my $expirationdate = $today->clone; diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t index 538e7119de..bd5e778390 100755 --- a/t/db_dependent/Koha/Holds.t +++ b/t/db_dependent/Koha/Holds.t @@ -19,12 +19,13 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; use Test::Warn; use C4::Reserves; use Koha::AuthorisedValueCategory; use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); use Koha::Holds; use t::lib::Mocks; @@ -408,6 +409,44 @@ subtest 'Desks' => sub { }; +subtest 'set_waiting' => sub { + + plan tests => 1; + + subtest 'ReservesMaxPickUpDelay got removed' => sub { + + plan tests => 1; + + t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', undef); + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $item = $builder->build_sample_item({ library => $library->branchcode }); + my $manager = $builder->build_object( { class => "Koha::Patrons" } ); + t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { branchcode => $library->branchcode, } + } + ); + + my $reserve_id = C4::Reserves::AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item->biblionumber, + priority => 1, + itemnumber => $item->itemnumber, + } + ); + + my $hold = Koha::Holds->find($reserve_id); + $hold->set_waiting; + is( $hold->waitingdate, dt_from_string->ymd, 'If ReservesMaxPickUpDelay does not exist in DB, we should default to 0' ); + }; +}; + $schema->storage->txn_rollback; 1; -- 2.20.1