From c587fcae1cc3cc828cf252b5aabb9500db01b0f5 Mon Sep 17 00:00:00 2001 From: Mathieu Lu Date: Tue, 28 Nov 2023 08:26:11 -0500 Subject: [PATCH] Fix support for DB logging with multilingual --- CRM/Core/I18n/Schema.php | 17 +++++++++++++++-- CRM/Logging/Schema.php | 4 ---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CRM/Core/I18n/Schema.php b/CRM/Core/I18n/Schema.php index e000811f52..83b5356495 100644 --- a/CRM/Core/I18n/Schema.php +++ b/CRM/Core/I18n/Schema.php @@ -303,9 +303,15 @@ class CRM_Core_I18n_Schema { } // rebuild views + $logging_enabled = \Civi::settings()->get('logging'); + foreach ($locales as $locale) { foreach ($tables as $table) { $queries[] = self::createViewQuery($locale, $table, $dao, $class, $isUpgradeMode); + + if ($logging_enabled) { + $queries[] = self::createViewQuery($locale, 'log_' . $table, $dao, $class, $isUpgradeMode); + } } } @@ -459,9 +465,16 @@ class CRM_Core_I18n_Schema { $cols = []; $tableCols = []; $dao->query("DESCRIBE {$table}", FALSE); + + $lookup_table = $table; + + if (substr($table, 0, 4) == 'log_') { + $lookup_table = substr($table, 4); + } + while ($dao->fetch()) { // view non-internationalized columns directly - if (!array_key_exists($dao->Field, $columns[$table]) && + if (!in_array($dao->Field, array_keys($columns[$lookup_table])) && !preg_match('/_[a-z][a-z]_[A-Z][A-Z]$/', $dao->Field) ) { $cols[] = '`' . $dao->Field . '`'; @@ -469,7 +482,7 @@ class CRM_Core_I18n_Schema { $tableCols[] = $dao->Field; } // view internationalized columns through an alias - foreach ($columns[$table] as $column => $_) { + foreach ($columns[$lookup_table] as $column => $_) { if (!$isUpgradeMode) { $cols[] = "`{$column}_{$locale}` `{$column}`"; } diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 70cc37c30a..845f61d9d9 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -81,10 +81,6 @@ class CRM_Logging_Schema { if (!(CRM_Core_DAO::checkTriggerViewPermission(FALSE)) && $value) { throw new CRM_Core_Exception(ts("In order to use this functionality, the installation's database user must have privileges to create triggers and views (if binary logging is enabled – this means the SUPER privilege). This install does not have the required privilege(s) enabled.")); } - // dev/core#1812 Disable logging in a multilingual environment. - if (CRM_Core_I18n::isMultilingual() && $value) { - throw new CRM_Core_Exception(ts("Logging is not supported in a multilingual environment!")); - } return TRUE; } -- 2.25.1