From 1d98f354eb34943fee3a992589a660c036e1038d Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 3 Oct 2018 09:25:45 +1300 Subject: [PATCH] Bug 8367: Moved database update out of updatedatabase.pl into atomicupdates dir --- installer/data/mysql/atomicupdate/bug_8367.perl | 23 ++++++++++++++++++++ installer/data/mysql/updatedatabase.pl | 29 ------------------------- 2 files changed, 23 insertions(+), 29 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_8367.perl diff --git a/installer/data/mysql/atomicupdate/bug_8367.perl b/installer/data/mysql/atomicupdate/bug_8367.perl new file mode 100644 index 0000000..464b3a6 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_8367.perl @@ -0,0 +1,23 @@ +my $maxpickupdelay = C4::Context->preference('ReservesMaxPickUpDelay') || 0; #MaxPickupDelay +$dbh->do(q{ DELETE FROM systempreferences WHERE variable='ReservesMaxPickUpDelay'; }); +$dbh->do(q{ DELETE FROM systempreferences WHERE variable='ExpireReservesOnHolidays'; }); +# //DELETE FROM systempreferences WHERE variable='ExpireReservesMaxPickUpDelay'; #This syspref is not needed and would be better suited to be calculated from the holdspickupwait +# //ExpireReservesMaxPickUpDelayCharge #This could be added as a column to the issuing rules. +$dbh->do(q{ ALTER TABLE issuingrules ADD COLUMN holdspickupwait INT(11) NULL default NULL AFTER reservesallowed; }); +$dbh->do(q{ ALTER TABLE reserves ADD COLUMN lastpickupdate DATE NULL default NULL AFTER suspend_until; }); +$dbh->do(q{ ALTER TABLE old_reserves ADD COLUMN lastpickupdate DATE NULL default NULL AFTER suspend_until; }); +my $sth = $dbh->prepare(q{ + UPDATE issuingrules SET holdspickupwait = ? +}); +$sth->execute( $maxpickupdelay ) if $maxpickupdelay; #Don't want to accidentally nullify all! +##Populate the lastpickupdate-column from existing 'ReservesMaxPickUpDelay' +print "Populating the new lastpickupdate-column for all waiting holds. This might take a while.\n"; +$sth = $dbh->prepare(q{ SELECT * FROM reserves WHERE found = 'W'; }); +$sth->execute( ); +my $dtdur = DateTime::Duration->new( days => 0 ); + +while ( my $res = $sth->fetchrow_hashref ) { + C4::Reserves::MoveWaitingdate( $res, $dtdur ); #We call MoveWaitingdate with a 0 duration to simply recalculate the lastpickupdate and store the new values to DB. +} +print "Upgrade to $DBversion done (8367: Add colum issuingrules.holdspickupwait and reserves.lastpickupdate. Populates introduced columns from the expiring ReservesMaxPickUpDelay. Deletes the ReservesMaxPickUpDelay and ExpireReservesOnHolidays -sysprefs)\n"; + diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 5b57b7c..90c6100 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -16066,35 +16066,6 @@ if ( CheckVersion($DBversion) ) { print "Upgrade to $DBversion done (18.05.02 release)\n"; } - -$DBversion = "18.06.00.XXX"; -if ( CheckVersion($DBversion) ) { - my $maxpickupdelay = C4::Context->preference('ReservesMaxPickUpDelay') || 0; #MaxPickupDelay - $dbh->do(q{ DELETE FROM systempreferences WHERE variable='ReservesMaxPickUpDelay'; }); - $dbh->do(q{ DELETE FROM systempreferences WHERE variable='ExpireReservesOnHolidays'; }); - # //DELETE FROM systempreferences WHERE variable='ExpireReservesMaxPickUpDelay'; #This syspref is not needed and would be better suited to be calculated from the holdspickupwait - # //ExpireReservesMaxPickUpDelayCharge #This could be added as a column to the issuing rules. - $dbh->do(q{ ALTER TABLE issuingrules ADD COLUMN holdspickupwait INT(11) NULL default NULL AFTER reservesallowed; }); - $dbh->do(q{ ALTER TABLE reserves ADD COLUMN lastpickupdate DATE NULL default NULL AFTER suspend_until; }); - $dbh->do(q{ ALTER TABLE old_reserves ADD COLUMN lastpickupdate DATE NULL default NULL AFTER suspend_until; }); - my $sth = $dbh->prepare(q{ - UPDATE issuingrules SET holdspickupwait = ? - }); - $sth->execute( $maxpickupdelay ) if $maxpickupdelay; #Don't want to accidentally nullify all! - - ##Populate the lastpickupdate-column from existing 'ReservesMaxPickUpDelay' - print "Populating the new lastpickupdate-column for all waiting holds. This might take a while.\n"; - $sth = $dbh->prepare(q{ SELECT * FROM reserves WHERE found = 'W'; }); - $sth->execute( ); - my $dtdur = DateTime::Duration->new( days => 0 ); - - while ( my $res = $sth->fetchrow_hashref ) { - C4::Reserves::MoveWaitingdate( $res, $dtdur ); #We call MoveWaitingdate with a 0 duration to simply recalculate the lastpickupdate and store the new values to DB. - } - print "Upgrade to $DBversion done (8367: Add colum issuingrules.holdspickupwait and reserves.lastpickupdate. Populates introduced columns from the expiring ReservesMaxPickUpDelay. Deletes the ReservesMaxPickUpDelay and ExpireReservesOnHolidays -sysprefs)\n"; - SetVersion($DBversion); -} - # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. -- 2.1.4