From 3bf35e82bf3a7f5def90df4f2c98a0ba50fc9a41 Mon Sep 17 00:00:00 2001 From: Jason Coward Date: Mon, 25 Mar 2024 09:46:06 -0600 Subject: [PATCH] Fix default value for modManagerLog.occurred column (#16526) ### What does it do? Adds a default value for the datetime column in the modx_manager_log table that is compatible with strict modes, which may be enabled in some environments. Re-up of #15736 with migration Re-up of #16520 to target 3.0.x ### Why is it needed? Beginning with MySQL > 5.7.8 added strict modes ERROR_FOR_DIVISION_BY_ZERO, NO_ZERO_DATE, NO_ZERO_IN_DATE. With these strict modes enabled, a datetime default value cannot be NULL and must be > '0000-00-00'. ### How to test Install/update on MySQL 5.7.8 ### Related issue(s)/PR(s) Re-up of #15736 Re-up of #16520 --------- Co-authored-by: Mark Hamstra --- core/model/schema/modx.mysql.schema.xml | 2 +- core/src/Revolution/mysql/modManagerLog.php | 6 +++--- setup/includes/upgrades/common/3.0.5-db-changes.php | 12 ++++++++++++ setup/includes/upgrades/mysql/3.0.5-pl.php | 11 +++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 setup/includes/upgrades/common/3.0.5-db-changes.php create mode 100644 setup/includes/upgrades/mysql/3.0.5-pl.php diff --git a/core/model/schema/modx.mysql.schema.xml b/core/model/schema/modx.mysql.schema.xml index 05c4afbb3a0..fd6efd4c602 100644 --- a/core/model/schema/modx.mysql.schema.xml +++ b/core/model/schema/modx.mysql.schema.xml @@ -646,7 +646,7 @@ - + diff --git a/core/src/Revolution/mysql/modManagerLog.php b/core/src/Revolution/mysql/modManagerLog.php index 7020239c56a..d65c3663fb7 100644 --- a/core/src/Revolution/mysql/modManagerLog.php +++ b/core/src/Revolution/mysql/modManagerLog.php @@ -18,7 +18,7 @@ class modManagerLog extends \MODX\Revolution\modManagerLog 'fields' => array ( 'user' => 0, - 'occurred' => NULL, + 'occurred' => 'CURRENT_TIMESTAMP', 'action' => '', 'classKey' => '', 'item' => '0', @@ -38,8 +38,8 @@ class modManagerLog extends \MODX\Revolution\modManagerLog array ( 'dbtype' => 'datetime', 'phptype' => 'datetime', - 'null' => true, - 'default' => NULL, + 'null' => false, + 'default' => 'CURRENT_TIMESTAMP', ), 'action' => array ( diff --git a/setup/includes/upgrades/common/3.0.5-db-changes.php b/setup/includes/upgrades/common/3.0.5-db-changes.php new file mode 100644 index 00000000000..8cd088417ce --- /dev/null +++ b/setup/includes/upgrades/common/3.0.5-db-changes.php @@ -0,0 +1,12 @@ +getManager(); + +$manager->alterField(\MODX\Revolution\modManagerLog::class, 'occurred'); diff --git a/setup/includes/upgrades/mysql/3.0.5-pl.php b/setup/includes/upgrades/mysql/3.0.5-pl.php new file mode 100644 index 00000000000..e038042b58d --- /dev/null +++ b/setup/includes/upgrades/mysql/3.0.5-pl.php @@ -0,0 +1,11 @@ +