From 332d634b18ed9b25128dcc9b084262ea87460cca Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 14 Nov 2024 12:49:39 +0000 Subject: [PATCH] Bug 36822: (follow-up) Catch MySQL 8 failure in update We add a try/catch around the call to fix 0000-00-00 dates in the database. MySQL 8.0 throws an error on the WHERE clause for such a search. Signed-off-by: Martin Renvoize --- installer/data/mysql/db_revs/240600056.pl | 35 ++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/installer/data/mysql/db_revs/240600056.pl b/installer/data/mysql/db_revs/240600056.pl index 82b0413128a..b7e09718c8d 100755 --- a/installer/data/mysql/db_revs/240600056.pl +++ b/installer/data/mysql/db_revs/240600056.pl @@ -1,5 +1,6 @@ use Modern::Perl; use Koha::Installer::Output qw(say_warning say_success say_info); +use Try::Tiny qw( catch try ); return { bug_number => "36822", @@ -8,21 +9,23 @@ return { my ($args) = @_; my ( $dbh, $out ) = @$args{qw(dbh out)}; - my $sth = $dbh->prepare( - q{ - SELECT borrowernumber - FROM borrowers - WHERE updated_on = '0000-00-00 00:00:00' - } - ); - $sth->execute; - my $results = $sth->fetchall_arrayref( {} ); - - if (@$results) { - sanitize_zero_date( 'borrowers', 'updated_on' ); - say_info( $out, "The following borrowers' updated_on has been sanitized: " - . join( ', ', map { $_->{borrowernumber} } @$results ) ); - } - + try { + my $sth = $dbh->prepare( + q{ + SELECT borrowernumber + FROM borrowers + WHERE updated_on = '0000-00-00 00:00:00' + } + ); + $sth->execute; + my $results = $sth->fetchall_arrayref( {} ); + if (@$results) { + sanitize_zero_date( 'borrowers', 'updated_on' ); + say_info( $out, "The following borrowers' updated_on has been sanitized: " + . join( ', ', map { $_->{borrowernumber} } @$results ) ); + } + } catch { + say_warning( $out, "Unable to sanitize borrowers.updated_on, you may want to check for 0000-00-00 dates" ); + }; }, }; -- 2.47.0