function upd_alter_table($table, $alters, $condition = true) { global $config, $update_tables; if (!$condition) { return; } upd_add_more_time(); $alters_print = is_array($alters) ? dump($alters) : $alters; upd_log_message("Altering table '{$table}' with alterations {$alters_print}"); if (!is_array($alters)) { $alters = array($alters); } $alters = implode(',', $alters); // foreach($alters as $table_name => ) $qry = "ALTER TABLE {$config->db_prefix}{$table} {$alters};"; //$result = db_query($qry); $result = upd_do_query($qry); $error = db_error(); if ($error) { die("Altering error for table `{$table}`: {$error}<br />{$alters_print}"); } upd_load_table_info($table, false); return $result; }
function upd_alter_table($table, $alters, $condition = true) { global $config; if (!$condition) { return; } upd_add_more_time(); $alters_print = is_array($alters) ? dump($alters) : $alters; upd_log_message("Altering table '{$table}' with alterations {$alters_print}"); if (!is_array($alters)) { $alters = array($alters); } $qry = "ALTER TABLE {$config->db_prefix}{$table} " . implode(',', $alters) . ';'; $result = mysql_query($qry); $error = mysql_error(); if ($error) { die("Altering error for table `{$table}`: {$error}<br />{$alters_print}"); } upd_load_table_info($table, false); return $result; }
case 24: upd_log_version_update(); upd_create_table('confirmations', "(\n `id` bigint(11) NOT NULL AUTO_INCREMENT,\n `id_user` bigint(11) NOT NULL DEFAULT 0,\n `type` SMALLINT NOT NULL DEFAULT 0,\n `code` NVARCHAR(16) NOT NULL DEFAULT '',\n `email` NVARCHAR(64) NOT NULL DEFAULT '',\n `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`),\n KEY `i_code_email` (`code`, `email`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); if ($update_tables['users']['urlaubs_until']) { upd_alter_table('users', "ADD `vacation` int(11) NOT NULL DEFAULT '0' COMMENT 'Time when user can leave vacation mode'", !$update_tables['users']['vacation']); upd_do_query('UPDATE {{users}} SET `vacation` = `urlaubs_until` WHERE `urlaubs_modus` <> 0;'); upd_alter_table('users', 'DROP COLUMN `urlaubs_until`, DROP COLUMN `urlaubs_modus`, DROP COLUMN `urlaubs_modus_time`', $update_tables['users']['urlaubs_until']); } upd_check_key('user_vacation_disable', $config->urlaubs_modus_erz, !isset($config->user_vacation_disable)); upd_do_query("DELETE FROM {{config}} WHERE `config_name` IN ('urlaubs_modus_erz');"); upd_do_query('COMMIT;', true); $new_version = 25; case 25: upd_log_version_update(); upd_alter_table('rw', array("DROP COLUMN `a_zestrzelona`", "DROP INDEX `rid`", "ADD COLUMN `report_id` bigint(11) NOT NULL AUTO_INCREMENT FIRST", "ADD PRIMARY KEY (`report_id`)", "ADD INDEX `i_rid` (`rid`)"), !$update_tables['rw']['report_id']); upd_add_more_time(); upd_create_table('logs_backup', "AS (SELECT * FROM {$config->db_prefix}logs);"); upd_alter_table('logs', array("MODIFY COLUMN `log_id` INT(1)", "DROP PRIMARY KEY"), !$update_tables['logs']['log_timestamp']); upd_alter_table('logs', array("DROP COLUMN `log_id`", "ADD COLUMN `log_timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Human-readable record timestamp' FIRST", "ADD COLUMN `log_username` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'Username' AFTER `log_timestamp`", "MODIFY COLUMN `log_title` VARCHAR(64) NOT NULL DEFAULT 'Log entry' COMMENT 'Short description' AFTER `log_username`", "MODIFY COLUMN `log_page` VARCHAR(512) NOT NULL DEFAULT '' COMMENT 'Page that makes entry to log' AFTER `log_text`", "CHANGE COLUMN `log_type` `log_code` INT UNSIGNED NOT NULL DEFAULT 0 AFTER `log_page`", "MODIFY COLUMN `log_sender` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'User ID which make log record' AFTER `log_code`", "MODIFY COLUMN `log_time` INT(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Machine-readable timestamp' AFTER `log_sender`", "ADD COLUMN `log_dump` TEXT NOT NULL DEFAULT '' COMMENT 'Machine-readable dump of variables' AFTER `log_time`", "ADD INDEX `i_log_username` (`log_username`)", "ADD INDEX `i_log_time` (`log_time`)", "ADD INDEX `i_log_sender` (`log_sender`)", "ADD INDEX `i_log_code` (`log_code`)", "ADD INDEX `i_log_page` (`log_page`)", "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci"), !$update_tables['logs']['log_timestamp']); upd_do_query('DELETE FROM `{{logs}}` WHERE `log_code` = 303;'); if ($update_tables['errors']) { upd_do_query('INSERT INTO `{{logs}}` (`log_code`, `log_sender`, `log_title`, `log_text`, `log_page`, `log_time`) SELECT 500, `error_sender`, `error_type`, `error_text`, `error_page`, `error_time` FROM `{{errors}}`;'); if ($update_tables['errors_backup']) { upd_drop_table('errors_backup'); } __db_query("ALTER TABLE {$config->db_prefix}errors RENAME TO {$config->db_prefix}errors_backup;"); upd_drop_table('errors'); } upd_alter_table('logs', 'ORDER BY log_time'); upd_alter_table('logs', array("ADD COLUMN `log_id` SERIAL", "ADD PRIMARY KEY (`log_id`)"), !$update_tables['logs']['log_id']); upd_do_query('UPDATE `{{logs}}` SET `log_timestamp` = FROM_UNIXTIME(`log_time`);');
} $unit_cost = implode(';', $unit_cost); $que_lines[] = "({$que_row['id']},{$que_data[QI_PLANET_ID]}," . QUE_RESEARCH . ",{$que_data[QI_TIME]},{$que_data[QI_UNIT_ID]},1," . BUILD_CREATE . ",{$unit_level},{$que_data[QI_TIME]},'{$unit_cost}')"; } if (!empty($que_lines)) { upd_do_query('INSERT INTO `{{que}}` (`que_player_id`,`que_planet_id_origin`,`que_type`,`que_time_left`,`que_unit_id`,`que_unit_amount`,`que_unit_mode`,`que_unit_level`,`que_unit_time`,`que_unit_price`) VALUES ' . implode(',', $que_lines)); } upd_alter_table('users', array("DROP COLUMN `que`"), $update_tables['users']['que']); } upd_check_key('server_que_length_research', 1, !isset($config->server_que_length_research)); // Ковертируем технологии в таблицы if ($update_tables['users']['graviton_tech']) { upd_do_query("DELETE FROM {{unit}} WHERE unit_type = " . UNIT_TECHNOLOGIES); $que_lines = array(); $user_query = upd_do_query("SELECT * FROM {{users}}"); upd_add_more_time(300); $sn_group_tech = sn_get_groups('tech'); while ($user_row = db_fetch($user_query)) { foreach ($sn_group_tech as $tech_id) { if ($tech_level = intval($user_row[get_unit_param($tech_id, P_NAME)])) { $que_lines[] = "({$user_row['id']}," . LOC_USER . ",{$user_row['id']}," . UNIT_TECHNOLOGIES . ",{$tech_id},{$tech_level})"; } } } if (!empty($que_lines)) { upd_do_query("INSERT INTO {{unit}} (unit_player_id, unit_location_type, unit_location_id, unit_type, unit_snid, unit_level) VALUES " . implode(',', $que_lines)); } upd_alter_table('users', array("DROP COLUMN `graviton_tech`"), $update_tables['users']['graviton_tech']); } if (!$update_indexes['unit']['I_unit_record_search']) { upd_alter_table('unit', array("ADD KEY `I_unit_record_search` (`unit_snid`,`unit_player_id`,`unit_level` DESC,`unit_id`)"), !$update_indexes['unit']['I_unit_record_search']);