@@ -, +, @@ importing patrons --- Koha/Patrons/Import.pm | 3 +++ .../prog/en/modules/tools/import_borrowers.tt | 8 +++++++- misc/import_patrons.pl | 9 ++++++++- t/db_dependent/Koha/Patrons/Import.t | 9 +++++++-- tools/import_borrowers.pl | 2 ++ 5 files changed, 27 insertions(+), 4 deletions(-) --- a/Koha/Patrons/Import.pm +++ a/Koha/Patrons/Import.pm @@ -71,6 +71,7 @@ sub import_patrons { my $matchpoint = $params->{matchpoint}; my $defaults = $params->{defaults}; my $preserve_fields = $params->{preserve_fields}; + my $update_dateexpiry = $params->{update_dateexpiry}; my $ext_preserve = $params->{preserve_extended_attributes}; my $overwrite_cardnumber = $params->{overwrite_cardnumber}; my $overwrite_passwords = $params->{overwrite_passwords}; @@ -264,6 +265,8 @@ sub import_patrons { } } + $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ) if $update_dateexpiry; + for my $col ( keys %borrower ) { # use values from extant patron unless our csv file includes this column or we provided a default. --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt @@ -266,7 +266,11 @@
  • -
  • +
  • + + +
  • @@ -370,9 +374,11 @@ you can supply dates in ISO format (e.g., '2010-10-28'). $("#overwrite_cardnumberno").click(function(){ $("#overwrite_passwords").prop('checked',false).prop('disabled',true); + $("#update_dateexpiry").prop('checked',false).prop('disabled',true); }); $("#overwrite_cardnumberyes").click(function(){ $("#overwrite_passwords").prop('disabled',false); + $("#update_dateexpiry").prop('disabled',false); }); [% END %] --- a/misc/import_patrons.pl +++ a/misc/import_patrons.pl @@ -36,6 +36,7 @@ my $confirm; my $verbose = 0; my $help; my @columns_to_remove; +my $update_dateexpiry; GetOptions( 'c|confirm' => \$confirm, @@ -44,6 +45,7 @@ GetOptions( 'd|default=s' => \%defaults, 'o|overwrite' => \$overwrite_cardnumber, 'op|overwrite_passwords' => \$overwrite_passwords, + 'ue|update_expiration' => \$update_dateexpiry, 'p|preserve-extended-attributes' => \$ext_preserve, 'pf|preserve-field' => \@preserve_fields, 'v|verbose+' => \$verbose, @@ -68,6 +70,7 @@ my $return = $Import->import_patrons( overwrite_passwords => $overwrite_passwords, preserve_extended_attributes => $ext_preserve, preserve_fields => \@preserve_fields, + update_dateexpiry => $update_dateexpiry dry_run => !$confirm, } ); @@ -107,7 +110,7 @@ import_patrons.pl - CLI script to import patrons data into Koha =head1 SYNOPSIS -import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve_field ] [--preserve-extended-attributes] [--verbose] +import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve_field ] [--preserve-extended-attributes] [--update-expiration] [--verbose] =head1 OPTIONS @@ -145,6 +148,10 @@ Overwrite existing patrons with new data if a match is found Retain extended patron attributes for existing patrons being overwritten +=item B<-p|--update-expiration> + +If a matching patron is found, extend the expiration date of their account using the patron's enrollment date as the base + =item B<-v|--verbose> Be verbose --- a/t/db_dependent/Koha/Patrons/Import.t +++ a/t/db_dependent/Koha/Patrons/Import.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 172; +use Test::More tests => 174; use Test::Warn; use Encode qw( encode_utf8 ); use utf8; @@ -188,7 +188,10 @@ is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from imp # overwrite but firstname is not my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b); open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!"; -my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ] }; +my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ], update_dateexpiry => 1 }; + +my $patron_3 = Koha::Patrons->find({ cardnumber => '1000' }); +is( $patron_3->dateexpiry, '2015-07-01', "Expiration date is correct with update_dateexpiry = false" ); # When ... my $result_3c; @@ -210,6 +213,8 @@ is($result_3c->{invalid}, 0, 'Got the expected 0 invalid result from import_patr is($result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); my $patron_3c = Koha::Patrons->find({ cardnumber => '1000' }); +is( $patron_3c->dateexpiry, '2023-03-28', "Expiration date is correct with update_dateexpiry = true" ); + is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" ); is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" ); --- a/tools/import_borrowers.pl +++ a/tools/import_borrowers.pl @@ -120,6 +120,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { my $handle = $input->upload('uploadborrowers'); my %defaults = $input->Vars; my $overwrite_passwords = defined $input->param('overwrite_passwords') ? 1 : 0; + my $update_dateexpiry = defined $input->param('update_dateexpiry') ? 1 : 0; my $return = $Import->import_patrons( { file => $handle, @@ -129,6 +130,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { overwrite_passwords => $overwrite_passwords, preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0, preserve_fields => \@preserve_fields, + update_dateexpiry => $update_dateexpiry, } ); --