View | Details | Raw Unified | Return to bug 27920
Collapse All | Expand All

(-)a/Koha/Patrons/Import.pm (-1 / +4 lines)
Lines 78-83 sub import_patrons { Link Here
78
    my $send_welcome         = $params->{send_welcome};
78
    my $send_welcome         = $params->{send_welcome};
79
    my $extended             = C4::Context->preference('ExtendedPatronAttributes');
79
    my $extended             = C4::Context->preference('ExtendedPatronAttributes');
80
    my $set_messaging_prefs  = C4::Context->preference('EnhancedMessagingPreferences');
80
    my $set_messaging_prefs  = C4::Context->preference('EnhancedMessagingPreferences');
81
    my $update_dateexpiry            = $params->{update_dateexpiry};
82
    my $update_dateexpiry_from_today = $params->{update_dateexpiry_from_today};
81
83
82
    my $schema = Koha::Database->new->schema;
84
    my $schema = Koha::Database->new->schema;
83
    $schema->storage->txn_begin if $dry_run;
85
    $schema->storage->txn_begin if $dry_run;
Lines 170-176 sub import_patrons { Link Here
170
172
171
        # Default date enrolled and date expiry if not already set.
173
        # Default date enrolled and date expiry if not already set.
172
        $borrower{dateenrolled} = $self->today_iso() unless $borrower{dateenrolled};
174
        $borrower{dateenrolled} = $self->today_iso() unless $borrower{dateenrolled};
173
        $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ) unless $borrower{dateexpiry};
175
        my $expiration_start_date = $update_dateexpiry_from_today ? dt_from_string : $borrower{dateenrolled};
176
        $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $expiration_start_date ) if $update_dateexpiry;
174
177
175
        my $borrowernumber;
178
        my $borrowernumber;
176
        my ( $member, $patron );
179
        my ( $member, $patron );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt (-1 / +11 lines)
Lines 320-326 Link Here
320
                        <li>
320
                        <li>
321
                            <input class="overwrite_passwords" type="checkbox" id="overwrite_passwords" name="overwrite_passwords" disabled/>
321
                            <input class="overwrite_passwords" type="checkbox" id="overwrite_passwords" name="overwrite_passwords" disabled/>
322
                            <label class="overwrite_passwords" for="overwrite_passwords">Replace patron passwords with those in the file (blank passwords will be ignored)</label>
322
                            <label class="overwrite_passwords" for="overwrite_passwords">Replace patron passwords with those in the file (blank passwords will be ignored)</label>
323
                        </li
323
                        </li>
324
                        <li>
325
                            <input class="update_dateexpiry" type="checkbox" id="update_dateexpiry" name="update_dateexpiry" disabled/>
326
                            <label class="update_dateexpiry" for="update_dateexpiry">Update existing patron expiration dates.</label>
327
                        </li>
328
                        <li>
329
                            <input class="update_dateexpiry_from_today" type="checkbox" id="update_dateexpiry_from_today" name="update_dateexpiry_from_today" disabled/>
330
                            <label class="update_dateexpiry_from_today" for="update_dateexpiry_from_today">Update patron's expiration date based on the current date instead of the patron's enrollment date</label>
331
                        </li>
324
                    </ul>
332
                    </ul>
325
                </li>
333
                </li>
326
            </ol>
334
            </ol>
Lines 435-443 you can supply dates in ISO format (e.g., '2010-10-28'). Link Here
435
443
436
        $("#overwrite_cardnumberno").click(function(){
444
        $("#overwrite_cardnumberno").click(function(){
437
            $("#overwrite_passwords").prop('checked',false).prop('disabled',true);
445
            $("#overwrite_passwords").prop('checked',false).prop('disabled',true);
446
            $("#update_dateexpiry").prop('checked',false).prop('disabled',true);
438
        });
447
        });
439
        $("#overwrite_cardnumberyes").click(function(){
448
        $("#overwrite_cardnumberyes").click(function(){
440
            $("#overwrite_passwords").prop('disabled',false);
449
            $("#overwrite_passwords").prop('disabled',false);
450
            $("#update_dateexpiry").prop('disabled',false);
441
        });
451
        });
442
    </script>
452
    </script>
443
[% END %]
453
[% END %]
(-)a/misc/import_patrons.pl (-1 / +15 lines)
Lines 37-42 my $confirm; Link Here
37
my $verbose      = 0;
37
my $verbose      = 0;
38
my $help;
38
my $help;
39
my @preserve_fields;
39
my @preserve_fields;
40
my $update_dateexpiry;
41
my $update_dateexpiry_from_today;
40
42
41
GetOptions(
43
GetOptions(
42
    'c|confirm'                      => \$confirm,
44
    'c|confirm'                      => \$confirm,
Lines 45-50 GetOptions( Link Here
45
    'd|default=s'                    => \%defaults,
47
    'd|default=s'                    => \%defaults,
46
    'o|overwrite'                    => \$overwrite_cardnumber,
48
    'o|overwrite'                    => \$overwrite_cardnumber,
47
    'op|overwrite_passwords'         => \$overwrite_passwords,
49
    'op|overwrite_passwords'         => \$overwrite_passwords,
50
    'ue|update-expiration'           => \$update_dateexpiry,
51
    'et|expiration-from-today'       => \$update_dateexpiry_from_today,
48
    'en|email-new'                   => \$welcome_new,
52
    'en|email-new'                   => \$welcome_new,
49
    'p|preserve-extended-attributes' => \$ext_preserve,
53
    'p|preserve-extended-attributes' => \$ext_preserve,
50
    'pf|preserve-field=s'            => \@preserve_fields,
54
    'pf|preserve-field=s'            => \@preserve_fields,
Lines 70-75 my $return = $Import->import_patrons( Link Here
70
        overwrite_passwords          => $overwrite_passwords,
74
        overwrite_passwords          => $overwrite_passwords,
71
        preserve_extended_attributes => $ext_preserve,
75
        preserve_extended_attributes => $ext_preserve,
72
        preserve_fields              => \@preserve_fields,
76
        preserve_fields              => \@preserve_fields,
77
        update_dateexpiry            => $update_dateexpiry
78
        update_dateexpiry_from_today => $update_dateexpiry_from_today
73
        send_welcome                 => $welcome_new,
79
        send_welcome                 => $welcome_new,
74
        dry_run                      => !$confirm,
80
        dry_run                      => !$confirm,
75
    }
81
    }
Lines 110-116 import_patrons.pl - CLI script to import patrons data into Koha Link Here
110
116
111
=head1 SYNOPSIS
117
=head1 SYNOPSIS
112
118
113
import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve_field <column>] [--preserve-extended-attributes] [--verbose]
119
import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve_field <column>] [--preserve-extended-attributes] [--update-expiration] [--verbose]
114
120
115
=head1 OPTIONS
121
=head1 OPTIONS
116
122
Lines 152-157 Retain extended patron attributes for existing patrons being overwritten Link Here
152
158
153
Send the WELCOME notice email to new users
159
Send the WELCOME notice email to new users
154
160
161
=item B<-ue|--update-expiration>
162
163
If a matching patron is found, extend the expiration date of their account using the patron's enrollment date as the base
164
165
=item B<-et|--expiration-from-today>
166
167
If a matching patron is found, extend the expiration date of their account using the patron's enrollment date as the base
168
155
=item B<-v|--verbose>
169
=item B<-v|--verbose>
156
170
157
Be verbose
171
Be verbose
(-)a/t/db_dependent/Koha/Patrons/Import.t (-2 / +8 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 174;
21
use Test::More tests => 176;
22
use Test::Warn;
22
use Test::Warn;
23
use Test::Exception;
23
use Test::Exception;
24
use Encode qw( encode_utf8 );
24
use Encode qw( encode_utf8 );
Lines 28-33 use utf8; Link Here
28
use Test::MockModule;
28
use Test::MockModule;
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::Patron::Relationships;
30
use Koha::Patron::Relationships;
31
use Koha::DateUtils qw(dt_from_string);
31
32
32
use File::Temp qw(tempfile tempdir);
33
use File::Temp qw(tempfile tempdir);
33
my $temp_dir = tempdir('Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1);
34
my $temp_dir = tempdir('Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1);
Lines 189-195 is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from imp Link Here
189
# overwrite but firstname is not
190
# overwrite but firstname is not
190
my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b);
191
my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b);
191
open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!";
192
open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!";
192
my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ] };
193
my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ], update_dateexpiry => 1, update_dateexpiry_from_today => 1 };
194
195
my $patron_3 = Koha::Patrons->find({ cardnumber => '1000' });
196
is( $patron_3->dateexpiry, '2015-07-01', "Expiration date is correct with update_dateexpiry = false" );
193
197
194
# When ...
198
# When ...
195
my $result_3c;
199
my $result_3c;
Lines 211-216 is($result_3c->{invalid}, 0, 'Got the expected 0 invalid result from import_patr Link Here
211
is($result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched');
215
is($result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched');
212
216
213
my $patron_3c = Koha::Patrons->find({ cardnumber => '1000' });
217
my $patron_3c = Koha::Patrons->find({ cardnumber => '1000' });
218
is( $patron_3c->dateexpiry, dt_from_string->add( months => 99, end_of_month => 'limit' )->ymd, "Expiration date is correct with update_dateexpiry = true" );
219
214
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" );
220
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" );
215
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" );
221
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" );
216
222
(-)a/tools/import_borrowers.pl (-1 / +4 lines)
Lines 118-123 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
118
    my $handle   = $input->upload('uploadborrowers');
118
    my $handle   = $input->upload('uploadborrowers');
119
    my %defaults = $input->Vars;
119
    my %defaults = $input->Vars;
120
    my $overwrite_passwords = defined $input->param('overwrite_passwords') ? 1 : 0;
120
    my $overwrite_passwords = defined $input->param('overwrite_passwords') ? 1 : 0;
121
    my $update_dateexpiry = defined $input->param('update_dateexpiry') ? 1 : 0;
122
    my $update_dateexpiry_from_today = defined $input->param('update_dateexpiry_from_today') ? 1 : 0;
121
    my $return = $Import->import_patrons(
123
    my $return = $Import->import_patrons(
122
        {
124
        {
123
            file                         => $handle,
125
            file                         => $handle,
Lines 127-132 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
127
            overwrite_passwords          => $overwrite_passwords,
129
            overwrite_passwords          => $overwrite_passwords,
128
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
130
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
129
            preserve_fields              => \@preserve_fields,
131
            preserve_fields              => \@preserve_fields,
132
            update_dateexpiry            => $update_dateexpiry,
133
            update_dateexpiry_from_today => $update_dateexpiry_from_today,
130
            send_welcome                 => $welcome_new,
134
            send_welcome                 => $welcome_new,
131
        }
135
        }
132
    );
136
    );
133
- 

Return to bug 27920