forked from science-ation/science-ation
Fixes for issue with record id's
This commit is contained in:
parent
712348dbb9
commit
82bdfdbd10
@ -14,6 +14,8 @@ function db_update_195_post(){
|
|||||||
$fields['fair'] = array('fairs_id');
|
$fields['fair'] = array('fairs_id');
|
||||||
$fields['sponsor'] = array('sponsors_id','primary','position','notes');
|
$fields['sponsor'] = array('sponsors_id','primary','position','notes');
|
||||||
|
|
||||||
|
$max_id = 0;
|
||||||
|
|
||||||
// let's do some data massaging
|
// let's do some data massaging
|
||||||
mysql_query("BEGIN");
|
mysql_query("BEGIN");
|
||||||
try{
|
try{
|
||||||
@ -68,6 +70,7 @@ function db_update_195_post(){
|
|||||||
"`superuser` = '$superuser', " .
|
"`superuser` = '$superuser', " .
|
||||||
"`year` = $year " .
|
"`year` = $year " .
|
||||||
"WHERE username = '$username'";
|
"WHERE username = '$username'";
|
||||||
|
//echo $query . "\n";
|
||||||
if(!mysql_query($updateQuery)){
|
if(!mysql_query($updateQuery)){
|
||||||
throw new Exception("Error on query \"$updateQuery\":\n\n" . mysql_error());
|
throw new Exception("Error on query \"$updateQuery\":\n\n" . mysql_error());
|
||||||
}
|
}
|
||||||
@ -76,15 +79,18 @@ function db_update_195_post(){
|
|||||||
|
|
||||||
}else{
|
}else{
|
||||||
echo "Creating a new record for uid $uid ($username)\n";
|
echo "Creating a new record for uid $uid ($username)\n";
|
||||||
|
$accounts_id = $uid;
|
||||||
|
|
||||||
$newAccountQuery = "INSERT INTO accounts (`username`, `password`, `email`, `pendingemail`, `superuser`, `year`) ";
|
$newAccountQuery = "INSERT INTO accounts (`id`, `username`, `password`, `email`, `pendingemail`, `superuser`, `year`) ";
|
||||||
$newAccountQuery .= "VALUES ('$username', '$password', '$email', '$pendingemail', '$superuser', $year)";
|
$newAccountQuery .= "VALUES ('$accounts_id', '$username', '$password', '$email', '$pendingemail', '$superuser', $year)";
|
||||||
if(mysql_query($newAccountQuery)){
|
//echo $newAccountQuery . "\n";
|
||||||
$accounts_id = mysql_insert_id();
|
if(!mysql_query($newAccountQuery)){
|
||||||
}else{
|
// $accounts_id = mysql_insert_id();
|
||||||
|
// }else{
|
||||||
throw new Exception("Error on query \"$newAccountQuery\":\n\n" . mysql_error());
|
throw new Exception("Error on query \"$newAccountQuery\":\n\n" . mysql_error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if($accounts_id > $max_id) $max_id = $accounts_id;
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
Now that we have an account created,
|
Now that we have an account created,
|
||||||
@ -93,8 +99,8 @@ function db_update_195_post(){
|
|||||||
do{
|
do{
|
||||||
// let's set the uid in this record to be the new ID in our accounts table
|
// let's set the uid in this record to be the new ID in our accounts table
|
||||||
$query = "UPDATE users SET uid = $accounts_id WHERE id=" . $userRecord['id'];
|
$query = "UPDATE users SET uid = $accounts_id WHERE id=" . $userRecord['id'];
|
||||||
|
//echo $query . "\n";
|
||||||
if(!mysql_query($query)){
|
if(!mysql_query($query)){
|
||||||
echo $query;
|
|
||||||
throw new Exception("Failed on updating users table for userid {$userRecord['id']}");
|
throw new Exception("Failed on updating users table for userid {$userRecord['id']}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +137,7 @@ function db_update_195_post(){
|
|||||||
$query = "INSERT INTO user_roles";
|
$query = "INSERT INTO user_roles";
|
||||||
$query .= ' (' . implode(', ', array_keys($params)) . ')';
|
$query .= ' (' . implode(', ', array_keys($params)) . ')';
|
||||||
$query .= ' VALUES ("' . implode('", "', array_values($params)) . '")';
|
$query .= ' VALUES ("' . implode('", "', array_values($params)) . '")';
|
||||||
|
//echo $query . "\n";
|
||||||
mysql_query($query);
|
mysql_query($query);
|
||||||
|
|
||||||
// now we need to take all of their role data and insert it into users:
|
// now we need to take all of their role data and insert it into users:
|
||||||
@ -145,6 +152,7 @@ function db_update_195_post(){
|
|||||||
$query .= "'";
|
$query .= "'";
|
||||||
}
|
}
|
||||||
$query .= " WHERE id = " . $userRecord['id'];
|
$query .= " WHERE id = " . $userRecord['id'];
|
||||||
|
//echo $query . "\n";
|
||||||
if(!mysql_query($query)){
|
if(!mysql_query($query)){
|
||||||
throw new exception("ERROR with query:\n$query\n");
|
throw new exception("ERROR with query:\n$query\n");
|
||||||
}
|
}
|
||||||
@ -166,6 +174,7 @@ function db_update_195_post(){
|
|||||||
|
|
||||||
// now that the account records have all been created, we can delete any user records that have a year of zero
|
// now that the account records have all been created, we can delete any user records that have a year of zero
|
||||||
mysql_query("DELETE FROM users WHERE year = 0");
|
mysql_query("DELETE FROM users WHERE year = 0");
|
||||||
|
mysql_query("ALTER TABLE accounts AUTO_INCREMENT = " . ($max_id + 1));
|
||||||
|
|
||||||
mysql_query("COMMIT");
|
mysql_query("COMMIT");
|
||||||
}catch(Exception $e){
|
}catch(Exception $e){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user