From 4af1d9ac0cd385bd0ff9742b4e0fbe85379e61bc Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 4 Sep 2008 12:23:47 -0500 Subject: [PATCH] bug 2582 [2/2]: fix NULL issues.issuedate Corrects loans whose issuedate was set to NULL during a renewal as follows: * First, tries to extract the loan date from the statistics table. * For any remaining rows, sets the issue date to the date of the last renewal. Signed-off-by: Galen Charlton Signed-off-by: Chris Cormack --- installer/data/mysql/updatedatabase.pl | 37 +++++++++++++++++++++++++- kohaversion.pl | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 19793ad6e1..3fa1ff863f 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -1969,7 +1969,7 @@ if (C4::Context->preference("Version") =~/3\.00/) { } } -$DBversion = '3.00.02.001'; +$DBversion = '3.00.04.001'; if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { $dbh->do(" CREATE TABLE hold_fill_targets ( @@ -1999,6 +1999,41 @@ if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = '3.00.04.002'; +if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { + # use statistics where available + $dbh->do(" + ALTER TABLE statistics ADD KEY tmp_stats (type, itemnumber, borrowernumber) + "); + $dbh->do(" + UPDATE issues iss + SET issuedate = ( + SELECT max(datetime) + FROM statistics + WHERE type = 'issue' + AND itemnumber = iss.itemnumber + AND borrowernumber = iss.borrowernumber + ) + WHERE issuedate IS NULL; + "); + $dbh->do("ALTER TABLE statistics DROP KEY tmp_stats"); + + # default to last renewal date + $dbh->do(" + UPDATE issues + SET issuedate = lastreneweddate + WHERE issuedate IS NULL + and lastreneweddate IS NOT NULL + "); + + my $num_bad_issuedates = $dbh->selectrow_array("SELECT COUNT(*) FROM issues WHERE issuedate IS NULL"); + if ($num_bad_issuedates > 0) { + print STDERR "After the upgrade to $DBversion, there are still $num_bad_issuedates loan(s) with a NULL (blank) loan date. ", + "Please check the issues table in your database."; + } + print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)"; + SetVersion($DBversion); +} =item DropAllForeignKeys($table) diff --git a/kohaversion.pl b/kohaversion.pl index 754b2267b3..5f970c79c2 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -10,7 +10,7 @@ use strict; sub kohaversion { - our $VERSION = '3.00.04.001'; + our $VERSION = '3.00.04.002'; # version needs to be set this way # so that it can be picked up by Makefile.PL # during install -- 2.39.5