Index: branches/RC/core/install/upgrades.php =================================================================== diff -u -r10832 -r11120 --- branches/RC/core/install/upgrades.php (.../upgrades.php) (revision 10832) +++ branches/RC/core/install/upgrades.php (.../upgrades.php) (revision 11120) @@ -204,6 +204,51 @@ } } + /** + * Removes duplicate phrases (created during proj-base and in-portal shared installation) + * + * @param string $mode when called mode {before, after) + */ + function Upgrade_4_3_9($mode) + { + if ($mode == 'after') { + $id_field = $this->Application->getUnitOption('phrases', 'IDField'); + $table_name = $this->Application->getUnitOption('phrases', 'TableName'); + + $sql = 'SELECT LanguageId, Phrase, MIN(LastChanged) AS LastChanged, COUNT(*) AS DupeCount + FROM ' . $table_name . ' + GROUP BY LanguageId, Phrase + HAVING COUNT(*) > 1'; + $duplicate_phrases = $this->Conn->Query($sql); + + foreach ($duplicate_phrases as $phrase_record) { + // 1. keep phrase, that was added first, because it is selected in PhrasesCache::LoadPhraseByLabel + $where_clause = Array ( + 'LanguageId = ' . $phrase_record['LanguageId'], + 'Phrase = ' . $this->Conn->qstr($phrase_record['Phrase']), + 'LastChanged' . ' = ' . $phrase_record['LastChanged'], + ); + + $sql = 'SELECT ' . $id_field . ' + FROM ' . $table_name . ' + WHERE (' . implode(') AND (', $where_clause) . ')'; + $phrase_id = $this->Conn->GetOne($sql); + + // 2. delete all other duplicates + $where_clause = Array ( + 'LanguageId = ' . $phrase_record['LanguageId'], + 'Phrase = ' . $this->Conn->qstr($phrase_record['Phrase']), + $id_field . ' <> ' . $phrase_id, + ); + + $sql = 'DELETE FROM ' . $table_name . ' + WHERE (' . implode(') AND (', $where_clause) . ')'; + $this->Conn->Query($sql); + } + + } + } + } ?> \ No newline at end of file