Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-19683: Can now change word replacements if you have more than one language #9446

Merged
merged 2 commits into from
Nov 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CRM/Admin/Form/WordReplacements.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ public function postProcess() {
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();

Expand Down
38 changes: 23 additions & 15 deletions CRM/Core/BAO/WordReplacement.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ public static function rebuild($clearCaches = TRUE) {
/**
* 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
Expand All @@ -222,6 +223,12 @@ public static function rebuild($clearCaches = TRUE) {
* @see CRM_Core_BAO_WordReplacement::convertConfigArraysToAPIParams
*/
public static function getConfigArraysAsAPIParams($rebuildEach) {
$settingsResult = civicrm_api3('Setting', 'get', array(
'return' => 'lcMessages',
));
$returnValues = CRM_Utils_Array::first($settingsResult['values']);
$lang = $returnValues['lcMessages'];

$wordReplacementCreateParams = array();
// get all domains
$result = civicrm_api3('domain', 'get', array(
Expand All @@ -236,19 +243,20 @@ public static function getConfigArraysAsAPIParams($rebuildEach) {
$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;
}
}
}
Expand Down