Index: trunk/core/install/upgrades.php =================================================================== diff -u -N -r7855 -r8038 --- trunk/core/install/upgrades.php (.../upgrades.php) (revision 7855) +++ trunk/core/install/upgrades.php (.../upgrades.php) (revision 8038) @@ -6,16 +6,69 @@ * */ class CoreUpgrades extends kHelper { - + /** * Changes table structure, where multilingual fields of TEXT type are present * * @param string $mode when called mode {before, after) */ function Upgrade_4_0_2($mode) { + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + $lang_count = $ml_helper->getLanguageCount(); + $this->Application->UnitConfigReader->iterateConfigs( Array (&$this, 'updateTextFields', $lang_count) ); } + + /** + * Callback function, that makes all ml fields of text type null with same default value + * + * @param string $prefix + * @param Array $config_data + * @param int $language_count + * @return bool + */ + function updateTextFields($prefix, &$config_data, $language_count) + { + if (!isset($config_data['TableName']) || !isset($config_data['Fields'])) { + // invalid config found or prefix not found + return false; + } + + $table_name = $config_data['TableName']; + $table_structure = $this->Conn->Query('DESCRIBE '.$table_name, 'Field'); + if (!$table_structure) { + // table not found + return false; + } + + $sqls = Array (); + foreach ($config_data['Fields'] as $field => $options) { + if (isset($options['formatter']) && $options['formatter'] == 'kMultiLanguage' && !isset($options['master_field'])) { + // update all l_ fields (new format) + for ($i = 1; $i <= $language_count; $i++) { + $ml_field = 'l'.$i.'_'.$field; + if ($table_structure[$ml_field]['Type'] == 'text') { + $sqls[] = 'CHANGE '.$ml_field.' '.$ml_field.' TEXT NULL DEFAULT NULL'; + } + } + + // update if found (old format) + if (isset($table_structure[$field]) && $table_structure[$field]['Type'] == 'text') { + $sqls[] = 'CHANGE '.$field.' '.$field.' TEXT NULL DEFAULT NULL'; + } + } + } + + if ($sqls) { + $sql = 'ALTER TABLE '.$table_name.' '.implode(', ', $sqls); + $this->Conn->Query($sql); + } + + return true; + } + } ?> \ No newline at end of file