From b37b9bef9346558e75b6f7f8d2e383f2eb96f122 Mon Sep 17 00:00:00 2001 From: Johan Vervloet Date: Thu, 24 Nov 2016 10:41:05 +0100 Subject: [PATCH] CRM-19683 Can now change word replacements if you have more than one language. --- CRM/Admin/Form/WordReplacements.php | 3 ++- CRM/Core/BAO/WordReplacement.php | 37 +++++++++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/CRM/Admin/Form/WordReplacements.php b/CRM/Admin/Form/WordReplacements.php index 0a5fabdb0c..a130f505d2 100644 --- a/CRM/Admin/Form/WordReplacements.php +++ b/CRM/Admin/Form/WordReplacements.php @@ -226,7 +226,8 @@ class CRM_Admin_Form_WordReplacements extends CRM_Core_Form { CRM_Core_BAO_WordReplacement::setLocaleCustomStrings($config->lcMessages, $overrides); // This controller was originally written to CRUD $config->locale_custom_strings, - // but that's no longer the canonical store. Sync changes to canonical store. + // but that's no longer the canonical store. Sync changes to canonical store + // (civicrm_word_replacement table in the database). // This is inefficient - at some point, we should rewrite this UI. CRM_Core_BAO_WordReplacement::rebuildWordReplacementTable(); diff --git a/CRM/Core/BAO/WordReplacement.php b/CRM/Core/BAO/WordReplacement.php index 6f880fca6a..a76d5a583e 100644 --- a/CRM/Core/BAO/WordReplacement.php +++ b/CRM/Core/BAO/WordReplacement.php @@ -205,8 +205,9 @@ WHERE domain_id = %1 /** * Get word replacements for the api. * - * Get all the word-replacements stored in config-arrays - * and convert them to params for the WordReplacement.create API. + * Get all the word-replacements stored in config-arrays for the + * configured language, and convert them to params for the + * WordReplacement.create API. * * Note: This function is duplicated in CRM_Core_BAO_WordReplacement and * CRM_Upgrade_Incremental_php_FourFour to ensure that the incremental upgrade @@ -222,6 +223,11 @@ WHERE domain_id = %1 * @see CRM_Core_BAO_WordReplacement::convertConfigArraysToAPIParams */ public static function getConfigArraysAsAPIParams($rebuildEach) { + $settingsResult = civicrm_api3('Setting', 'get', array( + 'return' => 'lcMessages', + )); + $lang = CRM_Utils_Array::first($settingsResult['values'])['lcMessages']; + $wordReplacementCreateParams = array(); // get all domains $result = civicrm_api3('domain', 'get', array( @@ -236,19 +242,20 @@ WHERE domain_id = %1 $localeCustomArray = unserialize($value["locale_custom_strings"]); if (!empty($localeCustomArray)) { $wordMatchArray = array(); - // Traverse Language array - foreach ($localeCustomArray as $localCustomData) { - // Traverse status array "enabled" "disabled" - foreach ($localCustomData as $status => $matchTypes) { - $params["is_active"] = ($status == "enabled") ? TRUE : FALSE; - // Traverse Match Type array "wildcardMatch" "exactMatch" - foreach ($matchTypes as $matchType => $words) { - $params["match_type"] = $matchType; - foreach ($words as $word => $replace) { - $params["find_word"] = $word; - $params["replace_word"] = $replace; - $wordReplacementCreateParams[] = $params; - } + // Only return the replacement strings of the current language, + // otherwise some replacements will be duplicated, which will + // lead to undesired results, like CRM-19683. + $localCustomData = $localeCustomArray[$lang]; + // Traverse status array "enabled" "disabled" + foreach ($localCustomData as $status => $matchTypes) { + $params["is_active"] = ($status == "enabled") ? TRUE : FALSE; + // Traverse Match Type array "wildcardMatch" "exactMatch" + foreach ($matchTypes as $matchType => $words) { + $params["match_type"] = $matchType; + foreach ($words as $word => $replace) { + $params["find_word"] = $word; + $params["replace_word"] = $replace; + $wordReplacementCreateParams[] = $params; } } } -- 2.25.1