From 340f6aa099d91bb49d2c9c0f58b7dec7108c903d Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Fri, 19 Apr 2013 19:48:36 -0700 Subject: [PATCH] CRM-12390 ---------------------------------------- * CRM-12390: Triggers should not include database name when logging is to the same DB http://issues.civicrm.org/jira/browse/CRM-12390 --- CRM/Logging/Schema.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index d81002f527..beeed84620 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -37,6 +37,7 @@ class CRM_Logging_Schema { private $tables = array(); private $db; + private $useDBPrefix = TRUE; private $reports = array( 'logging/contact/detail', @@ -74,7 +75,14 @@ AND TABLE_NAME LIKE 'civicrm_%' // do not log civicrm_mailing_event* tables, CRM-12300 $this->tables = preg_grep('/^civicrm_mailing_event_/', $this->tables, PREG_GREP_INVERT); - $dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN); + if (defined('CIVICRM_LOGGING_DSN')) { + $dsn = DB::parseDSN(CIVICRM_LOGGING_DSN); + $this->useDBPrefix = (CIVICRM_LOGGING_DSN != CIVICRM_DSN); + } + else { + $dsn = DB::parseDSN(CIVICRM_DSN); + $this->useDBPrefix = FALSE; + } $this->db = $dsn['database']; $dao = CRM_Core_DAO::executeQuery(" @@ -402,7 +410,12 @@ COLS; $suppressLoggingCond = "@civicrm_disable_logging IS NULL OR @civicrm_disable_logging = 0"; $updateSQL = "IF ( (" . implode( ' OR ', $cond ) . ") AND ( $suppressLoggingCond ) ) THEN "; - $sqlStmt = "INSERT INTO `{$this->db}`.log_{tableName} ("; + if ($this->useDBPrefix) { + $sqlStmt = "INSERT INTO `{$this->db}`.log_{tableName} ("; + } + else { + $sqlStmt = "INSERT INTO log_{tableName} ("; + } foreach ($columns as $column) { $sqlStmt .= "$column, "; } -- 2.25.1