From: Seamus Lee Date: Tue, 23 Jan 2018 23:29:44 +0000 (+1100) Subject: CRM-21687 fix issue with MariaDB 10.2 logging query writing due to current_timestamp... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=91bd5c1426d6862a6940b5d702a50595fc96b3af;p=civicrm-core.git 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 --- diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 4551b89a64..e91f02d52f 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -444,7 +444,7 @@ AND (TABLE_NAME LIKE 'log_civicrm_%' $nonStandardTableNameString ) $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 @@ AND (TABLE_NAME LIKE 'log_civicrm_%' $nonStandardTableNameString ) * * @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 0000000000..889cdaf3d0 --- /dev/null +++ b/tests/phpunit/CRM/Logging/SchemaTest.php @@ -0,0 +1,33 @@ +assertEquals($expectedQuery, CRM_Logging_Schema::fixTimeStampAndNotNullSQL($query)); + } + +}