Index: branches/5.3.x/core/units/helpers/language_import_helper.php =================================================================== diff -u -N -r15483 -r15584 --- branches/5.3.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 15483) +++ branches/5.3.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 15584) @@ -1,6 +1,6 @@ _importOptions & $option_bit) == $option_bit; + } + + /** + * Sets import option + * + * @param int $option_bit + * @param bool $enabled + * @return void + * @access public + */ + public function setOption($option_bit, $enabled = true) + { + if ( $enabled ) { + $this->_importOptions |= $option_bit; + } + else { + $this->_importOptions = $this->_importOptions & ~$option_bit; + } + } + + /** * Performs import of given language pack (former Parse method) * * @param string $filename * @param string $phrase_types * @param Array $module_ids - * @param int $import_mode * @return bool */ - function performImport($filename, $phrase_types, $module_ids, $import_mode = LANG_SKIP_EXISTING) + function performImport($filename, $phrase_types, $module_ids) { // define the XML parsing routines/functions to call based on the handler path if (!file_exists($filename) || !$phrase_types /*|| !$module_ids*/) { @@ -184,14 +220,13 @@ // $module_ids = explode('|', substr($module_ids, 1, -1) ); $this->phrase_types_allowed = array_flip($phrase_types); - $this->import_mode = $import_mode; $this->_parseXML($filename); // copy data from temp tables to live foreach ($this->_languages as $language_id) { - $this->_performUpgrade($language_id, 'phrases', 'PhraseKey', Array ('l%s_Translation', 'l%s_HintTranslation', 'l%s_ColumnTranslation', 'PhraseType')); - $this->_performUpgrade($language_id, 'emailevents', 'EventId', Array ('l%s_Subject', 'Headers', 'l%s_HtmlBody', 'l%s_PlainTextBody')); + $this->_performUpgrade($language_id, 'phrases', 'PhraseKey', Array ('l%s_Translation', 'l%s_HintTranslation', 'l%s_ColumnTranslation', 'l%s_TranslateFrom', 'PhraseType')); + $this->_performUpgrade($language_id, 'emailevents', 'EventId', Array ('l%s_Subject', 'Headers', 'l%s_HtmlBody', 'l%s_PlainTextBody', 'l%s_TranslateFrom')); $this->_performUpgrade($language_id, 'country-state', 'CountryStateId', Array ('l%s_Name')); } @@ -535,15 +570,15 @@ $live_records = $this->_getTableData($language_id, $prefix, $unique_field, $data_fields[0], false); $temp_records = $this->_getTableData($language_id, $prefix, $unique_field, $data_fields[0], true); - if (!$temp_records) { + if ( !$temp_records ) { // no data for given language - return ; + return; } // perform insert for records, that are missing in live table $to_insert = array_diff($temp_records, $live_records); - if ($to_insert) { + if ( $to_insert ) { $to_insert = $this->Conn->qstrArray($to_insert); $sql = 'INSERT INTO ' . $this->Application->getUnitOption($prefix, 'TableName') . ' @@ -559,7 +594,7 @@ // perform update for records, that are present in live table $to_update = array_diff($temp_records, $to_insert); - if ($to_update) { + if ( $to_update ) { $to_update = $this->Conn->qstrArray($to_update); $sql = 'UPDATE ' . $this->Application->getUnitOption($prefix, 'TableName') . ' live @@ -582,19 +617,19 @@ $unique_field . ' IN (' . implode(',', $to_update) . ')', ); - if ($this->import_mode == LANG_SKIP_EXISTING) { + if ( !$this->hasOption(self::OVERWRITE_EXISTING) ) { // empty OR not set $data_field = sprintf($data_fields[0], $language_id); $where_clause[] = '(' . $data_field . ' = "") OR (' . $data_field . ' IS NULL)'; } - if ($where_clause) { + if ( $where_clause ) { $sql .= "\n" . 'WHERE (' . implode(') AND (', $where_clause) . ')'; } $this->Conn->Query($sql); - if ($this->Conn->getAffectedRows() > 0) { + if ( $this->Conn->getAffectedRows() > 0 ) { // existing records were updated $this->changedPrefixes[] = $prefix; } @@ -914,6 +949,9 @@ { static $other_translations = Array (); + $primary_language = $this->Application->GetDefaultLanguageId(); + $translate_from = $this->hasOption(self::SYNC_ADDED) || $primary_language == $language_id ? 0 : $primary_language; + if ( $this->Application->isDebugMode() ) { $this->Application->Debugger->profileStart('L[' . $language_id . ']P', 'Language: ' . $language_id . '; Phrases Import'); } @@ -951,12 +989,14 @@ $other_translations[$phrase_key]['l' . $other_language_id . '_Translation'] = ''; $other_translations[$phrase_key]['l' . $other_language_id . '_HintTranslation'] = ''; $other_translations[$phrase_key]['l' . $other_language_id . '_ColumnTranslation'] = ''; + $other_translations[$phrase_key]['l' . $other_language_id . '_TranslateFrom'] = 0; } } $other_translations[$phrase_key]['l' . $language_id . '_Translation'] = $translation; $other_translations[$phrase_key]['l' . $language_id . '_HintTranslation'] = $hint_translation; $other_translations[$phrase_key]['l' . $language_id . '_ColumnTranslation'] = $column_translation; + $other_translations[$phrase_key]['l' . $language_id . '_TranslateFrom'] = $translate_from; $fields_hash = array_merge($fields_hash, $other_translations[$phrase_key]); $this->Conn->doInsert($fields_hash, $this->_tables['phrases'], 'REPLACE', false); @@ -981,6 +1021,9 @@ { static $other_translations = Array (); + $primary_language = $this->Application->GetDefaultLanguageId(); + $translate_from = $this->hasOption(self::SYNC_ADDED) || $primary_language == $language_id ? 0 : $primary_language; + if ( $this->Application->isDebugMode() ) { $this->Application->Debugger->profileStart('L[' . $language_id . ']E', 'Language: ' . $language_id . '; Events Import'); } @@ -1022,12 +1065,14 @@ $other_translations[$event_id]['l' . $other_language_id . '_Subject'] = ''; $other_translations[$event_id]['l' . $other_language_id . '_HtmlBody'] = ''; $other_translations[$event_id]['l' . $other_language_id . '_PlainTextBody'] = ''; + $other_translations[$event_id]['l' . $other_language_id . '_TranslateFrom'] = 0; } } $other_translations[$event_id]['l' . $language_id . '_Subject'] = $parsed['Subject']; $other_translations[$event_id]['l' . $language_id . '_HtmlBody'] = $parsed['HtmlBody']; $other_translations[$event_id]['l' . $language_id . '_PlainTextBody'] = $parsed['PlainTextBody']; + $other_translations[$event_id]['l' . $language_id . '_TranslateFrom'] = $translate_from; if ( $parsed['Headers'] ) { $other_translations[$event_id]['Headers'] = $parsed['Headers']; @@ -1124,11 +1169,11 @@ WHERE PackName = ' . $this->Conn->qstr($fields_hash['PackName']); $language_id = $this->Conn->GetOne($sql); - if ($language_id) { + if ( $language_id ) { // 2. language found -> update, when allowed $this->lang_object->Load($language_id); - if ($this->import_mode == LANG_OVERWRITE_EXISTING) { + if ( $this->hasOption(self::OVERWRITE_EXISTING) ) { // update live language record based on data from xml $this->lang_object->SetFieldsFromHash($fields_hash); $this->lang_object->Update(); @@ -1139,18 +1184,18 @@ $this->lang_object->SetFieldsFromHash($fields_hash); $this->lang_object->SetDBField('Enabled', STATUS_ACTIVE); - if ($this->lang_object->Create()) { + if ( $this->lang_object->Create() ) { $language_id = $this->lang_object->GetID(); - if (defined('IS_INSTALL') && IS_INSTALL) { + if ( defined('IS_INSTALL') && IS_INSTALL ) { // language created during install becomes admin interface language $this->lang_object->setPrimary(true, true); } } } // 4. collect ID of every processed language - if (!in_array($language_id, $this->_languages)) { + if ( !in_array($language_id, $this->_languages) ) { $this->_languages[kUtil::crc32($fields_hash['PackName'])] = $language_id; }