Fix a bug where judging teams containing apostrophe's wasnt being created, but it was using an old ID from a previous insert, so judges were being linked to teams that didnt exist... then the records became orphaned and couldnt be deleted.

This commit is contained in:
james 2008-03-29 20:48:39 +00:00
parent 572242bc14
commit 5458a5809e

View File

@ -416,6 +416,17 @@ while($r = mysql_fetch_object($q)) {
/* Finally, delete all the autocreated judges teams */
mysql_query("DELETE FROM judges_teams WHERE autocreate_type_id=1 AND year={$config['FAIRYEAR']}");
print mysql_error();
/* Also delete any judges_teams_link that link to teams that dont exist */
$q=mysql_query("SELECT judges_teams_link.id, judges_teams.id AS judges_teams_id FROM judges_teams_link LEFT JOIN judges_teams ON judges_teams_link.judges_teams_id=judges_teams.id WHERE judges_teams_link.year={$config['FAIRYEAR']}");
$n=0;
while($r=mysql_fetch_object($q)) {
if(!$r->judges_teams_id) {
mysql_query("DELETE FROM judges_teams_link WHERE id='$r->id'");
$n++;
}
}
print("Deleted $n orphaned team linkings\n");
TRACE(" Done.\n");
set_status("Loading Judges");
@ -786,14 +797,14 @@ if($config['scheduler_enable_sa_scheduling'] == 'yes') {
$tn = "{$i->name}";
/* Write this team to the DB */
mysql_query("INSERT INTO judges_teams (num,name,autocreate_type_id,year)
VALUES ('$max_jteam_num','$tn','1','{$config['FAIRYEAR']}')");
VALUES ('$max_jteam_num','".mysql_escape_string($tn)."','1','{$config['FAIRYEAR']}')");
$sa_jteam[$x]['id'] = mysql_insert_id();
/* Link the award to this team */
mysql_query("INSERT INTO judges_teams_awards_link (award_awards_id,judges_teams_id,year)
VALUES ('{$i->id}','{$sa_jteam[$x]['id']}','{$config['FAIRYEAR']}')");
TRACE("Created Team: $tn\n");
TRACE("Created Team: $tn {$sa_jteam[$x]['id']}\n");
$jteam_id++;
$x++;
}