diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm
index 7d661a4228..6f62cc1a37 100644
--- a/Koha/Patrons/Import.pm
+++ b/Koha/Patrons/Import.pm
@@ -79,6 +79,8 @@ sub import_patrons {
my $send_welcome = $params->{send_welcome};
my $extended = C4::Context->preference('ExtendedPatronAttributes');
my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences');
+ my $update_dateexpiry = $params->{update_dateexpiry};
+ my $update_dateexpiry_from_today = $params->{update_dateexpiry_from_today};
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin if $dry_run;
@@ -171,7 +173,8 @@ sub import_patrons {
# Default date enrolled and date expiry if not already set.
$borrower{dateenrolled} = $self->today_iso() unless $borrower{dateenrolled};
- $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ) unless $borrower{dateexpiry};
+ my $expiration_start_date = $update_dateexpiry_from_today ? dt_from_string : $borrower{dateenrolled};
+ $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $expiration_start_date ) if $update_dateexpiry;
my $borrowernumber;
my ( $member, $patron );
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt
index b96320a0b7..3690784018 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt
@@ -323,7 +323,15 @@
-
+
+
+
+
+
+
+
+
@@ -443,9 +451,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 %]
diff --git a/misc/import_patrons.pl b/misc/import_patrons.pl
index 6dc037d6bb..910a1438c7 100755
--- a/misc/import_patrons.pl
+++ b/misc/import_patrons.pl
@@ -37,6 +37,8 @@ my $confirm;
my $verbose = 0;
my $help;
my @preserve_fields;
+my $update_dateexpiry;
+my $update_dateexpiry_from_today;
GetOptions(
'c|confirm' => \$confirm,
@@ -45,6 +47,8 @@ GetOptions(
'd|default=s' => \%defaults,
'o|overwrite' => \$overwrite_cardnumber,
'op|overwrite_passwords' => \$overwrite_passwords,
+ 'ue|update-expiration' => \$update_dateexpiry,
+ 'et|expiration-from-today' => \$update_dateexpiry_from_today,
'en|email-new' => \$welcome_new,
'p|preserve-extended-attributes' => \$ext_preserve,
'pf|preserve-field=s' => \@preserve_fields,
@@ -70,6 +74,8 @@ my $return = $Import->import_patrons(
overwrite_passwords => $overwrite_passwords,
preserve_extended_attributes => $ext_preserve,
preserve_fields => \@preserve_fields,
+ update_dateexpiry => $update_dateexpiry
+ update_dateexpiry_from_today => $update_dateexpiry_from_today
send_welcome => $welcome_new,
dry_run => !$confirm,
}
@@ -110,7 +116,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
@@ -152,6 +158,14 @@ Retain extended patron attributes for existing patrons being overwritten
Send the WELCOME notice email to new users
+=item B<-ue|--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<-et|--expiration-from-today>
+
+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
diff --git a/t/db_dependent/Koha/Patrons/Import.t b/t/db_dependent/Koha/Patrons/Import.t
index bf16c1e118..aaaf167213 100755
--- a/t/db_dependent/Koha/Patrons/Import.t
+++ b/t/db_dependent/Koha/Patrons/Import.t
@@ -18,7 +18,7 @@
# along with Koha; if not, see .
use Modern::Perl;
-use Test::More tests => 174;
+use Test::More tests => 176;
use Test::Warn;
use Test::Exception;
use Encode qw( encode_utf8 );
@@ -28,6 +28,7 @@ use utf8;
use Test::MockModule;
use Koha::Database;
use Koha::Patron::Relationships;
+use Koha::DateUtils qw(dt_from_string);
use File::Temp qw(tempfile tempdir);
my $temp_dir = tempdir('Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1);
@@ -189,7 +190,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, update_dateexpiry_from_today => 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;
@@ -211,6 +215,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, dt_from_string->add( months => 99, end_of_month => 'limit' )->ymd, "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" );
diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl
index 995801cb47..da932523b4 100755
--- a/tools/import_borrowers.pl
+++ b/tools/import_borrowers.pl
@@ -114,6 +114,8 @@ 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 $update_dateexpiry_from_today = defined $input->param('update_dateexpiry_from_today') ? 1 : 0;
my $return = $Import->import_patrons(
{
file => $handle,
@@ -123,6 +125,8 @@ 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,
+ update_dateexpiry_from_today => $update_dateexpiry_from_today,
send_welcome => $welcome_new,
}
);