Beispiel #1
0
function upd_db_changeset_apply($db_changeset)
{
    if (!is_array($db_changeset) || empty($db_changeset)) {
        return;
    }
    foreach ($db_changeset as $table_name => $table_data) {
        foreach ($table_data as $record_id => $conditions) {
            $where = '';
            if (!empty($conditions['where'])) {
                $where = 'WHERE ' . implode(' AND ', $conditions['where']);
            }
            $fields = array();
            if ($conditions['fields']) {
                foreach ($conditions['fields'] as $field_name => $field_data) {
                    $condition = "`{$field_name}` = ";
                    $value = '';
                    if ($field_data['delta']) {
                        $value = "`{$field_name}`" . ($field_data['delta'] >= 0 ? '+' : '') . $field_data['delta'];
                    } elseif ($field_data['set']) {
                        $value = is_string($field_data['set']) ? "'{$field_data['set']}'" : $field_data['set'];
                    }
                    if ($value) {
                        $fields[] = $condition . $value;
                    }
                }
            }
            $fields = implode(',', $fields);
            switch ($conditions['action']) {
                case SQL_OP_DELETE:
                    upd_do_query("DELETE FROM {{{$table_name}}} {$where}");
                    break;
                case SQL_OP_UPDATE:
                    if ($fields) {
                        /*if($table_name == 'unit')
                          {
                            pdump("UPDATE {{{$table_name}}} SET {$fields} {$where}");
                            //die();
                          }*/
                        upd_do_query("UPDATE {{{$table_name}}} SET {$fields} {$where}");
                    }
                    break;
                case SQL_OP_INSERT:
                    if ($fields) {
                        upd_do_query("INSERT INTO {{{$table_name}}} SET {$fields}");
                    }
                    break;
                case SQL_OP_REPLACE:
                    if ($fields) {
                        upd_do_query("REPLACE INTO {{{$table_name}}} SET {$fields}");
                    }
                    break;
            }
        }
    }
}
Beispiel #2
0
        upd_alter_table('chat', array("MODIFY COLUMN `user` TEXT COMMENT 'Chat message user name'"), strtoupper($update_tables['chat']['user']['Type']) != 'TEXT');
        upd_alter_table('planets', array("ADD `ship_sattelite_sloth` bigint(20) NOT NULL DEFAULT '0' COMMENT 'Terran Sloth'", "ADD `ship_bomber_envy` bigint(20) NOT NULL DEFAULT '0' COMMENT 'Lunar Envy'", "ADD `ship_recycler_gluttony` bigint(20) NOT NULL DEFAULT '0' COMMENT 'Mercurian Gluttony'", "ADD `ship_fighter_wrath` bigint(20) NOT NULL DEFAULT '0' COMMENT 'Venerian Wrath'", "ADD `ship_battleship_pride` bigint(20) NOT NULL DEFAULT '0' COMMENT 'Martian Pride'", "ADD `ship_cargo_greed` bigint(20) NOT NULL DEFAULT '0' COMMENT 'Republican Greed'"), !$update_tables['planets']['ship_sattelite_sloth']);
        upd_alter_table('planets', array("ADD `ship_sattelite_sloth_porcent` TINYINT(3) UNSIGNED NOT NULL DEFAULT '10' COMMENT 'Terran Sloth production'", "ADD KEY `I_ship_sattelite_sloth` (`ship_sattelite_sloth`, `id_level`)", "ADD KEY `I_ship_bomber_envy` (`ship_bomber_envy`, `id_level`)", "ADD KEY `I_ship_recycler_gluttony` (`ship_recycler_gluttony`, `id_level`)", "ADD KEY `I_ship_fighter_wrath` (`ship_fighter_wrath`, `id_level`)", "ADD KEY `I_ship_battleship_pride` (`ship_battleship_pride`, `id_level`)", "ADD KEY `I_ship_cargo_greed` (`ship_cargo_greed`, `id_level`)"), !$update_tables['planets']['ship_sattelite_sloth_porcent']);
        upd_check_key('stats_hide_admins', 1, !isset($config->stats_hide_admins));
        upd_check_key('stats_hide_player_list', '', !isset($config->stats_hide_player_list));
        upd_check_key('adv_seo_meta_description', '', !isset($config->adv_seo_meta_description));
        upd_check_key('adv_seo_meta_keywords', '', !isset($config->adv_seo_meta_keywords));
        upd_check_key('stats_hide_pm_link', '0', !isset($config->stats_hide_pm_link));
        upd_alter_table('notes', array("ADD INDEX `I_owner_priority_time` (`owner`, `priority`, `time`)"), !$update_indexes['notes']['I_owner_priority_time']);
        if (!$update_tables['buddy']['BUDDY_ID']) {
            upd_alter_table('buddy', array("CHANGE COLUMN `id` `BUDDY_ID` SERIAL COMMENT 'Buddy table row ID'", "CHANGE COLUMN `active` `BUDDY_STATUS` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Buddy request status'", "CHANGE COLUMN `text` `BUDDY_REQUEST` TINYTEXT DEFAULT '' COMMENT 'Buddy request text'", "DROP INDEX `id`", "DROP FOREIGN KEY `FK_buddy_sender_id`", "DROP FOREIGN KEY `FK_buddy_owner_id`", "DROP INDEX `I_buddy_sender`", "DROP INDEX `I_buddy_owner`"), !$update_tables['buddy']['BUDDY_ID']);
            upd_alter_table('buddy', array("CHANGE COLUMN `sender` `BUDDY_SENDER_ID` BIGINT(20) UNSIGNED NULL DEFAULT NULL COMMENT 'Buddy request sender ID'", "CHANGE COLUMN `owner` `BUDDY_OWNER_ID` BIGINT(20) UNSIGNED NULL DEFAULT NULL COMMENT 'Buddy request recipient ID'"), !$update_tables['buddy']['BUDDY_SENDER']);
            $query = upd_do_query("SELECT `BUDDY_ID`, `BUDDY_SENDER_ID`, `BUDDY_OWNER_ID` FROM {{buddy}} ORDER BY `BUDDY_ID`;");
            $found = $lost = array();
            while ($row = db_fetch($query)) {
                $index = min($row['BUDDY_SENDER_ID'], $row['BUDDY_OWNER_ID']) . ';' . max($row['BUDDY_SENDER_ID'], $row['BUDDY_OWNER_ID']);
                if (!isset($found[$index])) {
                    $found[$index] = $row['BUDDY_ID'];
                } else {
                    $lost[] = $row['BUDDY_ID'];
                }
            }
            $lost = implode(',', $lost);
            if ($lost) {
                upd_do_query("DELETE FROM {{buddy}} WHERE `BUDDY_ID` IN ({$lost})");
            }
            upd_alter_table('buddy', array("ADD KEY `I_BUDDY_SENDER_ID` (`BUDDY_SENDER_ID`, `BUDDY_OWNER_ID`)", "ADD KEY `I_BUDDY_OWNER_ID` (`BUDDY_OWNER_ID`, `BUDDY_SENDER_ID`)", "ADD CONSTRAINT `FK_BUDDY_SENDER_ID` FOREIGN KEY (`BUDDY_SENDER_ID`) REFERENCES `{$config->db_prefix}users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE", "ADD CONSTRAINT `FK_BUDDY_OWNER_ID` FOREIGN KEY (`BUDDY_OWNER_ID`) REFERENCES `{$config->db_prefix}users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE"), !$update_indexes['buddy']['I_BUDDY_SENDER_ID']);
        }
        upd_do_query('COMMIT;', true);
        $new_version = 35;
}
Beispiel #3
0
 function propagade_player_options($old_option_name, $new_option_id)
 {
     global $update_tables;
     if (!empty($update_tables['users'][$old_option_name])) {
         upd_do_query("REPLACE INTO {{player_options}} (`player_id`, `option_id`, `value`)\n          SELECT `id`, {$new_option_id}, `{$old_option_name}`\n          FROM {{users}}\n          WHERE `user_as_ally` is null and `user_bot` = " . USER_BOT_PLAYER);
         // TODO - UNCOMMENT !!!
         upd_alter_table('users', array("DROP COLUMN `{$old_option_name}`"));
     }
 }
Beispiel #4
0
        upd_check_key('payment_currency_exchange_eur', 0.9, true);
        upd_check_key('payment_currency_exchange_wme', 0.9, true);
        upd_check_key('payment_currency_exchange_wmb', 18000, !$config->payment_currency_exchange_wmb);
        upd_check_key('payment_currency_exchange_uah', 30, true);
        upd_check_key('payment_currency_exchange_wmu', 30, true);
        upd_check_key('payment_currency_exchange_rub', 60, true);
        upd_check_key('payment_currency_exchange_wmr', 60, true);
        upd_do_query('COMMIT;', true);
        $new_version = 39;
    case 39:
        upd_log_version_update();
        upd_do_query('COMMIT;', true);
        // $new_version = 40;
}
upd_log_message('Upgrade complete.');
upd_do_query('SET FOREIGN_KEY_CHECKS=1;');
if ($new_version) {
    $config->db_saveItem('db_version', $new_version);
    upd_log_message("<font color=green>DB version is now {$new_version}</font>");
} else {
    upd_log_message("DB version didn't changed from {$config->db_version}");
}
$config->db_loadAll();
/*
if($user['authlevel'] >= 3) {
  print(str_replace("\r\n", '<br>', $upd_log));
}
*/
unset($sn_cache->tables);
sys_refresh_tablelist($config->db_prefix);
upd_log_message('Restoring server status');