<?
define( 'UPGRADING', true );
require( 'function/funcStat.php' );
if( is_file( 'config.php' ) )
{
$UPGRADING_ARRAY['folder'] = 'default';
require( 'common.php' );
$Result = $DB->send_query( 'SELECT value FROM '.$INT_Config->myPrefix.'config WHERE `option` = "VERSIONID"' );
$Array = $DB->get_array( $Result );
$CurrentVersion = $Array['value'];
}
else
{
$CurrentVersion = '0.1.2';
}
require( 'installer/points.temp' );
switch( $CurrentVersion )
{
case '0.1.2':
define( 'INSTALL_SQL_LOCATION', 'installer/sql_012_014.temp' );
// V 0.1.2 to 0.1.3 requires installer to be run //
include( "install.php" );
if( $_POST['step'] == 6 )
{
/* Update ship fields in tables */
updateShipsField( $DB, $INT_Config->myPrefix.'victims' );
updateShipsField( $DB, $INT_Config->myPrefix.'attackers' );
}
break;
case '0.1.3':
case '0.1.3.B':
require( 'installer/sql_013_014.temp' );
foreach( $Query as $key=>$value )
{
$DB->send_query( $value );
}
case '0.1.4':
require( 'installer/sql_014_015.temp' );
// Run structure updates //
foreach( $Query as $key=>$value )
{
$DB->send_query( $value );
}
// Change corp from text to ID //
fillCorpTableFromExisting( $DB, $INT_Config->myPrefix.'victims', $INT_Config->myPrefix.'corps' );
fillCorpTableFromExisting( $DB, $INT_Config->myPrefix.'attackers', $INT_Config->myPrefix.'corps' );
// Change name from text to ID //
$DB->send_query( "ALTER TABLE `".$INT_Config->myPrefix."victims` DROP INDEX `name`" );
covertUsersFromTextToID( $DB, $INT_Config->myPrefix.'victims', $INT_Config->myPrefix.'players' );
covertUsersFromTextToID( $DB, $INT_Config->myPrefix.'attackers', $INT_Config->myPrefix.'players' );
// Fix bug: attacker table has tinytext ship column not tinyint ! //
updateShipsField( $DB, $INT_Config->myPrefix.'attackers' );
// Insert default class points value //
foreach( $Points as $Name=>$Value )
{
$DB->send_query( 'UPDATE `'.$INT_Config->myPrefix.'ships_class` SET points = "'.$Value.'" WHERE name = "'.$Name.'"' );
}
syncUserStats( $DB );
case '0.1.5':
// Drop primary key on themes table if it exists //
require( 'installer/sql_015_015B.temp' );
foreach( $Query as $key=>$value )
{
$DB->send_query($value);
}
case '0.1.5.B':
require( 'installer/sql_015B_015C.temp' );
foreach( $Query as $key=>$value )
{
$DB->send_query($value);
}
syncShips($DB, 'installer/ships.csv');
case '0.1.5.C':
default:
$template->set_filenames( array(
'message' => 'message.tpl' )
);
$template->assign_var( 'MESSAGE', 'Your version of EVEkill is up to date.' );
outputpage( $template, 'message' );
}
// Required for 0.1.2 > 0.1.3 //
function updateShipsField( &$DB, $table = 'victims' )
{
$data = array();
// Read in all fields amd convert ships to Ref ID //
$Result = $DB->send_query( 'SELECT battle_id, name, ship FROM '.$table );
while( $Array = $DB->get_array( $Result ) )
{
$data[$Array['battle_id']][$Array['name']] = ( is_numeric( $Array['ship'] ) ? $Array['ship'] : convertShipToId( trim( $Array['ship'] ), $DB ) );
}
// Change field type //
$DB->send_query( 'ALTER TABLE '.$table.' CHANGE ship ship TINYINT UNSIGNED NOT NULL' );
// Restore DB //
foreach( $data as $battleID=>$Array )
{
foreach( $Array as $Name=>$ShipID )
{
$DB->send_query( 'UPDATE '.$table.' SET ship = '.$ShipID.' WHERE battle_id = "'.$battleID.'" AND name = "'.$Name.'"' );
}
}
foreach( $data as $ID=>$ShipID )
{
}
}
// Required for * > 0.1.5 //
function fillCorpTableFromExisting( &$DB, $sourceTable, $corpTable )
{
$data = array();
// Extract the corp names from the source table //
$Result = $DB->send_query( 'SELECT battle_id, name, corp FROM '.$sourceTable );
// Convert corp name into ID //
while( $Array = $DB->get_array( $Result ) )
{
$data[$Array['battle_id']][$Array['name']] = ( is_numeric( $Array['corp'] ) ? $Array['corp'] : convertCorpToId( trim( $Array['corp'] ), $DB ) );
}
// Change field type //
$DB->send_query( "ALTER TABLE ".$sourceTable." CHANGE corp corp MEDIUMINT UNSIGNED NOT NULL default '0'" );
// Restore corp ID's to source table //
foreach( $data as $battleID=>$Array )
{
foreach( $Array as $Name=>$CorpID )
{
$DB->send_query( 'UPDATE '.$sourceTable.' SET corp = '.$CorpID.' WHERE battle_id = "'.$battleID.'" AND name = "'.$Name.'"' );
}
}
}
function covertUsersFromTextToID( &$DB, $tableName, $playerTable )
{
$data = array();
// Extract the corp names from the source table //
$Result = $DB->send_query( 'SELECT battle_id, name FROM '.$tableName );
// Convert corp name into ID //
while( $Array = $DB->get_array( $Result ) )
{
$data[$Array['battle_id']][$Array['name']] = ( is_numeric( $Array['name'] ) ? $Array['name'] : convertPlayerToID( trim( $Array['name']), $DB, true ) );
}
// Restore corp ID's to source table //
foreach( $data as $battleID=>$Array )
{
foreach( $Array as $Name=>$PlayerID )
{
$DB->send_query( 'UPDATE '.$tableName.' SET name = '.$PlayerID.' WHERE battle_id = "'.$battleID.'" AND name = "'.$Name.'"' );
}
}
// Change field type //
$DB->send_query( "ALTER TABLE `".$tableName."` CHANGE name name INT NOT NULL default '0'" );
}
?>