forked from science-ation/science-ation
- Handle the case where a user is a volunteer and a committee member, tested. works.
- Add the UNIQUE username,year condition to the 117 update. - Bump the version to 119. I won't commit anything else to the existing updates, unless I find an error in a script.
This commit is contained in:
parent
9c40cc91f8
commit
af6eb12985
@ -1 +1 @@
|
||||
115
|
||||
119
|
||||
|
@ -25,12 +25,86 @@ function db_update_116_post()
|
||||
mysql_query("UPDATE users SET username='$username' WHERE id='$r->id'");
|
||||
}
|
||||
|
||||
//okay now finally, there's a chance of duplicates from committee/volunteer that were in here before, so we need to merge them
|
||||
//FIXME: dave add the merge code :)
|
||||
//after done, we should be able to do "ALTER TABLE users ADD UNIQUE (username,year)"
|
||||
//this can go into update 117.sql i guess?
|
||||
|
||||
//okay now finally, there's a chance of duplicates from
|
||||
//committee/volunteer that were in here before, so we need to merge
|
||||
//them
|
||||
$q = mysql_query("SELECT * FROM `users` WHERE types LIKE '%committee%'");
|
||||
while($r = mysql_fetch_assoc($q)) {
|
||||
$orig_r = $r;
|
||||
$qq = mysql_query("SELECT * FROM `users` WHERE
|
||||
(`username`='{$r['username']}' OR `email`='{$r['email']}')
|
||||
AND `id`!={$r['id']}");
|
||||
if(mysql_num_rows($qq) == 0) continue;
|
||||
|
||||
echo "User id {$r['id']} ({$r['username']} {$r['email']}) has multiple users, merging...\n";
|
||||
|
||||
/* Now, there should only be two types, because the system is
|
||||
* only supposed to let committee members and volunteers be
|
||||
* created, and it has only been in use for one year without
|
||||
* year stamps., but we'll handle any number */
|
||||
|
||||
/* However, we will make the committee the record that sticks
|
||||
* */
|
||||
$delete_ids = array();
|
||||
$delete_userids = array();
|
||||
while($rr = mysql_fetch_assoc($qq)) {
|
||||
$delete_ids[] = "`id`={$rr['id']}";
|
||||
$delete_userids[] = "`users_id`={$rr['id']}";
|
||||
$keys = array_keys($rr);
|
||||
foreach($keys as $k) {
|
||||
switch($k) {
|
||||
case 'id':
|
||||
/* Skip */
|
||||
break;
|
||||
case 'types':
|
||||
/* Merge types */
|
||||
if(strstr($r['types'], $rr['types']) == false) {
|
||||
$r['types']= $r['types'].','.$rr['types'];
|
||||
echo " New type: {$r['types']}\n";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Save data */
|
||||
if(trim($r[$k]) == '' && trim($rr[$k]) != '') {
|
||||
$r[$k] = $rr[$k];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Construct SQL for a SET clause */
|
||||
$set = array();
|
||||
$keys = array_keys($r);
|
||||
foreach($keys as $k) {
|
||||
if($r[$k] != $orig_r[$k]) {
|
||||
$set[] = "`$k`='{$r[$k]}'";
|
||||
}
|
||||
}
|
||||
if(count($set)) {
|
||||
$query = join(',',$set);
|
||||
mysql_query("UPDATE `users` SET $query WHERE id={$r['id']}");
|
||||
echo "Update query: UPDATE `users` SET $query WHERE id={$r['id']}\n";
|
||||
}
|
||||
|
||||
/* Join together the WHERE commands */
|
||||
$where_id = "WHERE ".join(" OR ", $delete_ids);
|
||||
$where_users_id = "WHERE ".join(" OR ", $delete_userids);
|
||||
|
||||
echo "Merged... Deleting duplicate and adjusting volunteer tables...\n";
|
||||
/* Delete the dupe */
|
||||
mysql_query("DELETE FROM `users` $where_id");
|
||||
/* Update volunteer linkage */
|
||||
mysql_query("UPDATE `users_volunteer` SET `users_id`={$r['id']} $where_users_id");
|
||||
mysql_query("UPDATE `volunteer_positions_signup` SET `users_id`={$r['id']} $where_users_id");
|
||||
|
||||
echo "done with this user.\n";
|
||||
|
||||
}
|
||||
|
||||
/* Create volunteer database entries for any that don't exist */
|
||||
$q = mysql_query("SELECT * FROM users WHERE types LIKE '%volunteer%'");
|
||||
while($i = mysql_fetch_object($q)) {
|
||||
|
@ -17,3 +17,5 @@ ALTER TABLE `judges_teams_link` CHANGE `judges_id` `users_id` INT( 11 ) NOT NULL
|
||||
-- The users_id is linked with the year, don't need to store it here too
|
||||
ALTER TABLE `judges_specialaward_sel` DROP `year`;
|
||||
|
||||
ALTER TABLE users ADD UNIQUE (username,year);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user