Index: branches/RC/core/units/languages/languages_event_handler.php =================================================================== diff -u -r11495 -r11538 --- branches/RC/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 11495) +++ branches/RC/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 11538) @@ -13,7 +13,6 @@ 'OnChangeLanguage' => Array('self' => true), 'OnSetPrimary' => Array('self' => 'advanced:set_primary|add|edit'), 'OnImportLanguage' => Array('self' => 'advanced:import'), - 'OnImportProgress' => Array('self' => 'advanced:import'), 'OnExportLanguage' => Array('self' => 'advanced:export'), 'OnExportProgress' => Array('self' => 'advanced:export'), 'OnReflectMultiLingualFields' => Array ('self' => 'view'), @@ -35,6 +34,10 @@ $event->status = erSTOP; } + if (is_object($event->MasterEvent) && $event->MasterEvent->status != erSUCCESS) { + return ; + } + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); /* @var $ml_helper kMultiLanguageHelper */ @@ -246,7 +249,7 @@ $modules = getArrayValue($field_values, 'Module'); $lang_xml->Parse($filename, $field_values['PhraseType'], $modules, $field_values['ImportOverwrite'] ? LANG_OVERWRITE_EXISTING : LANG_SKIP_EXISTING); - $event->redirect = $this->Application->GetVar('next_template'); + $event->SetRedirectParam('opener', 'u'); } else { $object =& $this->Application->recallObject('phrases.import'); @@ -257,133 +260,6 @@ } /** - * Copies imported from xml file from temp table to live table - * - * @param kEvent $event - */ - function OnImportProgress(&$event) - { - define('IMPORT_BY', 300); // import this much records per step - $template_name = 'regional/languages_import_step2'; - - $import_mode = (int)$this->Application->GetVar('mode'); // 1 - overwrite existing phrases, 0 - don't overwrite existing phrases - $import_source = (int)$this->Application->GetVar('source'); - $import_steps = Array(0 => 'lang', 1 => 'phrases', 2 => 'emailmessages', 3 => 'finish'); - - $key_fields = Array(0 => 'PackName', 1 => 'Phrase', 2 => 'EventId'); // by what field should we search record match - - $import_titles = Array(0 => 'la_ImportingLanguages', 1 => 'la_ImportingPhrases', 2 => 'la_ImportingEmailEvents', 3 => 'la_Done'); - - // --- BEFORE --- - $import_prefix = $import_steps[$import_source]; - $import_start = (int)$this->Application->GetVar('start'); - $id_field = $this->Application->getUnitOption($import_prefix,'IDField'); - $dst_table = $this->Application->getUnitOption($import_prefix,'TableName'); - $src_table = $this->Application->GetTempName($dst_table); - - $import_total = $this->Application->GetVar('total'); - if(!$import_total) $import_total = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$src_table); - // --- AFTER --- - - if($import_start == $import_total) - { - $import_source++; - $import_prefix = $import_steps[$import_source]; - if($import_prefix == 'finish') - { - $event->SetRedirectParam('opener','u'); - return true; - } - - $import_start = 0; - $id_field = $this->Application->getUnitOption($import_prefix,'IDField'); - $dst_table = $this->Application->getUnitOption($import_prefix,'TableName'); - $src_table = $this->Application->GetTempName($dst_table); - $import_total = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$src_table); - } - - if($import_total > 0) - { - $done_percent = ($import_start * 100) / $import_total; - } - else - { - $done_percent = 100; - } - - $block_params = Array( 'name' => $template_name, - 'title' => $import_titles[$import_source], - 'percent_done' => $done_percent, - 'percent_left' => 100 - $done_percent); - - $this->Application->InitParser(); - $this->Application->setUnitOption('phrases','AutoLoad',false); - echo $this->Application->ParseBlock($block_params); - - //break out of buffering - $buffer_content = Array(); - while (ob_get_level()) { - $buffer_content[] = ob_get_clean(); - } - $ret = implode('', array_reverse($buffer_content)); - echo $ret; - flush(); - - - $sql = 'SELECT * FROM %s LIMIT %s,%s'; - $rows = $this->Conn->Query( sprintf($sql,$src_table,$import_start,IMPORT_BY) ); - - $values_sql = ''; - - // if found and mode = 1 (overwrite) - $search_sql = 'SELECT '.$id_field.' FROM '.$dst_table.' WHERE '.$key_fields[$import_source].' = %s AND LanguageId = %s'; - $update_sql = 'UPDATE '.$dst_table.' SET %s WHERE '.$id_field.' = %s'; - - foreach($rows as $row) - { - $tmp_sql = sprintf($search_sql, $this->Conn->qstr($row[ $key_fields[$import_source] ]), $row['LanguageId'] ); - $tmp_id = $this->Conn->GetOne($tmp_sql); - if($tmp_id > 0 && $import_mode == 1) - { - // update - $update_fields = ''; - foreach($row as $field_name => $field_value) - { - if($field_name == $id_field) continue; - $update_fields .= '`'.$field_name.'` = '.$this->Conn->qstr($field_value).','; - } - $update_fields = preg_replace('/(.*),$/', '\\1', $update_fields); - $this->Conn->Query( sprintf($update_sql, $update_fields, $tmp_id) ); - } - elseif(!$tmp_id) - { - $values_sql .= '('; - foreach($row as $field_value) - { - $values_sql .= $this->Conn->qstr($field_value).','; - } - $values_sql = preg_replace('/(.*),$/', '\\1', $values_sql).'),'; - } - } - - if($values_sql) - { - $fields_sql = ''; - $fields = array_keys( $this->Application->getUnitOption($import_prefix,'Fields') ); - foreach($fields as $field_name) - { - $fields_sql .= '`'.$field_name.'`,'; - } - $fields_sql = preg_replace('/(.*),$/', '\\1', $fields_sql); - - $values_sql = preg_replace('/(.*),$/', '\\1', $values_sql); - $sql = sprintf('INSERT INTO %s (%s) VALUES %s', $dst_table, $fields_sql, $values_sql); - $this->Conn->Query($sql); - } - $event->setRedirectParams( Array('lang_event' => 'OnImportProgress', 'pass' => 'all,lang', 'start' => $import_start += count($rows), 'total' => $import_total, 'source' => $import_source, 'mode' => $import_mode) ); - } - - /** * Stores ids of selected languages and redirects to export language step 1 * * @param kEvent $event @@ -399,8 +275,7 @@ $this->StoreSelectedIDs($event); $this->Application->StoreVar('export_language_ids', implode(',', $this->getSelectedIDs($event)) ); - $event->setRedirectParams( Array('m_opener'=>'d','phrases.export_event'=>'OnNew','pass'=>'all,phrases.export') ); - $event->redirect = 'regional/languages_export'; + $event->setRedirectParams( Array('phrases.export_event' => 'OnNew', 'pass' => 'all,phrases.export') ); } /**