From 703a4611c94992a23a66456fe0d6ea48e761ba03 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 10 Jan 2017 18:08:44 -0500 Subject: [PATCH] JBAS-1717 Student card processor ignores duplicate IDs Signed-off-by: Bill Erickson --- .../import_students/generate-patrons-from-csv.pl | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 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 45c7203156..3244841fb3 100755 --- a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl +++ b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl @@ -256,14 +256,16 @@ sub iterate_csv_rows { $csv->column_names($csv->fields); - my $skipped = 0; + my %seen; while (my $phash = $csv->getline_hr($fh)) { - if (!$phash->{student_id}) { $skipped++; next; } + next unless $phash->{student_id}; - # Remove any non-alphanumeric characters. + # Remove all non-alphanumeric characters. $phash->{student_id} =~ s/[^\w]//oag; + next unless $phash->{student_id}; + # If the ID value is less than 4 characters, pad the value # with zeros to be 4 characters long. This will effect # the barcode and password. Only do this for teacher accounts. @@ -271,11 +273,17 @@ sub iterate_csv_rows { if $is_teacher && length($phash->{student_id}) < 4; # All teacher ID's, which can be alpha-numeric, are upper case. + # Student ID's can also be alpha-numeric, but remain in the + # provided case. $phash->{student_id} = uc($phash->{student_id}) if $is_teacher; - # Teacher cards have an extra 't' between district code and ID. - $phash->{barcode} = $district_code . - ($is_teacher ? 't' : '') . $phash->{student_id}; + # Avoid processing duplicates + next if $seen{$phash->{student_id}}; + $seen{$phash->{student_id}} = 1; + + $phash->{barcode} = $district_code; + $phash->{barcode} .= 't' if $is_teacher; + $phash->{barcode} .= $phash->{student_id}; $row_handler->($phash); } @@ -286,8 +294,6 @@ sub iterate_csv_rows { } $fh->close; - - announce('WARNING', "$skipped entries had no student_id") if $skipped; } # Determine which patrons in the file are new by testing whether their @@ -306,7 +312,7 @@ sub find_new_patrons { iterate_csv_rows($row_handler); - announce('INFO', "File contains ".scalar(@all_barcodes)." total students"); + announce('INFO', "File contains ".scalar(@all_barcodes)." unique students"); my $all_barcodes = join(',', @all_barcodes); -- 2.11.0