From f37c765de1696dd96d5e4c246d1ba8d123e83af1 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 16 Oct 2017 10:38:27 -0400 Subject: [PATCH] Student importer too-many-new warning 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 --- .../import_students/generate-patrons-from-csv.pl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 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 f36903c41b..903a5c94ff 100755 --- a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl +++ b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl @@ -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; -- 2.11.0