From 8d2c1ae5a400284f0c12877bb9b94154b22ca6ba Mon Sep 17 00:00:00 2001 From: Eileen Date: Sat, 23 Apr 2016 04:32:26 +0000 Subject: [PATCH] CRM-18193 add default log_conn values for when interacting with mysql outside of CiviCRM. In this instand @uniqueID will not be set. We had a go at setting it within the trigger but that was unreliable. Eventual decision was a string 'con_' to identify a system connection + a timestamp to hourly granularity + the connection id. Proposed further work is to specifically block the revert from the UI for these and add a higher permission or a 'yes I really really mean it' param to the revert api for these --- CRM/Logging/Schema.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index a8a4aa492e..99dcc2d645 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -868,18 +868,21 @@ COLS; $deleteSQL .= "OLD.$column, "; } if (civicrm_api3('Setting', 'getvalue', array('name' => 'logging_uniqueid_date'))) { - $sqlStmt .= "@uniqueID, @civicrm_user_id, '{eventName}');"; - $deleteSQL .= "@uniqueID, @civicrm_user_id, '{eventName}');"; + // Note that when connecting directly via mysql @uniqueID may not be set so a fallback is + // 'c_' to identify a non-CRM connection + timestamp to the hour + connection_id + // If the connection_id is longer than 6 chars it will be truncated. + // We tried setting the @uniqueID in the trigger but it was unreliable. + // An external interaction could split over 2 connections & it seems worth blocking the revert on + // these reports & adding extra permissioning to the api for this. + $connectionSQLString = "COALESCE(@uniqueID, LEFT(CONCAT('con_', unix_timestamp()/3600, CONNECTION_ID()), 17))"; } 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 .= "CONNECTION_ID(), @civicrm_user_id, '{eventName}');"; + $connectionSQLString = "CONNECTION_ID()"; } - - $sqlStmt .= "END IF;"; - $deleteSQL .= "END IF;"; + $sqlStmt .= $connectionSQLString . ", @civicrm_user_id, '{eventName}'); END IF;"; + $deleteSQL .= $connectionSQLString . ", @civicrm_user_id, '{eventName}'); END IF;"; $insertSQL .= $sqlStmt; $updateSQL .= $sqlStmt; -- 2.25.1