From c7984104a131da5a7b69a359a30ca2bb232cd548 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 16 Sep 2016 13:57:34 -0400 Subject: [PATCH] JBAS-1586 Student account gen scripts support --teacher * Using new Teacher Ecard profile * 10-year expire * Default to 1900-01-01 DoB. * Slightly modified alert message * Insert 't' between district code and ID in the barcode. sftp-client-agent.sh treats all CSV files with 'teacher' in the filename as teacher files. Signed-off-by: Bill Erickson --- .../import_students/generate-patrons-from-csv.pl | 27 ++++++++++++++++++---- .../import_students/sftp-client-agent.sh | 8 ++++++- 2 files changed, 29 insertions(+), 6 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 da28863588..5d030adda8 100755 --- a/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl +++ b/KCLS/utility-scripts/import_students/generate-patrons-from-csv.pl @@ -14,6 +14,7 @@ use OpenILS::Utils::KCLSNormalize; my $syslog_facility = 'LOCAL6'; # matches Evergreen gateway my $syslog_ops = 'pid'; my $profile = 901; # "Student Ecard" +my $t_profile = 902; # "Teacher Ecard" my $c_profile = 902; # "Classroom Databases" my $net_access = 101; # No Access my $ident_type = 101; # "Sch-district file" ident type @@ -21,6 +22,7 @@ my $c_ident_type = 3; # ident type "Other" my $c_ident_value = "KCLS generated"; my $syslog_ident = 'ECARD'; my $alert_msg = 'Student Ecard: No physical checkouts. No computer/printing. No laptops.'; +my $t_alert_msg = 'Teacher Ecard: No physical checkouts. No computer/printing. No laptops.'; my $c_alert_msg = 'Classroom use only: No physical checkouts. No computer/printing. No laptops.'; my $alert2_msg = 'DO NOT MERGE OR EDIT. RECORD MANAGED CENTRALLY.'; my $alert_type = 20; # "Alerting note, no Blocks" standing penalty @@ -72,6 +74,7 @@ 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 $is_teacher = 0; my $is_classroom = 0; my $purge_all = 0; my $out_dir = '.'; @@ -90,6 +93,7 @@ GetOptions( 'commit-mode=s' => \$commit_mode, 'purge-all' => \$purge_all, 'default-pass=s' => \$default_pass, + 'teacher' => \$is_teacher, 'classroom' => \$is_classroom, 'log-stdout' => \$log_stdout, 'out-dir=s' => \$out_dir, @@ -115,6 +119,12 @@ Options: --district-code 3-character school district code. + --teacher + Process CSV file entries as teacher accounts. + + --classroom + Process CSV file entries as classroom accounts. + --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 @@ -241,7 +251,9 @@ sub iterate_csv_rows { $csv->column_names($csv->fields); while (my $phash = $csv->getline_hr($fh)) { - $phash->{barcode} = $district_code . $phash->{student_id}; + # Teacher cards have an extra 't' between district code and ID. + $phash->{barcode} = $district_code . + ($is_teacher ? 't' : '') . $phash->{student_id}; $row_handler->($phash); } @@ -300,7 +312,7 @@ sub set_expire_date { my $now_date = DateTime->now; my $now_year = $now_date->year; - if ($is_classroom) { + if ($is_classroom || $is_teacher) { # classroom cards expire after 10 years. $now_date->set_year($now_year + 10); $phash->{expire_date} = $now_date; @@ -369,6 +381,11 @@ sub translate_patron_fields { $phash->{$_} =~ s/(^\s*|\s*$)//g if $phash->{$_}; } + # Apply default DoB for classroom / teacher cards. + if ($is_classroom || $is_teacher) { + $phash->{dob} = '1900-01-01' unless $phash->{dob}; + } + my @required = qw/student_id first_given_name family_name dob/; # check required fields @@ -590,8 +607,8 @@ sub create_patron { my $barcode = $phash->{barcode}; my @user_bind = ( - $is_classroom ? 'f' : 't', - $is_classroom ? $c_profile : $profile, + ($is_classroom || $is_teacher) ? 'f' : 't', + $is_classroom ? $c_profile : ($is_teacher ? $t_profile : $profile), $is_classroom ? $c_ident_type : $ident_type, $barcode, $home_ou, $net_access, $phash->{passwd}, @@ -621,7 +638,7 @@ sub create_patron { my @alrt_bind = ( $root_org, $alert_type, - $is_classroom ? $c_alert_msg : $alert_msg + $is_classroom ? $c_alert_msg : ($is_teacher ? $t_alert_msg : $alert_msg) ); my @alrt2_bind = ( diff --git a/KCLS/utility-scripts/import_students/sftp-client-agent.sh b/KCLS/utility-scripts/import_students/sftp-client-agent.sh index 76025e55cb..91f3cfd8c4 100755 --- a/KCLS/utility-scripts/import_students/sftp-client-agent.sh +++ b/KCLS/utility-scripts/import_students/sftp-client-agent.sh @@ -141,9 +141,15 @@ for code in "${DISTRICT_CODES[@]}"; do announce "Retrieving file $FILE" $SCP:$FILE $LOCAL_FILE + TEACHER_FLAG="" + if [[ $LOCAL_FILE =~ 'teacher' ]]; then + announce "Processing a teacher file" + TEACHER_FLAG="--teacher" + fi + announce "Processing file $LOCAL_FILE" INFO=$(perl ./generate-patrons-from-csv.pl \ - --log-stdout \ + --log-stdout $TEACHER_FLAG \ --db-host $DB_HOST \ --district-code $code \ --commit-mode each \ -- 2.11.0