science-ation/db/db.update.149.php
james f165f39870 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
2009-10-22 19:54:53 +00:00

49 lines
1.5 KiB
PHP

<?
//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";
}
}
}
?>