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

(-)a/Koha/Patrons/Import.pm (-8 / +15 lines)
Lines 68-80 sub import_patrons { Link Here
68
    my $handle = $params->{file};
68
    my $handle = $params->{file};
69
    unless( $handle ) { carp('No file handle passed in!'); return; }
69
    unless( $handle ) { carp('No file handle passed in!'); return; }
70
70
71
    my $matchpoint           = $params->{matchpoint};
71
    my $matchpoint                   = $params->{matchpoint};
72
    my $defaults             = $params->{defaults};
72
    my $defaults                     = $params->{defaults};
73
    my $preserve_fields      = $params->{preserve_fields};
73
    my $preserve_fields              = $params->{preserve_fields};
74
    my $ext_preserve         = $params->{preserve_extended_attributes};
74
    my $update_dateexpiry            = $params->{update_dateexpiry};
75
    my $overwrite_cardnumber = $params->{overwrite_cardnumber};
75
    my $update_dateexpiry_from_today = $params->{update_dateexpiry_from_today};
76
    my $overwrite_passwords  = $params->{overwrite_passwords};
76
    my $ext_preserve                 = $params->{preserve_extended_attributes};
77
    my $dry_run              = $params->{dry_run};
77
    my $overwrite_cardnumber         = $params->{overwrite_cardnumber};
78
    my $overwrite_passwords          = $params->{overwrite_passwords};
79
    my $dry_run                      = $params->{dry_run};
78
    my $extended             = C4::Context->preference('ExtendedPatronAttributes');
80
    my $extended             = C4::Context->preference('ExtendedPatronAttributes');
79
    my $set_messaging_prefs  = C4::Context->preference('EnhancedMessagingPreferences');
81
    my $set_messaging_prefs  = C4::Context->preference('EnhancedMessagingPreferences');
80
82
Lines 168-174 sub import_patrons { Link Here
168
170
169
        # Default date enrolled and date expiry if not already set.
171
        # Default date enrolled and date expiry if not already set.
170
        $borrower{dateenrolled} = $self->today_iso() unless $borrower{dateenrolled};
172
        $borrower{dateenrolled} = $self->today_iso() unless $borrower{dateenrolled};
171
        $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ) unless $borrower{dateexpiry};
173
        my $expiration_start_date = $update_dateexpiry_from_today ? dt_from_string : $borrower{dateenrolled};
174
        $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $expiration_start_date ) unless $borrower{dateexpiry};
172
175
173
        my $borrowernumber;
176
        my $borrowernumber;
174
        my ( $member, $patron );
177
        my ( $member, $patron );
Lines 265-270 sub import_patrons { Link Here
265
                }
268
                }
266
            }
269
            }
267
270
271
            my $expiration_start_date = $update_dateexpiry_from_today ? dt_from_string : $borrower{dateenrolled};
272
            $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )
273
                                      ->get_expiry_date( $expiration_start_date ) if $update_dateexpiry;
274
268
            for my $col ( keys %borrower ) {
275
            for my $col ( keys %borrower ) {
269
276
270
                # use values from extant patron unless our csv file includes this column or we provided a default.
277
                # 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 (-1 / +11 lines)
Lines 322-328 Link Here
322
                        <li>
322
                        <li>
323
                            <input class="overwrite_passwords" type="checkbox" id="overwrite_passwords" name="overwrite_passwords" disabled/>
323
                            <input class="overwrite_passwords" type="checkbox" id="overwrite_passwords" name="overwrite_passwords" disabled/>
324
                            <label class="overwrite_passwords" for="overwrite_passwords">Replace patron passwords with those in the file (blank passwords will be ignored)</label>
324
                            <label class="overwrite_passwords" for="overwrite_passwords">Replace patron passwords with those in the file (blank passwords will be ignored)</label>
325
                        </li
325
                        </li>
326
                        <li>
327
                            <input class="update_dateexpiry" type="checkbox" id="update_dateexpiry" name="update_dateexpiry" disabled/>
328
                            <label class="update_dateexpiry" for="update_dateexpiry">Update existing patron expiration dates.</label>
329
                        </li>
330
                        <li>
331
                            <input class="update_dateexpiry_from_today" type="checkbox" id="update_dateexpiry_from_today" name="update_dateexpiry_from_today" disabled/>
332
                            <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>
333
                        </li>
326
                    </ul>
334
                    </ul>
327
                </li>
335
                </li>
328
            </ol>
336
            </ol>
Lines 426-434 you can supply dates in ISO format (e.g., '2010-10-28'). Link Here
426
434
427
        $("#overwrite_cardnumberno").click(function(){
435
        $("#overwrite_cardnumberno").click(function(){
428
            $("#overwrite_passwords").prop('checked',false).prop('disabled',true);
436
            $("#overwrite_passwords").prop('checked',false).prop('disabled',true);
437
            $("#update_dateexpiry").prop('checked',false).prop('disabled',true);
429
        });
438
        });
430
        $("#overwrite_cardnumberyes").click(function(){
439
        $("#overwrite_cardnumberyes").click(function(){
431
            $("#overwrite_passwords").prop('disabled',false);
440
            $("#overwrite_passwords").prop('disabled',false);
441
            $("#update_dateexpiry").prop('disabled',false);
432
        });
442
        });
433
    </script>
443
    </script>
434
[% END %]
444
[% END %]
(-)a/misc/import_patrons.pl (-1 / +15 lines)
Lines 36-41 my $confirm; Link Here
36
my $verbose      = 0;
36
my $verbose      = 0;
37
my $help;
37
my $help;
38
my @preserve_fields;
38
my @preserve_fields;
39
my $update_dateexpiry;
40
my $update_dateexpiry_from_today;
39
41
40
GetOptions(
42
GetOptions(
41
    'c|confirm'                      => \$confirm,
43
    'c|confirm'                      => \$confirm,
Lines 44-49 GetOptions( Link Here
44
    'd|default=s'                    => \%defaults,
46
    'd|default=s'                    => \%defaults,
45
    'o|overwrite'                    => \$overwrite_cardnumber,
47
    'o|overwrite'                    => \$overwrite_cardnumber,
46
    'op|overwrite_passwords'         => \$overwrite_passwords,
48
    'op|overwrite_passwords'         => \$overwrite_passwords,
49
    'ue|update-expiration'           => \$update_dateexpiry,
50
    'et|expiration-from-today'       => \$update_dateexpiry_from_today,
47
    'p|preserve-extended-attributes' => \$ext_preserve,
51
    'p|preserve-extended-attributes' => \$ext_preserve,
48
    'pf|preserve-field=s'            => \@preserve_fields,
52
    'pf|preserve-field=s'            => \@preserve_fields,
49
    'v|verbose+'                     => \$verbose,
53
    'v|verbose+'                     => \$verbose,
Lines 68-73 my $return = $Import->import_patrons( Link Here
68
        overwrite_passwords          => $overwrite_passwords,
72
        overwrite_passwords          => $overwrite_passwords,
69
        preserve_extended_attributes => $ext_preserve,
73
        preserve_extended_attributes => $ext_preserve,
70
        preserve_fields              => \@preserve_fields,
74
        preserve_fields              => \@preserve_fields,
75
        update_dateexpiry            => $update_dateexpiry
76
        update_dateexpiry_from_today => $update_dateexpiry_from_today
71
        dry_run                      => !$confirm,
77
        dry_run                      => !$confirm,
72
    }
78
    }
73
);
79
);
Lines 107-113 import_patrons.pl - CLI script to import patrons data into Koha Link Here
107
113
108
=head1 SYNOPSIS
114
=head1 SYNOPSIS
109
115
110
import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve_field <column>] [--preserve-extended-attributes] [--verbose]
116
import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve_field <column>] [--preserve-extended-attributes] [--update-expiration] [--verbose]
111
117
112
=head1 OPTIONS
118
=head1 OPTIONS
113
119
Lines 145-150 Overwrite existing patrons with new data if a match is found Link Here
145
151
146
Retain extended patron attributes for existing patrons being overwritten
152
Retain extended patron attributes for existing patrons being overwritten
147
153
154
=item B<-ue|--update-expiration>
155
156
If a matching patron is found, extend the expiration date of their account using the patron's enrollment date as the base
157
158
=item B<-et|--expiration-from-today>
159
160
If a matching patron is found, extend the expiration date of their account using the patron's enrollment date as the base
161
148
=item B<-v|--verbose>
162
=item B<-v|--verbose>
149
163
150
Be verbose
164
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 => 173;
21
use Test::More tests => 175;
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 120-125 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
120
    my $handle   = $input->upload('uploadborrowers');
120
    my $handle   = $input->upload('uploadborrowers');
121
    my %defaults = $input->Vars;
121
    my %defaults = $input->Vars;
122
    my $overwrite_passwords = defined $input->param('overwrite_passwords') ? 1 : 0;
122
    my $overwrite_passwords = defined $input->param('overwrite_passwords') ? 1 : 0;
123
    my $update_dateexpiry = defined $input->param('update_dateexpiry') ? 1 : 0;
124
    my $update_dateexpiry_from_today = defined $input->param('update_dateexpiry_from_today') ? 1 : 0;
123
    my $return = $Import->import_patrons(
125
    my $return = $Import->import_patrons(
124
        {
126
        {
125
            file                         => $handle,
127
            file                         => $handle,
Lines 129-134 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
129
            overwrite_passwords          => $overwrite_passwords,
131
            overwrite_passwords          => $overwrite_passwords,
130
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
132
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
131
            preserve_fields              => \@preserve_fields,
133
            preserve_fields              => \@preserve_fields,
134
            update_dateexpiry            => $update_dateexpiry,
135
            update_dateexpiry_from_today => $update_dateexpiry_from_today,
132
        }
136
        }
133
    );
137
    );
134
138
135
- 

Return to bug 27920