From 91bd5c1426d6862a6940b5d702a50595fc96b3af Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 24 Jan 2018 10:29:44 +1100 Subject: [PATCH] CRM-21687 fix issue with MariaDB 10.2 logging query writing due to current_timestamp and timestamp getting () added on the end in Maria10.2 --- CRM/Logging/Schema.php | 7 +++-- tests/phpunit/CRM/Logging/SchemaTest.php | 33 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/CRM/Logging/SchemaTest.php diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 4551b89a64f6..e91f02d52ffb 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -444,7 +444,7 @@ private function _getColumnQuery($col, $createQuery) { $line = preg_grep("/^ `$col` /", $createQuery); $line = rtrim(array_pop($line), ','); // CRM-11179 - $line = $this->fixTimeStampAndNotNullSQL($line); + $line = self::fixTimeStampAndNotNullSQL($line); return $line; } @@ -484,9 +484,12 @@ public function fixSchemaDifferencesForAll($rebuildTrigger = FALSE) { * * @return mixed */ - public function fixTimeStampAndNotNullSQL($query) { + public static function fixTimeStampAndNotNullSQL($query) { + $query = str_ireplace("TIMESTAMP() NOT NULL", "TIMESTAMP NULL", $query); $query = str_ireplace("TIMESTAMP NOT NULL", "TIMESTAMP NULL", $query); + $query = str_ireplace("DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP()", '', $query); $query = str_ireplace("DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", '', $query); + $query = str_ireplace("DEFAULT CURRENT_TIMESTAMP()", '', $query); $query = str_ireplace("DEFAULT CURRENT_TIMESTAMP", '', $query); $query = str_ireplace("NOT NULL", '', $query); return $query; diff --git a/tests/phpunit/CRM/Logging/SchemaTest.php b/tests/phpunit/CRM/Logging/SchemaTest.php new file mode 100644 index 000000000000..889cdaf3d08b --- /dev/null +++ b/tests/phpunit/CRM/Logging/SchemaTest.php @@ -0,0 +1,33 @@ +assertEquals($expectedQuery, CRM_Logging_Schema::fixTimeStampAndNotNullSQL($query)); + } + +}