Eileen has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/277929

Change subject: CRM-18193 create all new log tables with log_conn_id = 
varchar(17)
......................................................................

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

Bug: T130161
Change-Id: I33ca596b84184aecf71d7290729d38fb1a4c421d
---
M CRM/Logging/Schema.php
M settings/Core.setting.php
2 files changed, 46 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm/civicrm 
refs/changes/29/277929/1

diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php
index c3f3daa..4b584e5 100644
--- a/CRM/Logging/Schema.php
+++ b/CRM/Logging/Schema.php
@@ -563,7 +563,7 @@
     // rewrite the queries into CREATE TABLE queries for log tables:
     $cols = <<<COLS
             log_date    TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
-            log_conn_id INTEGER,
+            log_conn_id VARCHAR(17),
             log_user_id INTEGER,
             log_action  ENUM('Initialization', 'Insert', 'Update', 'Delete')
 COLS;
@@ -597,9 +597,13 @@
     CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray, TRUE, NULL, 
FALSE, FALSE);
 
     $columns = implode(', ', $this->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";
   }
 
@@ -739,8 +743,16 @@
         $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 1484bc7..98f8b16 100644
--- a/settings/Core.setting.php
+++ b/settings/Core.setting.php
@@ -748,6 +748,36 @@
     'description' => 'When enabled, "empowered by CiviCRM" is displayed at the 
bottom of public forms.',
     'help_text' => NULL,
   ),
+  '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?',
+  ),
   'wpLoadPhp' => array(
     'group_name' => 'CiviCRM Preferences',
     'group' => 'core',

-- 
To view, visit https://gerrit.wikimedia.org/r/277929
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I33ca596b84184aecf71d7290729d38fb1a4c421d
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to