- Convert award sources to fair users

This commit is contained in:
dave 2009-09-06 00:07:26 +00:00
parent dbff1e0bbc
commit d91ac62015
2 changed files with 52 additions and 0 deletions

52
db/db.update.129.php Normal file
View File

@ -0,0 +1,52 @@
<?
require_once('../user.inc.php');
function db_update_129_pre()
{
/* Load all external award sources */
$source_map = array();
$q = mysql_query("SELECT * FROM award_sources");
while($r = mysql_fetch_assoc($q)) {
/* Make a user, use the password generator to get
* a random username */
$u = user_create('fair', user_generate_password());
/* Add a Fair Entry */
$name = mysql_escape_string($r['name']);
$url = mysql_escape_string($r['url']);
$website = mysql_escape_string($r['website']);
$username = mysql_escape_string($r['username']);
$password = mysql_escape_string($r['password']);
$en = ($r['enabled'] == 'no') ? 'no' : 'yes';
mysql_query("INSERT INTO fairs (`id`,`name`,`abbrv`,`type`,
`url`,`website`,`username`,`password`,`enable_stats`,
`enable_awards`,`enable_winners`) VALUES (
'', '$name', '', 'ysf', '$url', '$web',
'$username','$password','no','$en','$en')");
/* Link the fair to the user */
$u['fairs_id'] = mysql_insert_id();
/* Record the old sources_id to new sources_id mapping */
$source_map[$r['id']] = $u['fairs_id'];
user_save($u);
}
/* Map all awards to their new source IDs */
$q = mysql_query("SELECT * FROM award_awards");
$keys = array_keys($source_map);
while($r = mysql_fetch_assoc($q)) {
$old_id = $r['award_sources_id'];
if(!in_array($old_id, $keys)) continue;
$qq = mysql_query("UPDATE award_awards SET award_sources_id='{$source_map[$old_id]}'
WHERE id='{$r['id']}'");
}
}
?>

0
db/db.update.129.sql Normal file
View File