From: Tim Otten Date: Mon, 10 Mar 2014 03:34:20 +0000 (-0700) Subject: CRM-14224 - Upgrade WordReplacements: X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=52592398093ab24e4357cad4289dbe738e4d3fe8;p=civicrm-core.git CRM-14224 - Upgrade WordReplacements: * Display a pre-upgrade message if any WordReplacements are too long * Log old/long WordReplacements * Don't migrate WordRepalcements which are too long --- diff --git a/CRM/Upgrade/Incremental/php/FourFour.php b/CRM/Upgrade/Incremental/php/FourFour.php index bb027fdafa..ba26bcf811 100644 --- a/CRM/Upgrade/Incremental/php/FourFour.php +++ b/CRM/Upgrade/Incremental/php/FourFour.php @@ -34,6 +34,8 @@ class CRM_Upgrade_Incremental_php_FourFour { const BATCH_SIZE = 5000; + const MAX_WORD_REPLACEMENT_SIZE = 255; + function verifyPreDBstate(&$errors) { return TRUE; } @@ -49,6 +51,20 @@ class CRM_Upgrade_Incremental_php_FourFour { * @return void */ function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { + if ($rev == '4.4.beta1') { + $apiCalls = self::getConfigArraysAsAPIParams(FALSE); + $oversizedEntries = 0; + foreach ($apiCalls as $params) { + if (!self::isValidWordReplacement($params)) { + $oversizedEntries++; + } + } + if ($oversizedEntries > 0) { + $preUpgradeMessage .= '
' . ts("WARNING: There are %1 word-replacement entries which will not be valid in v4.4+ (eg with over 255 characters). They will be dropped during upgrade. For details, consult the CiviCRM log.", array( + 1 => $oversizedEntries + )); + } + } } /** @@ -541,7 +557,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` ( public static function rebuildWordReplacementTable() { civicrm_api3('word_replacement', 'replace', array( 'options' => array('match' => array('domain_id', 'find_word')), - 'values' => self::getConfigArraysAsAPIParams(FALSE), + 'values' => array_filter(self::getConfigArraysAsAPIParams(FALSE), array(__CLASS__, 'isValidWordReplacement')), )); CRM_Core_BAO_WordReplacement::rebuild(); } @@ -578,4 +594,16 @@ CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` ( return TRUE; } + + /** + * @param array $params + * @return bool TRUE if $params is valid + */ + static function isValidWordReplacement($params) { + $result = strlen($params['find_word']) <= self::MAX_WORD_REPLACEMENT_SIZE && strlen($params['replace_word']) > self::MAX_WORD_REPLACEMENT_SIZE; + if (!$result) { + CRM_Core_Error::debug_var('invalidWordReplacement', $params); + } + return $result; + } }