Index: branches/5.2.x/core/units/helpers/language_import_helper.php =================================================================== diff -u -N -r15239 -r15327 --- branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 15239) +++ branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 15327) @@ -1,6 +1,6 @@ _updateEventsCache(); } - $this->_initImportTables(); - $phrase_types = explode('|', substr($phrase_types, 1, -1) ); // $module_ids = explode('|', substr($module_ids, 1, -1) ); @@ -229,7 +227,8 @@ $phrase_types = explode('|', substr($phrase_types, 1, -1) ); $module_ids = explode('|', substr($module_ids, 1, -1) ); - $ret = '' . "\n"; + $ret = '' . "\n"; + $ret .= '' . "\n"; $export_fields = $this->_getExportFields(); @@ -780,8 +779,6 @@ } foreach ($languages as $language_node) { - $language_id = false; - $fields_hash = Array ( 'PackName' => (string)$language_node['PackName'], 'LocalName' => (string)$language_node['PackName'], @@ -804,29 +801,10 @@ /* @var $sub_node SimpleXMLElement */ if ( in_array($sub_node->getName(), $container_nodes) ) { - // PHP 5.3 version would be: !$sub_node->count() - if ( !count($sub_node->children()) ) { continue; - } - - if ( !$language_id ) { - $language_id = $this->_processLanguage($fields_hash); - } } switch ($sub_node->getName()) { - case 'PHRASES': - $this->_processPhrases($sub_node, $language_id, $fields_hash['Encoding']); - break; - - case 'EVENTS': - $this->_processEvents($sub_node, $language_id, $fields_hash['Encoding']); - break; - - case 'COUNTRIES': - $this->_processCountries($sub_node, $language_id, $fields_hash['Encoding']); - break; - case 'REPLACEMENTS': // added since v2 $replacements = (string)$sub_node; @@ -851,10 +829,60 @@ break; } } + + $this->_processLanguage($fields_hash); } + + $ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + + // create ML columns for new languages + $ml_helper->resetState(); + $ml_helper->massCreateFields(); + + // create temp tables after new language columns were added + $this->_initImportTables(); } /** + * Processes parsed XML + * + * @param SimpleXMLElement $languages + */ + function _processLanguageData($languages) + { + foreach ($languages as $language_node) { + $encoding = (string)$language_node['Encoding']; + $language_id = $this->_languages[kUtil::crc32((string)$language_node['PackName'])]; + + $container_nodes = Array ('PHRASES', 'EVENTS', 'COUNTRIES'); + + foreach ($language_node as $sub_node) { + /* @var $sub_node SimpleXMLElement */ + + if ( !in_array($sub_node->getName(), $container_nodes) || !count($sub_node->children()) ) { + // PHP 5.3 version would be: !$sub_node->count() + continue; + } + + switch ($sub_node->getName()) { + case 'PHRASES': + $this->_processPhrases($sub_node, $language_id, $encoding); + break; + + case 'EVENTS': + $this->_processEvents($sub_node, $language_id, $encoding); + break; + + case 'COUNTRIES': + $this->_processCountries($sub_node, $language_id, $encoding); + break; + } + } + } + } + + /** * Decodes e-mail template design from language pack * * @param Array $fields_hash @@ -912,19 +940,21 @@ $column_translation = base64_decode($column_translation); } - if ( array_key_exists($phrase_key, $other_translations) ) { - $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; + if ( !array_key_exists($phrase_key, $other_translations) ) { + // ensure translation in every language to make same column count in every insert + $other_translations[$phrase_key] = Array (); + + foreach ($this->_languages as $other_language_id) { + $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'] = ''; + } } - else { - $other_translations[$phrase_key] = Array ( - 'l' . $language_id . '_Translation' => $translation, - 'l' . $language_id . '_HintTranslation' => $hint_translation, - 'l' . $language_id . '_ColumnTranslation' => $column_translation, - ); - } + $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; + $fields_hash = array_merge($fields_hash, $other_translations[$phrase_key]); $this->Conn->doInsert($fields_hash, $this->_tables['phrases'], 'REPLACE', false); } @@ -981,19 +1011,21 @@ $parsed = $email_message_helper->parseTemplate($template, $message_type); } - if ( array_key_exists($event_id, $other_translations) ) { - $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']; + if ( !array_key_exists($event_id, $other_translations) ) { + // ensure translation in every language to make same column count in every insert + $other_translations[$event_id] = Array (); + + foreach ($this->_languages as $other_language_id) { + $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'] = ''; + } } - else { - $other_translations[$event_id] = Array ( - 'l' . $language_id . '_Subject' => $parsed['Subject'], - 'l' . $language_id . '_HtmlBody' => $parsed['HtmlBody'], - 'l' . $language_id . '_PlainTextBody' => $parsed['PlainTextBody'], - ); - } + $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']; + if ( $parsed['Headers'] ) { $other_translations[$event_id]['Headers'] = $parsed['Headers']; } @@ -1051,13 +1083,18 @@ $fields_hash = Array ('CountryStateId' => $country_state_id); - if ( array_key_exists($country_state_id, $other_translations) ) { - $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation; + + if ( !array_key_exists($country_state_id, $other_translations) ) { + // ensure translation in every language to make same column count in every insert + $other_translations[$country_state_id] = Array (); + + foreach ($this->_languages as $other_language_id) { + $other_translations[$country_state_id]['l' . $other_language_id . '_Name'] = ''; + } } - else { - $other_translations[$country_state_id] = Array ('l' . $language_id . '_Name' => $translation); - } + $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation; + $fields_hash = array_merge($fields_hash, $other_translations[$country_state_id]); $this->Conn->doInsert($fields_hash, $this->_tables['country-state'], 'REPLACE', false); @@ -1111,7 +1148,7 @@ // 4. collect ID of every processed language if (!in_array($language_id, $this->_languages)) { - $this->_languages[] = $language_id; + $this->_languages[kUtil::crc32($fields_hash['PackName'])] = $language_id; } return $language_id;