Student importer too-many-new warning
authorBill Erickson <berickxx@gmail.com>
Mon, 16 Oct 2017 14:38:27 +0000 (10:38 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Logs a warning message and exits when the number of new students to
import exceeds the configured warning threshold (currently 500).  Such
files can be forcably processed via a new --force-new option.

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

index f36903c..903a5c9 100755 (executable)
@@ -29,6 +29,7 @@ my $alert_type      = 20; # "Alerting note, no Blocks" standing penalty
 my $root_org        = 1; # KCLS org unit for penalty application
 my $expire_age      = 21; 
 my $purge_count     = 0; # useful for local logging
+my $max_new_patrons = 500; # Max number of automatically generated new patrons
 my $db_handle;
 my %new_barcodes;
 my @failures;       # one row per student account that failed for any reason
@@ -84,6 +85,7 @@ my $commit_mode     = 'rollback'; # single xact, then rollback (for testing)
 my $is_teacher      = 0;
 my $is_classroom    = 0;
 my $purge_all       = 0;
+my $force_new       = 0;
 my $out_dir         = '.';
 my $log_stdout      = 0; # copy logs to stdout
 my $help            = 0; # show help message if true
@@ -99,6 +101,7 @@ GetOptions(
     'district-code=s' => \$district_code,
     'commit-mode=s'   => \$commit_mode,
     'purge-all'       => \$purge_all,
+    'force-new'       => \$force_new,
     'default-pass=s'  => \$default_pass,
     'teacher'         => \$is_teacher,
     'classroom'       => \$is_classroom,
@@ -163,6 +166,10 @@ Options:
         every user represented in the file.  This is useful for testing.
         The user will be prompted to continue.  USE WITH CAUTION.
 
+    --force-new
+        Force the creation of new accounts when the number of new accounts
+        exceeds the "too many new accounts" warning threshold.
+
     --out-dir   
         Output directory for status files.  Defaults to current working 
         directory.
@@ -336,8 +343,14 @@ SQL
 
     my $new_barcodes = $db_handle->selectall_arrayref($SQL);
 
-    announce('INFO', "New barcodes query returned ". 
-        scalar(@$new_barcodes) ." new barcodes");
+    my $new_count = scalar(@$new_barcodes);
+    announce('INFO', "New barcodes query returned $new_count new barcodes");
+
+    if ($new_count > $max_new_patrons && !$force_new) {
+        announce('WARNING', "Number of new accounts [$new_count] exceeds ".
+            "warning threshold [$max_new_patrons]. Exiting import. ".
+            "Use --force-new to override", 1);
+    }
 
     # hash-ify for faster lookup when processing each patron
     %new_barcodes = map {$_->[0] => 1} @$new_barcodes;