From 8dd883ca3bd00618905e1c7913bb9214d75a4153 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 16 Mar 2016 11:57:23 +1300 Subject: [PATCH] CRM-18193 create all new log tables with log_conn_id = varchar(17) This provides support for the unique id rather than the non-unique connection id Change-Id: Ia2ce2f1854d1f6f90095585dbb3924f704be38b5 --- CRM/Logging/Schema.php | 20 +++++++++++++++---- settings/Core.setting.php | 30 ++++++++++++++++++++++++++++ tests/phpunit/api/v3/LoggingTest.php | 1 + 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index b64452a270..47c761392a 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -597,7 +597,7 @@ WHERE table_schema IN ('{$this->db}', '{$civiDB}')"; $cols = <<columnsOf($table)); - CRM_Core_DAO::executeQuery("INSERT INTO `{$this->db}`.log_$table ($columns, log_conn_id, log_user_id, log_action) SELECT $columns, CONNECTION_ID(), @civicrm_user_id, 'Initialization' FROM {$table}", CRM_Core_DAO::$_nullArray, TRUE, NULL, FALSE, FALSE); + CRM_Core_DAO::executeQuery("INSERT INTO `{$this->db}`.log_$table ($columns, log_conn_id, log_user_id, log_action) SELECT $columns, @uniqueID, @civicrm_user_id, 'Initialization' FROM {$table}", CRM_Core_DAO::$_nullArray, TRUE, NULL, FALSE, FALSE); $this->tables[] = $table; + if(empty($this->logs)) { + civicrm_api3('Setting', 'create', array('logging_uniqueid_date' => 'now')); + civicrm_api3('Setting', 'create', array('logging_all_tables_uniquid' => 1)); + } $this->logs[$table] = "log_$table"; } @@ -776,8 +780,16 @@ COLS; $sqlStmt .= "NEW.$column, "; $deleteSQL .= "OLD.$column, "; } - $sqlStmt .= "CONNECTION_ID(), @civicrm_user_id, '{eventName}');"; - $deleteSQL .= "CONNECTION_ID(), @civicrm_user_id, '{eventName}');"; + if (civicrm_api3('Setting', 'getvalue', array('name' => 'logging_uniqueid_date', 'group' => 'core'))) { + $sqlStmt .= "@uniqueID, @civicrm_user_id, '{eventName}');"; + $deleteSQL .= "@uniqueID, @civicrm_user_id, '{eventName}');"; + } + else { + // The log tables have not yet been converted to have varchar(17) fields for log_conn_id. + // Continue to use the less reliable connection_id for al tables for now. + $sqlStmt .= "CONNECTION_ID(), @civicrm_user_id, '{eventName}');"; + $deleteSQL .= "@uniqueID, @civicrm_user_id, '{eventName}');"; + } $sqlStmt .= "END IF;"; $deleteSQL .= "END IF;"; diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 89dd7d150c..ce2c88fa9b 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -733,6 +733,36 @@ return array( 'CRM_Logging_Schema::onToggle', ), ), + 'logging_uniqueid_date' => array( + 'add' => '4.7', + 'help_text' => ts('This is the date when CRM-18193 was implemented'), + 'is_domain' => 1, + 'is_contact' => 0, + 'group_name' => 'CiviCRM Preferences', + 'group' => 'core', + 'name' => 'logging_uniqueid_date', + 'type' => 'Date', + 'quick_form_type' => 'DateTime', + 'html_type' => '', + 'default' => NULL, + 'title' => 'Logging Unique ID not recorded before', + 'description' => 'This is the date when CRM-18193 was implemented', + ), + 'logging_all_tables_uniquid' => array( + 'add' => '4.7', + 'help_text' => ts('This indicates there are no tables holdng pre-uniqid log_conn_id values (CRM-18193)'), + 'is_domain' => 1, + 'is_contact' => 0, + 'group_name' => 'CiviCRM Preferences', + 'group' => 'core', + 'name' => 'logging_all_tables_uniquid', + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'html_type' => '', + 'default' => 0, + 'title' => 'All tables use Unique Connection ID', + 'description' => 'Do some tables pre-date CRM-18193?', + ), 'userFrameworkUsersTableName' => array( 'add' => '4.7', 'help_text' => NULL, diff --git a/tests/phpunit/api/v3/LoggingTest.php b/tests/phpunit/api/v3/LoggingTest.php index 7e885b0cce..24bd12d5c6 100644 --- a/tests/phpunit/api/v3/LoggingTest.php +++ b/tests/phpunit/api/v3/LoggingTest.php @@ -111,6 +111,7 @@ class api_v3_LoggingTest extends CiviUnitTestCase { $this->assertEquals('log_civicrm_contact', $dao->Table); $tableField = 'Create_Table'; $this->assertContains('`log_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,', $dao->$tableField); + $this->assertContains('`log_conn_id` varchar(17) COLLATE utf8_unicode_ci DEFAULT NULL,', $dao->$tableField); return $dao->$tableField; } -- 2.25.1