From eddf7a17049687322546b1816f321f9d61f49b7f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 1 Feb 2016 14:33:13 -0500 Subject: [PATCH] JBAS-1161 Map districts to org units; remove --assume-new 1. District codes are mapped to org unit ID's within the script so the caller does not have to know the org unit. 2. Remove the --assume-new option, since it serves little purpose. Signed-off-by: Bill Erickson --- .../import_students/generate-patrons-from-csv.pl | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 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 25753c96ce..ca91a73323 100755 --- a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl +++ b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl @@ -43,6 +43,13 @@ my %summary_stats = ( delete_err => 0 ); +# map of district code to home org unit id. +my %home_ou_map = ( + 405 => 1492, + 415 => 1520, + 409 => 1527 +); + # pre-prepared sql query statement handles; my $create_user_sth; my $create_addr_sth; @@ -56,7 +63,6 @@ my $home_ou; # home org unit id my $district_code; # 3-char school district code my $default_pass; my $commit_mode = 'rollback'; # single xact, then rollback (for testing) -my $assume_new = 0; my $is_classroom = 0; my $purge_all = 0; my $out_dir = '.'; @@ -73,7 +79,6 @@ GetOptions( 'home-ou=s' => \$home_ou, 'district-code=s' => \$district_code, 'commit-mode=s' => \$commit_mode, - 'assume-new' => \$assume_new, 'purge-all' => \$purge_all, 'default-pass=s' => \$default_pass, 'classroom' => \$is_classroom, @@ -93,18 +98,20 @@ sub help { Processes a patron import CSV file. Student accounts may be created, updated, or deleted. -$0 --log-stdout --home-ou 1492 --district-code 405 --commit-mode each \ +$0 --log-stdout --district-code 405 --commit-mode each \ --db-host testing-db01 Options: - --home-ou - Org unit ID of the home library used for all patrons loaded - in the current file. - --district-code 3-character school district code. + --home-ou + Org unit ID of the home library used for all patrons loaded + in the current file. NOTE: Only use this parameter if the + home org unit for a batch does not match the default org + unit for the selected district code. + --default-pass If set, use this password instead of the last 4 of the student ID. @@ -125,10 +132,6 @@ Options: for production deployments to ensure that all patrons that insert without failure are added to the DB. - --assume-new - Assume all users in the CSV file are new users. No checks will - be made to see if the user already exists in the DB. - --purge-all Ignore any commands in the CSV file and purge (permanently delete) every user represented in the file. This is useful for testing. @@ -180,13 +183,13 @@ sub announce { sub verify_options { help() if $help; # exits - die "--home-ou required\n" unless $home_ou; die "--district-code required\n" unless $district_code; die "CSV file required\n" unless $csv_file = $ARGV[0]; - die "Valid --commit-mode values are 'batch', 'rollback', and 'each'\n" unless $commit_mode =~ /^(batch|rollback|each)$/; + $home_ou = $home_ou_map{$district_code} unless $home_ou; + # Kent students may be as old as 21. $expire_age = 21 if $district_code eq '415'; @@ -249,7 +252,7 @@ sub iterate_csv_rows { # per-row actions (create, update, delete) in the CSV file to clarify # which patrons are new. sub find_new_patrons { - return if $assume_new or $purge_all; # no lookup required. + return if $purge_all; # no lookup required. my @all_barcodes; @@ -484,7 +487,7 @@ sub process_each_patron { return unless translate_patron_data($phash); $summary_stats{trans}++; - if ($assume_new or $new_barcodes{$phash->{barcode}}) { + if ($new_barcodes{$phash->{barcode}}) { create_patron($phash); } else { update_patron($phash); -- 2.11.0