From d84bfb17bcd2325755e98a2b7c13d364224ffd41 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 16 Dec 2015 16:16:19 -0500 Subject: [PATCH] JBAS-1037 student importer improved error handling 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 --- .../import_students/generate-patrons-from-csv.pl | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl index 37a33ce25c..eb1eff643b 100755 --- a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl +++ b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl @@ -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 { -- 2.11.0