JBAS-886 day_phone capture improvements
authorBill Erickson <berickxx@gmail.com>
Wed, 30 Sep 2015 14:12:53 +0000 (07:12 -0700)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Capture the day_phone value and don't treat invalid phones as an error
condition preventing import of a student.  If an invalid phone is
encountered, treat it as unset.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl

index efec270..c692b5e 100755 (executable)
@@ -359,13 +359,15 @@ sub translate_patron_fields {
     push(@errors, "Invalid dob")
         unless $phash->{dob} =~ m/^\d{4}-\d{2}-\d{2}$/;
 
-    if (my $dp = $phash->{day_phone}) {
+    # we cannot continue if errors have occured at this stage.
+    return @errors if @errors;
 
-        if ($dp =~ /^\(?\d{3}\)?-?\s*-?\s*$/) {
-            # if the day_phone only contains an area code, treat it as unset.
-            $dp = undef;
+    # day_phone is not required, but if it's set,
+    # it has to be in a format we can understand.
+    # If it's malformed, we treat it as unset.
+    if (my $dp = $phash->{day_phone}) {
 
-        } elsif ($dp =~ /^\(?(\d{3})\)?[- \.](\d{3})[- \.](\d{4})$/) {
+        if ($dp =~ /^\(?(\d{3})\)?[- \.](\d{3})[- \.](\d{4})$/) {
 
             # Supported phone formats:
             # XXX-YYY-ZZZZ / (XXX) YYY-ZZZZ / XXX.YYY.ZZZZ
@@ -377,15 +379,11 @@ sub translate_patron_fields {
             $phash->{day_phone} = $dp;
 
         } else {
-            # Phone exists, is more than an area code, but is otherwise
-            # malformed.  Kick it back for repairs.
-            push(@errors, "Invalid day_phone");
+            # Phone exists, but is malformed.
+            $phash->{day_phone} = undef;
         } 
     }
 
-    # we cannot continue if errors have occured at this stage.
-    return @errors if @errors;
-
     # password uses the last 4 characters of the student ID,
     # unless a default password is set.
     $phash->{passwd} = $default_pass ? $default_pass : 
@@ -497,8 +495,6 @@ sub purge_patron {
         return 0;
     }
 
-    announce('DEBUG', "Purging user $bc with ID $user_id");
-
     eval {
         $db_handle->selectrow_array(
             "SELECT actor.usr_delete($user_id, NULL)");
@@ -541,8 +537,9 @@ sub prepare_patron_sql {
         family_name, 
         expire_date, 
         dob,
+        day_phone,
         email
-    ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
+    ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
 SQL
 
     $create_addr_sth = $db_handle->prepare(<<SQL);
@@ -598,6 +595,7 @@ sub create_patron {
         $phash->{family_name}, 
         $phash->{expire_date}, 
         $phash->{dob},
+        $phash->{day_phone},
         $phash->{email},
     );