localeCustomStrings has a pretty w.e.i.r.d. lifecycle (involving table `civicrm_word_replacements`
and column `civicrm_domain.locale_cusotm_Strings`). This commit does not unweird it, but the
weirdness no longer involves special-case logic on `CRM_Core_Config*` -- all the weirdness is
concentrated in `CRM_Core_BAO_WordReplacements` and `CRM_Admin_Form_WordReplacements`.
* @return array
*/
public function setDefaultValues() {
- if ($this->_defaults !== NULL) {
+ if (!empty($this->_defaults)) {
return $this->_defaults;
}
$config = CRM_Core_Config::singleton();
- $values = $config->localeCustomStrings[$config->lcMessages];
+ $values = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($config->lcMessages);
$i = 1;
$enableDisable = array(
}
}
- $name = $this->_stringName = "custom_string_override_{$config->lcMessages}";
- if (isset($config->$name) &&
- is_array($config->$name)
- ) {
- $this->_numStrings = 1;
- foreach ($config->$name as $old => $newValues) {
- $this->_numStrings++;
- $this->_numStrings += 9;
- }
- }
- else {
- $this->_numStrings = 10;
- }
-
return $this->_defaults;
}
*/
public function buildQuickForm() {
$config = CRM_Core_Config::singleton();
- $values = $config->localeCustomStrings[$config->lcMessages];
+ $values = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($config->lcMessages);
//CRM-14179
$instances = 0;
);
$config = CRM_Core_Config::singleton();
+ CRM_Core_BAO_WordReplacement::setLocaleCustomStrings($config->lcMessages, $overrides);
- $domain = new CRM_Core_DAO_Domain();
- $domain->find(TRUE);
-
- if ($domain->locales && $config->localeCustomStrings) {
- // for multilingual
- $addReplacements = $config->localeCustomStrings;
- $addReplacements[$config->lcMessages] = $overrides;
- $stringOverride = serialize($addReplacements);
- }
- else {
- // for single language
- $stringOverride = serialize(array($config->lcMessages => $overrides));
- }
-
- $params = array('locale_custom_strings' => $stringOverride);
- $id = CRM_Core_Config::domainID();
-
- $wordReplacementSettings = CRM_Core_BAO_Domain::edit($params, $id);
-
- if ($wordReplacementSettings) {
- // This controller was originally written to CRUD $config->locale_custom_strings,
- // but that's no longer the canonical store. Sync changes to canonical store.
- // This is inefficient - at some point, we should rewrite this UI.
- CRM_Core_BAO_WordReplacement::rebuildWordReplacementTable();
-
- CRM_Core_Session::setStatus("", ts("Settings Saved"), "success");
- CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/options/wordreplacements',
- "reset=1"
- ));
- }
+ // This controller was originally written to CRUD $config->locale_custom_strings,
+ // but that's no longer the canonical store. Sync changes to canonical store.
+ // This is inefficient - at some point, we should rewrite this UI.
+ CRM_Core_BAO_WordReplacement::rebuildWordReplacementTable();
+
+ CRM_Core_Session::setStatus("", ts("Settings Saved"), "success");
+ CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/options/wordreplacements',
+ "reset=1"
+ ));
}
}
self::formatParams($params, $values);
}
- // CRM-6151
- if (isset($params['localeCustomStrings']) &&
- is_array($params['localeCustomStrings'])
- ) {
- $domain->locale_custom_strings = serialize($params['localeCustomStrings']);
- }
-
// unset any of the variables we read from file that should not be stored in the database
// the username and certpath are stored flat with _test and _live
// check CRM-1470
if (CRM_Core_Config::isUpgradeMode()) {
$domain->selectAdd('config_backend');
}
- elseif (CRM_Utils_Array::value($urlVar, $_GET) == 'admin/modules/list/confirm') {
- $domain->selectAdd('config_backend', 'locales');
- }
else {
- $domain->selectAdd('config_backend, locales, locale_custom_strings');
+ $domain->selectAdd('config_backend, locales');
}
$domain->id = CRM_Core_Config::domainID();
}
}
- // check if there are any locale strings
- if ($domain->locale_custom_strings) {
- $defaults['localeCustomStrings'] = unserialize($domain->locale_custom_strings);
- }
- else {
- $defaults['localeCustomStrings'] = NULL;
- }
-
// are we in a multi-language setup?
$multiLang = $domain->locales ? TRUE : FALSE;
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
- if ($domain->locales && $config->localeCustomStrings) {
- // for multilingual
- $addReplacements = $config->localeCustomStrings;
- $addReplacements[$config->lcMessages] = $overrides;
- $stringOverride = $addReplacements;
- }
- else {
- // for single language
- $stringOverride = array($config->lcMessages => $overrides);
- }
+ // So. Weird. Some bizarre/probably-broken multi-lingual thing where
+ // data isn't really stored in civicrm_word_replacements. Probably
+ // shouldn't exist.
+ $stringOverride = self::_getLocaleCustomStrings($id);
+ $stringOverride[$config->lcMessages] = $overrides;
return $stringOverride;
}
*/
public static function rebuild($clearCaches = TRUE) {
$id = CRM_Core_Config::domainID();
- $stringOverride = self::getAllAsConfigArray($id);
- $params = array('locale_custom_strings' => serialize($stringOverride));
- $wordReplacementSettings = CRM_Core_BAO_Domain::edit($params, $id);
- if ($wordReplacementSettings) {
- CRM_Core_Config::singleton()->localeCustomStrings = $stringOverride;
-
- // Partially mitigate the inefficiency introduced in CRM-13187 by doing this conditionally
- if ($clearCaches) {
- // Reset navigation
- CRM_Core_BAO_Navigation::resetNavigation();
- // Clear js localization
- CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode();
- }
+ self::_setLocaleCustomStrings($id, self::getAllAsConfigArray($id));
- return TRUE;
+ // Partially mitigate the inefficiency introduced in CRM-13187 by doing this conditionally
+ if ($clearCaches) {
+ // Reset navigation
+ CRM_Core_BAO_Navigation::resetNavigation();
+ // Clear js localization
+ CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode();
}
- return FALSE;
+ return TRUE;
}
/**
CRM_Core_BAO_WordReplacement::rebuild();
}
+ /**
+ * Get WordReplacements for a locale.
+ *
+ * @param string $locale
+ * @return array
+ * List of word replacements (enabled/disabled) for the given locale.
+ */
+ public static function getLocaleCustomStrings($locale, $domainId = NULL) {
+ if ($domainId === NULL) {
+ $domainId = CRM_Core_Config::domainID();
+ }
+
+ return CRM_Utils_Array::value($locale, self::_getLocaleCustomStrings($domainId));
+ }
+
+ private static function _getLocaleCustomStrings($domainId) {
+ // TODO: Would it be worthwhile using memcache here?
+ $domain = CRM_Core_DAO::executeQuery('SELECT locale_custom_strings FROM civicrm_domain WHERE id = %1', array(
+ 1 => array($domainId, 'Integer'),
+ ));
+ while ($domain->fetch()) {
+ return empty($domain->locale_custom_strings) ? array() : unserialize($domain->locale_custom_strings);
+ }
+ }
+
+ public static function setLocaleCustomStrings($locale, $values, $domainId = NULL) {
+ if ($domainId === NULL) {
+ $domainId = CRM_Core_Config::domainID();
+ }
+
+ $lcs = self::_getLocaleCustomStrings($domainId);
+ $lcs[$locale] = $values;
+
+ self::_setLocaleCustomStrings($domainId, $lcs);
+ }
+
+ /**
+ * @param $domainId
+ * @param $lcs
+ */
+ private static function _setLocaleCustomStrings($domainId, $lcs) {
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_domain SET locale_custom_strings = %1 WHERE id = %2", array(
+ 1 => array(serialize($lcs), 'String'),
+ 2 => array($domainId, 'Integer'),
+ ));
+ }
+
}
public $maxFileSize = 2;
- /**
- * The custom locale strings. Note that these locale strings are stored
- * in a separate column in civicrm_domain
- * @var array
- */
- public $localeCustomStrings = NULL;
-
/**
* Map Provider
*
// do all wildcard translations first
$config = CRM_Core_Config::singleton();
- $stringTable = CRM_Utils_Array::value(
- $config->lcMessages,
- $config->localeCustomStrings
- );
+ if (!isset(Civi::$statics[__CLASS__][$config->lcMessages])) {
+ if ($config->dsn && !CRM_Core_Config::isUpgradeMode()) {
+ Civi::$statics[__CLASS__][$config->lcMessages] = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($config->lcMessages);
+ }
+ else {
+ Civi::$statics[__CLASS__][$config->lcMessages] = array();
+ }
+ }
+ $stringTable = Civi::$statics[__CLASS__][$config->lcMessages];
$exactMatch = FALSE;
if (isset($stringTable['enabled']['exactMatch'])) {