Index: trunk/core/units/languages/languages_event_handler.php =================================================================== diff -u -N -r3316 -r4000 --- trunk/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 3316) +++ trunk/core/units/languages/languages_event_handler.php (.../languages_event_handler.php) (revision 4000) @@ -10,51 +10,12 @@ */ function OnReflectMultiLingualFields($event) { - $table_name = $this->Application->getUnitOption($event->Prefix,'TableName'); - $languages_count = $this->Conn->GetOne('SELECT COUNT(*) FROM '.$table_name); - $languages_count = $languages_count + 5 - ( $languages_count % 5 ? ($languages_count % 5) : 5 ); - - $sqls = Array(); - + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + $unit_config_reader =& $this->Application->recallObject('kUnitConfigReader'); - - foreach($unit_config_reader->configData as $prefix => $config_data) - { - $table_name = getArrayValue($config_data,'TableName'); - $fields = getArrayValue($config_data,'Fields'); - if(!($table_name && $fields) ) continue; - - foreach($fields as $field_name => $field_options) - { - if( isset($field_options['formatter']) && $field_options['formatter'] == 'kMultiLanguage' ) - { - $describe = $this->Conn->Query('DESCRIBE '.$table_name.' \'l%_'.$field_name.'\''); - $created_count = count($describe); - if(!$describe) - { - // no multilingual fields at all - $describe = $this->Conn->Query('DESCRIBE '.$table_name.' \''.$field_name.'\''); - $created_count = 0; - } - if(!$describe) continue; - - $field_mask = 'l%s_'.$field_name.' '.$describe[0]['Type']; - $create_count = $languages_count - $created_count; - if($create_count > 0) - { - $sqls[] = 'ALTER TABLE '.$table_name.( $this->generateAlterSQL($field_mask, $created_count + 1, $create_count) ); - } - } - } + foreach ($unit_config_reader->configData as $prefix => $config_data) { + $ml_helper->createFields($prefix); } - - if($sqls) - { - foreach ($sqls as $sql_query) - { - $this->Conn->Query($sql_query); - } - } } /** @@ -72,31 +33,6 @@ } /** - * Returns ALTER statement part for adding required fields to table - * - * @param string $field_mask sql mask for creating field with correct definition (type & size) - * @param int $start_index add new fields starting from this index - * @param int $create_count create this much new multilingual field translations - * @return string - */ - function generateAlterSQL($field_mask, $start_index, $create_count) - { - $i_count = $start_index + $create_count; - $ret = ''; - while($start_index < $i_count) - { - list($prev_field,$type) = explode(' ', sprintf($field_mask, $start_index-1) ); - if( substr($prev_field, 0, 3) == 'l0_' ) - { - $prev_field = substr( $prev_field, 3, strlen($prev_field) ); - } - $ret .= ' ADD COLUMN '.sprintf($field_mask,$start_index).' AFTER `'.$prev_field.'`, '; - $start_index++; - } - return preg_replace('/, $/',';',$ret); - } - - /** * Copy labels from another language * * @param kEvent $event