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

(-)a/Koha/Patrons/Import.pm (+3 lines)
Lines 71-76 sub import_patrons { Link Here
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 $update_dateexpiry    = $params->{update_dateexpiry};
74
    my $ext_preserve         = $params->{preserve_extended_attributes};
75
    my $ext_preserve         = $params->{preserve_extended_attributes};
75
    my $overwrite_cardnumber = $params->{overwrite_cardnumber};
76
    my $overwrite_cardnumber = $params->{overwrite_cardnumber};
76
    my $overwrite_passwords  = $params->{overwrite_passwords};
77
    my $overwrite_passwords  = $params->{overwrite_passwords};
Lines 264-269 sub import_patrons { Link Here
264
                }
265
                }
265
            }
266
            }
266
267
268
            $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ) if $update_dateexpiry;
269
267
            for my $col ( keys %borrower ) {
270
            for my $col ( keys %borrower ) {
268
271
269
                # use values from extant patron unless our csv file includes this column or we provided a default.
272
                # 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 / +7 lines)
Lines 266-272 Link Here
266
                        <li>
266
                        <li>
267
                            <input class="overwrite_passwords" type="checkbox" id="overwrite_passwords" name="overwrite_passwords" disabled/>
267
                            <input class="overwrite_passwords" type="checkbox" id="overwrite_passwords" name="overwrite_passwords" disabled/>
268
                            <label class="overwrite_passwords" for="overwrite_passwords">Replace patron passwords with those in the file (blank passwords will be ignored)</label>
268
                            <label class="overwrite_passwords" for="overwrite_passwords">Replace patron passwords with those in the file (blank passwords will be ignored)</label>
269
                        </li
269
                        </li>
270
                        <li>
271
                            <input class="update_dateexpiry" type="checkbox" id="update_dateexpiry" name="update_dateexpiry" disabled/>
272
                            <label class="update_dateexpiry" for="update_dateexpiry">Update patron's expiration date based on enrollment date</label>
273
                        </li>
270
                    </ul>
274
                    </ul>
271
                </li>
275
                </li>
272
            </ol>
276
            </ol>
Lines 370-378 you can supply dates in ISO format (e.g., '2010-10-28'). Link Here
370
374
371
        $("#overwrite_cardnumberno").click(function(){
375
        $("#overwrite_cardnumberno").click(function(){
372
            $("#overwrite_passwords").prop('checked',false).prop('disabled',true);
376
            $("#overwrite_passwords").prop('checked',false).prop('disabled',true);
377
            $("#update_dateexpiry").prop('checked',false).prop('disabled',true);
373
        });
378
        });
374
        $("#overwrite_cardnumberyes").click(function(){
379
        $("#overwrite_cardnumberyes").click(function(){
375
            $("#overwrite_passwords").prop('disabled',false);
380
            $("#overwrite_passwords").prop('disabled',false);
381
            $("#update_dateexpiry").prop('disabled',false);
376
        });
382
        });
377
    </script>
383
    </script>
378
[% END %]
384
[% END %]
(-)a/misc/import_patrons.pl (-1 / +8 lines)
Lines 36-41 my $confirm; Link Here
36
my $verbose      = 0;
36
my $verbose      = 0;
37
my $help;
37
my $help;
38
my @columns_to_remove;
38
my @columns_to_remove;
39
my $update_dateexpiry;
39
40
40
GetOptions(
41
GetOptions(
41
    'c|confirm'                      => \$confirm,
42
    'c|confirm'                      => \$confirm,
Lines 44-49 GetOptions( Link Here
44
    'd|default=s'                    => \%defaults,
45
    'd|default=s'                    => \%defaults,
45
    'o|overwrite'                    => \$overwrite_cardnumber,
46
    'o|overwrite'                    => \$overwrite_cardnumber,
46
    'op|overwrite_passwords'         => \$overwrite_passwords,
47
    'op|overwrite_passwords'         => \$overwrite_passwords,
48
    'ue|update_expiration'           => \$update_dateexpiry,
47
    'p|preserve-extended-attributes' => \$ext_preserve,
49
    'p|preserve-extended-attributes' => \$ext_preserve,
48
    'pf|preserve-field'              => \@preserve_fields,
50
    'pf|preserve-field'              => \@preserve_fields,
49
    'v|verbose+'                     => \$verbose,
51
    'v|verbose+'                     => \$verbose,
Lines 68-73 my $return = $Import->import_patrons( Link Here
68
        overwrite_passwords          => $overwrite_passwords,
70
        overwrite_passwords          => $overwrite_passwords,
69
        preserve_extended_attributes => $ext_preserve,
71
        preserve_extended_attributes => $ext_preserve,
70
        preserve_fields              => \@preserve_fields,
72
        preserve_fields              => \@preserve_fields,
73
        update_dateexpiry            => $update_dateexpiry
71
        dry_run                      => !$confirm,
74
        dry_run                      => !$confirm,
72
    }
75
    }
73
);
76
);
Lines 107-113 import_patrons.pl - CLI script to import patrons data into Koha Link Here
107
110
108
=head1 SYNOPSIS
111
=head1 SYNOPSIS
109
112
110
import_patrons.pl --file /path/to/patrons.csv --matchpoint cardnumber --confirm [--default branchcode=MPL] [--overwrite] [--preserve_field <column>] [--preserve-extended-attributes] [--verbose]
113
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
114
112
=head1 OPTIONS
115
=head1 OPTIONS
113
116
Lines 145-150 Overwrite existing patrons with new data if a match is found Link Here
145
148
146
Retain extended patron attributes for existing patrons being overwritten
149
Retain extended patron attributes for existing patrons being overwritten
147
150
151
=item B<-p|--update-expiration>
152
153
If a matching patron is found, extend the expiration date of their account using the patron's enrollment date as the base
154
148
=item B<-v|--verbose>
155
=item B<-v|--verbose>
149
156
150
Be verbose
157
Be verbose
(-)a/t/db_dependent/Koha/Patrons/Import.t (-2 / +7 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 => 172;
21
use Test::More tests => 174;
22
use Test::Warn;
22
use Test::Warn;
23
use Encode qw( encode_utf8 );
23
use Encode qw( encode_utf8 );
24
use utf8;
24
use utf8;
Lines 188-194 is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from imp Link Here
188
# overwrite but firstname is not
188
# overwrite but firstname is not
189
my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b);
189
my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b);
190
open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!";
190
open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!";
191
my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ] };
191
my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ], update_dateexpiry => 1 };
192
193
my $patron_3 = Koha::Patrons->find({ cardnumber => '1000' });
194
is( $patron_3->dateexpiry, '2015-07-01', "Expiration date is correct with update_dateexpiry = false" );
192
195
193
# When ...
196
# When ...
194
my $result_3c;
197
my $result_3c;
Lines 210-215 is($result_3c->{invalid}, 0, 'Got the expected 0 invalid result from import_patr Link Here
210
is($result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched');
213
is($result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched');
211
214
212
my $patron_3c = Koha::Patrons->find({ cardnumber => '1000' });
215
my $patron_3c = Koha::Patrons->find({ cardnumber => '1000' });
216
is( $patron_3c->dateexpiry, '2023-03-28', "Expiration date is correct with update_dateexpiry = true" );
217
213
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" );
218
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" );
214
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" );
219
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" );
215
220
(-)a/tools/import_borrowers.pl (-1 / +2 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;
123
    my $return = $Import->import_patrons(
124
    my $return = $Import->import_patrons(
124
        {
125
        {
125
            file                         => $handle,
126
            file                         => $handle,
Lines 129-134 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
129
            overwrite_passwords          => $overwrite_passwords,
130
            overwrite_passwords          => $overwrite_passwords,
130
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
131
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
131
            preserve_fields              => \@preserve_fields,
132
            preserve_fields              => \@preserve_fields,
133
            update_dateexpiry            => $update_dateexpiry,
132
        }
134
        }
133
    );
135
    );
134
136
135
- 

Return to bug 27920