Index: branches/5.1.x/core/install/upgrades.php =================================================================== diff -u -N -r14327 -r14537 --- branches/5.1.x/core/install/upgrades.php (.../upgrades.php) (revision 14327) +++ branches/5.1.x/core/install/upgrades.php (.../upgrades.php) (revision 14537) @@ -1,6 +1,6 @@ Conn->Query($sql); } } + + /** + * Update to 5.1.3; Merges column and field phrases + * + * @param string $mode when called mode {before, after) + */ + function Upgrade_5_1_3($mode) + { + if ($mode != 'after') { + return ; + } + + $sql = 'SELECT * + FROM ' . TABLE_PREFIX . 'Phrase + WHERE PhraseKey LIKE "LA_COL_%"'; + $column_phrases = $this->Conn->Query($sql, 'PhraseKey'); + + $sql = 'SELECT * + FROM ' . TABLE_PREFIX . 'Phrase + WHERE PhraseKey LIKE "LA_FLD_%"'; + $field_phrases = $this->Conn->Query($sql, 'PhraseKey'); + + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + + $ml_helper->createFields('phrases'); + + $delete_ids = Array (); + $language_count = $ml_helper->getLanguageCount(); + + foreach ($column_phrases as $phrase_key => $phrase_info) { + $field_phrase_key = 'LA_FLD_' . substr($phrase_key, 7); + + if ( !isset($field_phrases[$field_phrase_key]) ) { + continue; + } + + $fields_hash = Array (); + + // copy column phrase main translation into field phrase column translation + for ($i = 1; $i <= $language_count; $i++) { + if ( !$ml_helper->LanguageFound($i) ) { + continue; + } + + $fields_hash['l' . $i . '_ColumnTranslation'] = $phrase_info['l' . $i . '_Translation']; + } + + $delete_ids[] = $phrase_info['PhraseId']; + $this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'Phrase', 'PhraseId = ' . $field_phrases[$field_phrase_key]['PhraseId']); + } + + // delete all column phrases, that were absorbed by field phrases + if ( $delete_ids ) { + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Phrase + WHERE PhraseId IN (' . implode(',', $delete_ids) . ')'; + $this->Conn->Query($sql); + + + $sql = 'DELETE FROM ' . TABLE_PREFIX . 'PhraseCache'; + $this->Conn->Query($sql); + } + } } \ No newline at end of file