JBAS-1037 student importer improved error handling
authorBill Erickson <berickxx@gmail.com>
Wed, 16 Dec 2015 21:16:19 +0000 (16:16 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Includes various small fixes, but mainly the ability to report when a
commit call fails, which is primarily important when processing in
batch.

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

index 37a33ce..eb1eff6 100755 (executable)
@@ -481,6 +481,7 @@ sub process_each_patron {
     } elsif ($commit_mode eq 'batch') {
         announce('INFO', "Committing batch transaction");
         eval { $db_handle->commit };
+        announce('ERR', "Unable to commit batch transaction : $@", 1) if $@;
     }
 }
 
@@ -513,9 +514,15 @@ sub purge_patron {
         }
 
     } else {
+        if ($commit_mode eq 'each') {
+            eval { $db_handle->commit };
+            announce('ERR', 
+                "Unable to commit patron purge transaction : $err") 
+                if $err = $@;
+        }
 
-        announce('DEBUG', "User $bc (ID $user_id) successfully purged");
-        eval { $db_handle->commit } if $commit_mode eq 'each';
+        announce('DEBUG', "User $bc (ID $user_id) successfully purged") 
+            unless $err;
     }
 }
 
@@ -663,17 +670,26 @@ sub handle_insert {
     
     if ($final and $rows > 0) {
         # commit the current patron once all required rows are inserted.
-        announce('DEBUG', "Inserted new patron $barcode");
-        eval { $db_handle->commit } if $commit_mode eq 'each';
+
+        my $err;
+        if ($commit_mode eq 'each') {
+            eval { $db_handle->commit };
+            announce('WARNING', 
+                "Unable to commit patron create transaction : $err") 
+                 if $err = $@;
+        }
+
+        announce('DEBUG', "Inserted new patron $barcode") unless $err;
         $summary_stats{create}++;
     } 
 
     return 1;
 }
 
+# Patron updates not supported
 sub update_patron {
     my $phash = shift;
-    announce('INFO', "Modifying patron with barcode " . $phash->{barcode});
+    announce('INFO', "Modifying patron with barcode " . $phash->{barcode});
 }
 
 sub cleanup_db {