forked from science-ation/science-ation
Add a 149 update script to convert emergency contacts to parents
And update the 146 user inc so we can just use that instead of having to make another new one
This commit is contained in:
parent
3632e29b6a
commit
f165f39870
@ -257,7 +257,7 @@ function db146_user_load_by_email($email)
|
||||
{
|
||||
/* Find the most recent uid for the email, regardless of deleted status */
|
||||
$e = mysql_real_escape_string($email);
|
||||
$q = mysql_query("SELECT uid FROM users WHERE email='$e' ORDER BY year DESC LIMIT 1");
|
||||
$q = mysql_query("SELECT uid FROM users WHERE email='$e' OR username='$e' ORDER BY year DESC LIMIT 1");
|
||||
|
||||
if(mysql_num_rows($q) == 1) {
|
||||
$i = mysql_fetch_assoc($q);
|
||||
@ -707,6 +707,9 @@ function db146_user_create($type, $username, $u = NULL)
|
||||
VALUES ('$type','$username','0000-00-00', NOW(), '{$config['FAIRYEAR']}')");
|
||||
echo mysql_error();
|
||||
$uid = mysql_insert_id();
|
||||
if(db146_user_valid_email($username)) {
|
||||
mysql_query("UPDATE users SET email='$username' WHERE id='$uid'");
|
||||
}
|
||||
mysql_query("UPDATE users SET uid='$uid' WHERE id='$uid'");
|
||||
echo mysql_error();
|
||||
db146_user_set_password($uid, NULL);
|
||||
|
48
db/db.update.149.php
Normal file
48
db/db.update.149.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?
|
||||
//146 user inc works fine here
|
||||
include "db.update.146.inc.php";
|
||||
|
||||
function db_update_142_post() {
|
||||
$q=mysql_query("SELECT * FROM emergencycontact");
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
$relation=strtolower(trim($r->relation));
|
||||
if( levenshtein('parent',$relation)<2
|
||||
|| levenshtein('mother',$relation)<3
|
||||
|| levenshtein('father',$relation)<3
|
||||
|| levenshtein('mom',$relation)<2
|
||||
|| levenshtein('mere',$relation)<2
|
||||
|| levenshtein('dad',$relation)<2
|
||||
|| levenshtein('pere',$relation)<2
|
||||
|| strstr($relation,'dad')
|
||||
|| strstr($relation,'mom')
|
||||
|| (strstr($relation,"mother") && !strstr($relation,"grand"))
|
||||
|| (strstr($relation,"father") && !strstr($relation,"grand"))
|
||||
)
|
||||
{
|
||||
echo "YES: $r->firstname $r->lastname with relation '$r->relation' looks like a parent\n";
|
||||
if($r->email) {
|
||||
echo " Have email, creating record - $r->email\n";
|
||||
if($u=db146_user_load_by_email($r->email)) {
|
||||
echo "This user already exists, linking parent record to their account!";
|
||||
db146_user_create("parent",$r->email,$u);
|
||||
}
|
||||
else {
|
||||
echo "Creating new parent record\n";
|
||||
$u=db146_user_create("parent",$r->email);
|
||||
$u['firstname']=$r->firstname;
|
||||
$u['lastname']=$r->lastname;
|
||||
$u['phonehome']=$r->phone1;
|
||||
$u['phonework']=$r->phone2;
|
||||
db146_user_save($u);
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "No email address, skipping";
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "NO: $r->firstname $r->lastname with relation '$r->relation' is NOT a parent\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
0
db/db.update.149.sql
Normal file
0
db/db.update.149.sql
Normal file
Loading…
x
Reference in New Issue
Block a user