Location: PHPKode > projects > Online Fantasy Football League > offl-0.2.6/www/upgrade/upgrade-015.php
 * Upgrade script for OFFL v0.1.6 or less
 * Long description
 * @author Stephen Rochelle <hide@address.com>
 * @version OFFL v0.2
 * @copyright Copyright (c) 2004 Stephen Rochelle.  Some rights reserved.
 * @package offl-ui

$pageTitle = "";
require_once($DOC_ROOT . "/lib/classes/offl_dbobject.php"); // gets database object for upgrading the DB.
require_once($DOC_ROOT . "/lib/classes/offl_league.php");
require_once($DOC_ROOT . "/lib/classes/offl_fflteam.php");
require_once($DOC_ROOT . "/lib/classes/offl_rosterplayer.php");
require_once($DOC_ROOT . "/lib/classes/offl_playerstat.php");
require_once($DOC_ROOT . "/lib/classes/offl_pastroster.php");

$fix = new OFFL_DBObject();


$fix->SQLQuery("DROP TABLE IF EXISTS `auctionvalues`");
$fix->SQLQuery("CREATE TABLE `auctionvalues` (`league_id` SMALLINT UNSIGNED NOT NULL, `player_id` SMALLINT UNSIGNED NOT NULL, `auctionvalue` SMALLINT UNSIGNED, primary key (`league_id`, `player_id`))");
$fix->SQLQuery("INSERT INTO `control` (`control_key`,`control_value`,`control_desc`,`control_allowed_values`) values ('CONFIG_USE_AUCTION','No','Use the auction format','Yes,No')");
$fix->SQLQuery("insert into `control` (`control_key`,`control_value`,`control_desc`) values	('CONFIG_SALARY_CAP','100','Maximum amount a team can spend at the auction');
$fix->SQLQuery("insert into `control` (`control_key`,`control_value`,`control_desc`) values ('CONFIG_AUCTION_SCREEN_REFRESH','0','Number of seconds between screen refreshes for auction page.');
$fix->SQLQuery("insert into `control` (`control_key`,`control_value`,`control_desc`) values ('CONFIG_MIN_PER_PLAYER','1','This is the minimum dollar amount a player can be purchased for in your auction.');
$fix->SQLQuery("insert into `control` (`control_key`,`control_value`,`control_desc`,`control_allowed_values`) values ('CONFIG_USE_DRAFT','Yes','Use the draft format','Yes,No');

$fix->SQLQuery("ALTER TABLE `control` ADD `all_leagues` TINYINT(1) unsigned DEFAULT 0 NOT NULL AFTER `league_id`");
$fix->SQLQuery("UPDATE `control` SET `all_leagues`=1 WHERE `control_key` LIKE 'MISC_SEASON_START_%'");
$fix->SQLQuery("UPDATE `control` SET `all_leagues`=1 WHERE `control_key`='MISC_WEBMASTER_EMAIL'");
$fix->SQLQuery("UPDATE `control` SET `all_leagues`=1 WHERE `control_key` LIKE 'STYLE_%'");
$fix->SQLQuery("DELETE FROM `control` WHERE (`league_id` > 0) AND ((`control_key` LIKE 'MISC_SEASON_START_%') OR (`control_key` LIKE 'STYLE_%') OR (`control_key`='MISC_WEBMASTER_EMAIL'))");


$fix->SQLQuery("ALTER TABLE `pastrosters` CHANGE `player_id_array` `player_id_array` VARCHAR( 100 ) DEFAULT NULL");
// The following line should be commented out if you've already added the `league_id` field
$fix->SQLQuery("ALTER TABLE `pastrosters` ADD `league_id` SMALLINT AFTER `fflteam_id`;");
$fix->SQLQuery("ALTER TABLE `pastrosters` ADD `nflteam_id_array` VARCHAR( 100 ) AFTER `player_id_array`;");
$fix->SQLQuery("UPDATE `control` SET `control_value`='2004-09-07 12:00:00' WHERE `control_key`='MISC_SEASON_START_2004'");

// UNCOMMENT the following line if your future games show scores already.  Be sure to change the week number (at the end of the string) to match the current week (that is, make sure it affects future games only).
//$fix->SQLQuery("UPDATE `games` SET v_fflteam_score=0, h_fflteam_score=0 WHERE week > 1");


// create the new database table
$fix->SQLQuery("DROP TABLE IF EXISTS `rosterplayers`");
$fix->SQLQuery("CREATE TABLE `rosterplayers` (`league_id` smallint unsigned not null, `player_id` smallint unsigned not null, `starter` bit default 0, `fflteam_id` smallint unsigned default 0, primary key (`player_id`, `league_id`))");
echo "<p>Database table `rosterplayers` created.</p>\n";

// now transfer the data (parse by fflteam, then insert data based on rosters)
$lg = new OFFL_League();
$teams = $lg->getAllFFLTeams(TRUE);
foreach($teams as $team)
	$fix->SQLQuery("SELECT player_ids, starters FROM fflteams WHERE fflteam_id=" . $team->getFFLTeamID());
	$pid = array_diff(explode(",",$fix->SQLResult(0, "player_ids")), array(""));
	$sts = array_diff(explode(",",$fix->SQLResult(0, "starters")), array(""));
	for($i = 0; $i < sizeof($pid); $i++)
		$RP = new OFFL_RosterPlayer();
echo "<p>Roster data migrated to `rosterplayers` successfully.</p>\n";

// now add nflteam data to pastrosters

$fix->SQLQuery("SELECT year, week, fflteam_id FROM `pastrosters`");
$num_rows = $fix->SQLNumRows();
for ($i = 0; $i < $num_rows; $i++)
	$PR = new OFFL_PastRoster($fix->SQLResult($i, "year"), $fix->SQLResult($i, "week"), $fix->SQLResult($i, "fflteam_id"));
	$player_ids = $PR->getPlayerIDArray();
	$nflteam_ids = array();
	foreach($player_ids as $player_id)
		$player = new OFFL_Player($player_id);
		$nflteam_ids[] = $player->getNFLTeamID();
echo "<p>`pastrosters` data upgrade complete.</p>\n";

// add the new field to `playerstats`
$fix->SQLQuery("ALTER TABLE `playerstats` ADD `nflteam_id` TINYINT UNSIGNED AFTER `week`");
echo "<p>`playerstats` table updated successfully.</p>\n";
// now add nflteam data to playerstats

$fix->SQLQuery("SELECT stat_id FROM `playerstats`");
$num_rows = $fix->SQLNumRows();
for ($i = 0; $i < $num_rows; $i++)
	$PS = new OFFL_PlayerStat($fix->SQLResult($i, "stat_id"));
	$player = new OFFL_Player($PS->getPlayerID());
	if (is_null($player->getNFLTeamID()))
	{	continue;	}
echo "<p>`playerstats` data upgrade complete.</p>\n";

echo "<p>Upgrade to OFFL v";
include($DOC_ROOT . "/lib/version");
echo " successful.</p>\n";


Return current item: Online Fantasy Football League