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['sponsor'] = array('sponsors_id','primary','position','notes');
|
||||
|
||||
$max_id = 0;
|
||||
|
||||
// let's do some data massaging
|
||||
mysql_query("BEGIN");
|
||||
try{
|
||||
@ -68,6 +70,7 @@ function db_update_195_post(){
|
||||
"`superuser` = '$superuser', " .
|
||||
"`year` = $year " .
|
||||
"WHERE username = '$username'";
|
||||
//echo $query . "\n";
|
||||
if(!mysql_query($updateQuery)){
|
||||
throw new Exception("Error on query \"$updateQuery\":\n\n" . mysql_error());
|
||||
}
|
||||
@ -76,15 +79,18 @@ function db_update_195_post(){
|
||||
|
||||
}else{
|
||||
echo "Creating a new record for uid $uid ($username)\n";
|
||||
$accounts_id = $uid;
|
||||
|
||||
$newAccountQuery = "INSERT INTO accounts (`username`, `password`, `email`, `pendingemail`, `superuser`, `year`) ";
|
||||
$newAccountQuery .= "VALUES ('$username', '$password', '$email', '$pendingemail', '$superuser', $year)";
|
||||
if(mysql_query($newAccountQuery)){
|
||||
$accounts_id = mysql_insert_id();
|
||||
}else{
|
||||
$newAccountQuery = "INSERT INTO accounts (`id`, `username`, `password`, `email`, `pendingemail`, `superuser`, `year`) ";
|
||||
$newAccountQuery .= "VALUES ('$accounts_id', '$username', '$password', '$email', '$pendingemail', '$superuser', $year)";
|
||||
//echo $newAccountQuery . "\n";
|
||||
if(!mysql_query($newAccountQuery)){
|
||||
// $accounts_id = mysql_insert_id();
|
||||
// }else{
|
||||
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,
|
||||
@ -93,8 +99,8 @@ function db_update_195_post(){
|
||||
do{
|
||||
// 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'];
|
||||
//echo $query . "\n";
|
||||
if(!mysql_query($query)){
|
||||
echo $query;
|
||||
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 .= ' (' . implode(', ', array_keys($params)) . ')';
|
||||
$query .= ' VALUES ("' . implode('", "', array_values($params)) . '")';
|
||||
//echo $query . "\n";
|
||||
mysql_query($query);
|
||||
|
||||
// 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 .= " WHERE id = " . $userRecord['id'];
|
||||
//echo $query . "\n";
|
||||
if(!mysql_query($query)){
|
||||
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
|
||||
mysql_query("DELETE FROM users WHERE year = 0");
|
||||
mysql_query("ALTER TABLE accounts AUTO_INCREMENT = " . ($max_id + 1));
|
||||
|
||||
mysql_query("COMMIT");
|
||||
}catch(Exception $e){
|
||||
|
Loading…
x
Reference in New Issue
Block a user