From e2d030efe7e39ed68c3abf714e9f5cc0c19c11e3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 6 Aug 2019 09:09:18 -0500 Subject: [PATCH] Bug 23265: (bug 12063 follow-up) Remove Koha::Holds from updatedatabase Test plan: Have a DB that fail the 16.12.00.032 update, then apply this patch and verify the expiration dates RM: Please inforce this rule, no use of Koha:: in updatedatabase! Signed-off-by: Victor Grousset Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize (cherry picked from commit 18d8d3b38b367ee0ea10169a0433e4a273252f15) Signed-off-by: Fridolin Somers (cherry picked from commit 8458626205fececfb1486cbb42b57f6e0c1af8e3) Signed-off-by: Lucas Gass --- installer/data/mysql/updatedatabase.pl | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 515305ae60..a4f0f37b07 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -14348,32 +14348,40 @@ if( CheckVersion( $DBversion ) ) { $DBversion = '16.12.00.032'; if( CheckVersion( $DBversion ) ) { require Koha::Calendar; - require Koha::Holds; $dbh->do(q{ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('ExcludeHolidaysFromMaxPickUpDelay', '0', 'If ON, reserves max pickup delay takes into account the closed days.', NULL, 'Integer'); }); - my $waiting_holds = Koha::Holds->search({ found => 'W', priority => 0 }); + my $waiting_holds = $dbh->selectall_arrayref(q| + SELECT expirationdate, waitingdate, branchcode + FROM reserves + WHERE found = 'W' AND priority = 0 + |); + my $update_sth = $dbh->prepare(q| + UPDATE reserves + SET expirationdate = ? + WHERE reserve_id = ? + |); my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay"); - while ( my $hold = $waiting_holds->next ) { + for my $hold ( @$waiting_holds ) { my $requested_expiration; - if ($hold->expirationdate) { - $requested_expiration = dt_from_string($hold->expirationdate); + if ($hold->{expirationdate}) { + $requested_expiration = dt_from_string($hold->{expirationdate}); } - my $expirationdate = dt_from_string($hold->waitingdate); + my $expirationdate = dt_from_string($hold->{waitingdate}); if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) { - my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode ); + my $calendar = Koha::Calendar->new( branchcode => $hold->{branchcode} ); $expirationdate = $calendar->days_forward( $expirationdate, $max_pickup_delay ); } else { $expirationdate->add( days => $max_pickup_delay ); } my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0; - $hold->expirationdate($cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd)->store; + $update_sth->execute($cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd, $hold->{reserve_id}); } SetVersion( $DBversion ); -- 2.39.5