From f8d28563915bfeea0663c12df4ef20ce3d10ac09 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 8 Mar 2016 13:31:44 +1300 Subject: [PATCH] CRM-18180 allow non-standard table names in logging reports --- CRM/Logging/Schema.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 810f047f6d..cd3f512164 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -154,6 +154,7 @@ AND TABLE_NAME LIKE 'civicrm_%' } CRM_Utils_Hook::alterLogTables($this->logTableSpec); $this->tables = array_keys($this->logTableSpec); + $nonStandardTableNameString = $this->getNonStandardTableNameFilterString(); if (defined('CIVICRM_LOGGING_DSN')) { $dsn = DB::parseDSN(CIVICRM_LOGGING_DSN); @@ -170,7 +171,7 @@ SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{$this->db}' AND TABLE_TYPE = 'BASE TABLE' -AND TABLE_NAME LIKE 'log_civicrm_%' +AND (TABLE_NAME LIKE 'log_civicrm_%' $nonStandardTableNameString ) "); while ($dao->fetch()) { $log = $dao->TABLE_NAME; @@ -676,6 +677,27 @@ COLS; return !empty($this->logs); } + /** + * Get an sql clause to find the names of any log tables that do not match the normal pattern. + * + * Most tables are civicrm_xxx with the log table being log_civicrm_xxx + * However, they don't have to match this pattern (e.g when defined by hook) so find the + * anomalies and return a filter string to include them. + * + * @return string + */ + public function getNonStandardTableNameFilterString() { + $nonStandardTableNames = preg_grep('/^civicrm_/', $this->tables, PREG_GREP_INVERT); + if (empty($nonStandardTableNames)) { + return ''; + } + $nonStandardTableLogs = array(); + foreach ($nonStandardTableNames as $nonStandardTableName) { + $nonStandardTableLogs[] = "'log_{$nonStandardTableName}'"; + } + return " OR TABLE_NAME IN (" . implode(',', $nonStandardTableLogs) . ")"; + } + /** * Predicate whether the logging triggers are in place. */ -- 2.25.1