Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0f75716632
Fetching contributors…

Cannot retrieve contributors at this time

executable file 96 lines (67 sloc) 2.753 kb
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with webDiplomacy. If not, see <>.
defined('IN_CODE') or die('This script can not be run by itself.');
* This file defragments the tables which may reach high ID levels. Once they go over
* 2^32-1 PHP can't keep the ID in memory, automatically starts using floats, and the
* imprecision causes lots of bizarre problems.
* The server must not be in use when this is run, but luckily it should never have
* to be run except on the largest servers after many years (unless lots of DATC testing
* is causing an artificially high number of orders etc)
* @package Admin
if ( !$User->type['Admin'] )
die('Admins only');
header('Content-Type: text/plain');
print 'Defragmenting'."\n"; flush();
$tableNames = array('Moves','Orders','TerrStatus','Units');
foreach($tableNames as $tableName)
print 'Defragmenting '.$tableName."\n"; flush();
list($max) = $DB->sql_row("SELECT MAX(id) FROM wD_".$tableName);
$tabl = $DB->sql_tabl("SELECT id FROM wD_".$tableName." ORDER BY id ASC");
while( list($id) = $DB->tabl_row($tabl) )
if ( ( $i % 100 ) == 0 )
print "\t".$id."(/".$max.") -> ".$i."\n"; flush();
if ( $i != $id )
$DB->sql_put("UPDATE wD_".$tableName." SET id = ".$i." WHERE id = ".$id);
if ( $tableName == 'Units' )
$DB->sql_put("UPDATE wD_TerrStatus SET occupyingUnitID = ".$i." WHERE occupyingUnitID = ".$id);
$DB->sql_put("UPDATE wD_TerrStatus SET retreatingUnitID = ".$i." WHERE retreatingUnitID = ".$id);
$DB->sql_put("UPDATE wD_Orders SET unitID = ".$i." WHERE unitID = ".$id);
$DB->sql_put("ALTER TABLE wD_".$tableName." AUTO_INCREMENT = ".$i);
print $tableName.' done: '.$max.'->'.$i."\n"; flush();
print "Done\n";
Jump to Line
Something went wrong with that request. Please try again.