science-ation/db/db.update.197.php
2010-07-13 03:30:07 +00:00

65 lines
1.9 KiB
PHP

<?
function db_update_197_post()
{
echo "Migrating passwordset and oldpassword data...\n";
$q = mysql_query("SELECT * FROM accounts");
echo mysql_error();
while($a = mysql_fetch_assoc($q)) {
$aid = $a['id'];
$qq = mysql_query("SELECT * FROM users WHERE accounts_id=$aid ORDER BY year DESC LIMIT 1");
echo mysql_error();
if(mysql_num_rows($qq)) {
$u = mysql_fetch_assoc($qq);
$set = $u['passwordset'];
$old = mysql_escape_string($u['oldpassword']);
} else {
$set = '0000-00-00';
$old = '';
}
mysql_query("UPDATE accounts SET passwordset='$set',oldpassword='$old' WHERE id=$aid");
echo mysql_error();
}
echo "Migating conference ID from user_roles to users...\n";
$q = mysql_query("SELECT * FROM users");
echo mysql_error();
while($u = mysql_fetch_assoc($q)) {
$id = $u['id'];
$qq = mysql_query("SELECT * FROM user_roles WHERE users_id=$id LIMIT 1");
echo mysql_error();
if(mysql_num_rows($qq)) {
$r = mysql_fetch_assoc($qq);
mysql_query("UPDATE users SET conferences_id='{$r['conferences_id']}' WHERE id=$id");
echo mysql_error();
} else {
echo " No role data for user $id, skipping\n";
}
}
echo "Migating admin/config access to roles...\n";
$q = mysql_query("SELECT * FROM users");
echo mysql_error();
while($u = mysql_fetch_assoc($q)) {
$id = $u['id'];
$qq = mysql_query("SELECT * FROM user_roles WHERE users_id=$id AND roles_id='2'");
echo mysql_error();
if(mysql_num_rows($qq)) {
/* User has a committee role, add config/admin roles */
if($u['access_admin'] == 'yes') {
mysql_query("INSERT INTO user_roles(`accounts_id`,`users_id`,`roles_id`,`active`,`complete`)
VALUES('{$u['accounts_id']}','$id',12,'yes','yes')");
}
if($u['access_config'] == 'yes') {
mysql_query("INSERT INTO user_roles(`accounts_id`,`users_id`,`roles_id`,`active`,`complete`)
VALUES('{$u['accounts_id']}','$id',13,'yes','yes')");
}
}
}
echo "Done.\n";
}