From e53944ef534bd807ed8a274d6036f90fdde22189 Mon Sep 17 00:00:00 2001 From: Brian Shaughnessy Date: Tue, 5 Nov 2013 00:17:09 -0500 Subject: [PATCH] CRM-13703 --- CRM/Core/DAO.php | 4 ++-- CRM/Logging/Schema.php | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index ce8d2cfb97..d31ccda9cf 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1526,11 +1526,11 @@ SELECT contact_id * @param $tableName string the specific table requiring a rebuild; or NULL to rebuild all tables * @see CRM-9716 */ - static function triggerRebuild($tableName = NULL) { + static function triggerRebuild($tableName = NULL, $force = FALSE) { $info = array(); $logging = new CRM_Logging_Schema; - $logging->triggerInfo($info, $tableName); + $logging->triggerInfo($info, $tableName, $force); CRM_Core_I18n_Schema::triggerInfo($info, $tableName); CRM_Contact_BAO_Contact::triggerInfo($info, $tableName); diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 877be2dad1..1ab0b64d83 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -207,7 +207,7 @@ AND TABLE_NAME LIKE 'log_civicrm_%' $this->fixSchemaDifferencesForALL(); } // invoke the meta trigger creation call - CRM_Core_DAO::triggerRebuild(); + CRM_Core_DAO::triggerRebuild(NULL, TRUE); } /** @@ -280,7 +280,8 @@ AND TABLE_NAME LIKE 'log_civicrm_%' foreach ($this->tables as $table) { if (empty($this->logs[$table])) { $this->createLogTableFor($table); - } else { + } + else { $diffs[$table] = $this->columnsWithDiffSpecs($table, "log_$table"); } } @@ -339,12 +340,12 @@ AND TABLE_NAME LIKE 'log_civicrm_%' /** * Get an array of column names of the given table. */ - private function columnsOf($table) { + private function columnsOf($table, $force = FALSE) { static $columnsOf = array(); $from = (substr($table, 0, 4) == 'log_') ? "`{$this->db}`.$table" : $table; - if (!isset($columnsOf[$table])) { + if (!isset($columnsOf[$table]) || $force) { CRM_Core_Error::ignoreException(); $dao = CRM_Core_DAO::executeQuery("SHOW COLUMNS FROM $from"); CRM_Core_Error::setCallback(); @@ -412,6 +413,10 @@ WHERE table_schema IN ('{$this->db}', '{$civiDB}')"; // NOTE: we consider only those columns for modifications where there is a spec change, and that the column definition // wasn't deliberately modified by fixTimeStampAndNotNullSQL() method. foreach ($civiTableSpecs as $col => $colSpecs) { + if ( !is_array($logTableSpecs[$col]) ) { + $logTableSpecs[$col] = array(); + } + $specDiff = array_diff($civiTableSpecs[$col], $logTableSpecs[$col]); if (!empty($specDiff) && $col != 'id' && !array_key_exists($col, $diff['ADD'])) { // ignore 'id' column for any spec changes, to avoid any auto-increment mysql errors @@ -530,7 +535,7 @@ COLS; return (bool) CRM_Core_DAO::singleValueQuery("SHOW TRIGGERS LIKE 'civicrm_contact'"); } - function triggerInfo(&$info, $tableName = NULL) { + function triggerInfo(&$info, $tableName = NULL, $force = FALSE) { // check if we have logging enabled $config =& CRM_Core_Config::singleton(); if (!$config->logging) { @@ -550,7 +555,7 @@ COLS; // logging is enabled, so now lets create the trigger info tables foreach ($tableNames as $table) { - $columns = $this->columnsOf($table); + $columns = $this->columnsOf($table, $force); // only do the change if any data has changed $cond = array( ); -- 2.25.1