From 7e3bf82654d85e9bed1ff45a201dd2b9e54c2e4f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 11 Nov 2020 14:22:50 +0100 Subject: [PATCH] Bug 26997: Fix upgrade process under MySQL 8 If you are coming from an old version of Koha, you may face an upgrade error for the SQL query using 0000-00-00. The idea was to fix it, but actually the DBMS will raise an error (not blocking the upgrade process however). We can hide them to not cause confusion Errors are like: DBD::mysql::db do failed: Incorrect date value: '0000-00-00' for column 'suggesteddate' at row 1 [for Statement "UPDATE suggestions SET suggesteddate = '1970-01-01' WHERE suggesteddate = '0000-00-00';"] at /kohadevbox/koha/installer/data/mysql/updatedatabase.pl line 23312. Test plan: Checkout an old version of Koha (3.20, not older) Insert a dump, install Koha Checkout a recent version of Koha, apply the patch (or use master) Execute the upgrade process You should not see the errors Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 3c087bc216eeab8fe0d68a2d33407b554bc57074) Signed-off-by: Fridolin Somers (cherry picked from commit da58f3e2c541bb617ba3ec5ef58d5cf1792caeb7) Signed-off-by: Andrew Fuerste-Henry (cherry picked from commit c720acc3c915b5c493edd66a65e5519a40e5486b) Signed-off-by: Victor Grousset/tuxayo --- installer/data/mysql/updatedatabase.pl | 62 +++++++++++++++----------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index d067d0c94a..4855a4c490 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -10639,11 +10639,14 @@ if ( CheckVersion($DBversion) ) { $DBversion = "3.21.00.009"; if ( CheckVersion($DBversion) ) { - $dbh->do(q| - UPDATE aqorders SET orderstatus='cancelled' - WHERE (datecancellationprinted IS NOT NULL OR - datecancellationprinted<>'0000-00-00'); - |); + eval { + local $dbh->{PrintError} = 0; + $dbh->do(q| + UPDATE aqorders SET orderstatus='cancelled' + WHERE (datecancellationprinted IS NOT NULL OR + datecancellationprinted<>'0000-00-00'); + |); + }; print "Upgrade to $DBversion done (Bug 13993: Correct orderstatus for transferred orders)\n"; SetVersion($DBversion); } @@ -10874,18 +10877,22 @@ if ( CheckVersion($DBversion) ) { $DBversion = "3.21.00.023"; if ( CheckVersion($DBversion) ) { - $dbh->do(q{ - UPDATE borrowers SET debarred=NULL WHERE debarred='0000-00-00' - }); - $dbh->do(q{ - UPDATE borrowers SET dateexpiry=NULL where dateexpiry='0000-00-00' - }); - $dbh->do(q{ - UPDATE borrowers SET dateofbirth=NULL where dateofbirth='0000-00-00' - }); - $dbh->do(q{ - UPDATE borrowers SET dateenrolled=NULL where dateenrolled='0000-00-00' - }); + eval { + local $dbh->{PrintError} = 0; + $dbh->do(q{ + UPDATE borrowers SET debarred=NULL WHERE debarred='0000-00-00' + }); + $dbh->do(q{ + UPDATE borrowers SET dateexpiry=NULL where dateexpiry='0000-00-00' + }); + $dbh->do(q{ + UPDATE borrowers SET dateofbirth=NULL where dateofbirth='0000-00-00' + }); + $dbh->do(q{ + UPDATE borrowers SET dateenrolled=NULL where dateenrolled='0000-00-00' + }); + }; + print "Upgrade to $DBversion done (Bug 14717: Prevent 0000-00-00 dates in patron data)\n"; SetVersion($DBversion); } @@ -17633,15 +17640,18 @@ $DBversion = '18.12.00.024'; if ( CheckVersion($DBversion) ) { # Fixup any pre-existing bad suggestedby, manageddate, accepteddate dates - $dbh->do( - "UPDATE suggestions SET suggesteddate = '1970-01-01' WHERE suggesteddate = '0000-00-00';" - ); - $dbh->do( - "UPDATE suggestions SET manageddate = '1970-01-01' WHERE manageddate = '0000-00-00';" - ); - $dbh->do( - "UPDATE suggestions SET accepteddate = '1970-01-01' WHERE accepteddate = '0000-00-00';" - ); + eval { + local $dbh->{PrintError} = 0; + $dbh->do( + "UPDATE suggestions SET suggesteddate = '1970-01-01' WHERE suggesteddate = '0000-00-00';" + ); + $dbh->do( + "UPDATE suggestions SET manageddate = '1970-01-01' WHERE manageddate = '0000-00-00';" + ); + $dbh->do( + "UPDATE suggestions SET accepteddate = '1970-01-01' WHERE accepteddate = '0000-00-00';" + ); + }; # Add constraint for suggestedby unless ( foreign_key_exists( 'suggestions', 'suggestions_ibfk_suggestedby' ) ) -- 2.39.5