From f79d2a29ebe1ec69285017db6033eff3908eef96 Mon Sep 17 00:00:00 2001 From: Jan Kissig Date: Thu, 7 May 2026 11:33:03 +0000 Subject: [PATCH] Bug 42412: Fix Incorrect date error in db-revs when using MySQL In Bug 36466 db_revs/251200019.pl was introduced to update wrong date values (0000-00-00) with NULL. This can fail on MySQL as it is running with sql_mode NO_ZERO_DATE activated which does not allow to select or update date fields with values='0000-00-00'. This patch changes the update queries in db_revs/251200019.pl to use Installer::sanitize_zero_date on both columns. Test plan: As the test shall be done using MysQL and Mariadb start 2 ktds: MySQL) DB_IMAGE=mysql:8.0 ktd --proxy --name mysql8 up -d MariaDB) ktd --proxy --name maria up -d a) checkout a version prior 36466: git checkout v24.11.14-1 b) reset_all c) Connect to staff interface (mysql8-intra.localhost and maria-intra.localhost) d) Go to Serials and create a new subscription e) run the following to enter database client in each ktd shell: koha-mysql kohadev f-mysql) run the following commands to be allowed to change planneddate and publisheddate to '0000-00-00': SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; update serial set planneddate = '0000-00-00', publisheddate = '0000-00-00'; f-maria) update serial set planneddate = '0000-00-00', publisheddate = '0000-00-00'; g) verify via: select * from serial; h) checkout main via: git checkout main i-mysql) run updatedatabase Upgrade to 25.12.00.019 [09:35:55]: Bug 36466 - Fix the incorrect 0000-00-00 date in planneddate and publisheddate field ERROR: {UNKNOWN}: DBI Exception: DBD::mysql::db do Incorrect date error in db-revs when using MySQL In 36466 db_revs/251200019.pl for column 'planneddate' at row 1 at /kohadevbox/koha/C4/Installer.pm line 818 i-maria) do not run updatedatabase yet j) apply patch k-mysql) run updatedatabase Upgrade to 25.12.00.019 [09:37:02]: Bug 36466 - Fix the incorrect 0000-00-00 date in planneddate and publisheddate field Incorrect date planneddate and publisheddate fixed ... -> is successful now k-maria) run updatedatabase l) verify via: select * from serial; Signed-off-by: Lucas Gass Signed-off-by: Wainui Witika-Park --- installer/data/mysql/db_revs/250508001.pl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/installer/data/mysql/db_revs/250508001.pl b/installer/data/mysql/db_revs/250508001.pl index 68671054ee..6752d39efa 100755 --- a/installer/data/mysql/db_revs/250508001.pl +++ b/installer/data/mysql/db_revs/250508001.pl @@ -7,12 +7,10 @@ return { my ($args) = @_; my ( $dbh, $out ) = @$args{qw(dbh out)}; - # Do you stuffs here - $dbh->do(q{update serial set planneddate=null where planneddate='0000-00-00';}); - $dbh->do(q{update serial set publisheddate=null where publisheddate='0000-00-00';}); + # sanitize both columns as they could be filled with invalid dates + sanitize_zero_date( 'serial', 'planneddate' ); + sanitize_zero_date( 'serial', 'publisheddate' ); - # Print useful stuff here - # sysprefs - say $out "incorrect date inplanneddate and publisheddate fixed"; + say $out "Incorrect date planneddate and publisheddate fixed"; }, };