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

(-)a/Koha/Patrons/Import.pm (-12 / +19 lines)
Lines 69-86 sub import_patrons { Link Here
69
    my $handle = $params->{file};
69
    my $handle = $params->{file};
70
    unless( $handle ) { carp('No file handle passed in!'); return; }
70
    unless( $handle ) { carp('No file handle passed in!'); return; }
71
71
72
    my $matchpoint           = $params->{matchpoint};
72
    my $matchpoint                      = $params->{matchpoint};
73
    my $defaults             = $params->{defaults};
73
    my $defaults                        = $params->{defaults};
74
    my $preserve_fields      = $params->{preserve_fields};
74
    my $preserve_fields                 = $params->{preserve_fields};
75
    my $ext_preserve         = $params->{preserve_extended_attributes};
75
    my $ext_preserve                    = $params->{preserve_extended_attributes};
76
    my $overwrite_cardnumber = $params->{overwrite_cardnumber};
76
    my $overwrite_cardnumber            = $params->{overwrite_cardnumber};
77
    my $overwrite_passwords  = $params->{overwrite_passwords};
77
    my $overwrite_passwords             = $params->{overwrite_passwords};
78
    my $dry_run              = $params->{dry_run};
78
    my $dry_run                         = $params->{dry_run};
79
    my $send_welcome         = $params->{send_welcome};
79
    my $send_welcome                    = $params->{send_welcome};
80
    my $extended             = C4::Context->preference('ExtendedPatronAttributes');
80
    my $update_dateexpiry               = $params->{update_dateexpiry};
81
    my $set_messaging_prefs  = C4::Context->preference('EnhancedMessagingPreferences');
81
    my $update_dateexpiry_from_today    = $params->{update_dateexpiry_from_today};
82
    my $update_dateexpiry            = $params->{update_dateexpiry};
82
    my $update_dateexpiry_from_existing = $params->{update_dateexpiry_from_existing};
83
    my $update_dateexpiry_from_today = $params->{update_dateexpiry_from_today};
83
84
    my $extended            = C4::Context->preference('ExtendedPatronAttributes');
85
    my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences');
84
86
85
    my $schema = Koha::Database->new->schema;
87
    my $schema = Koha::Database->new->schema;
86
    $schema->storage->txn_begin if $dry_run;
88
    $schema->storage->txn_begin if $dry_run;
Lines 205-210 sub import_patrons { Link Here
205
            }
207
            }
206
        }
208
        }
207
209
210
        if ( $patron && $update_dateexpiry_from_existing ) {
211
            $patron->dateexpiry( Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $patron->dateexpiry ) );
212
            delete $borrower{dateexpiry};
213
        }
214
208
        my $is_new = 0;
215
        my $is_new = 0;
209
        if ($patron) {
216
        if ($patron) {
210
            $member = $patron->unblessed;
217
            $member = $patron->unblessed;
(-)a/misc/import_patrons.pl (-11 / +21 lines)
Lines 40-45 my $help; Link Here
40
my @preserve_fields;
40
my @preserve_fields;
41
my $update_dateexpiry;
41
my $update_dateexpiry;
42
my $update_dateexpiry_from_today;
42
my $update_dateexpiry_from_today;
43
my $update_dateexpiry_from_existing;
43
44
44
my $command_line_options = join( " ", @ARGV );
45
my $command_line_options = join( " ", @ARGV );
45
46
Lines 52-57 GetOptions( Link Here
52
    'op|overwrite_passwords'         => \$overwrite_passwords,
53
    'op|overwrite_passwords'         => \$overwrite_passwords,
53
    'ue|update-expiration'           => \$update_dateexpiry,
54
    'ue|update-expiration'           => \$update_dateexpiry,
54
    'et|expiration-from-today'       => \$update_dateexpiry_from_today,
55
    'et|expiration-from-today'       => \$update_dateexpiry_from_today,
56
    'ee|expiration-from-existing'    => \$update_dateexpiry_from_existing,
55
    'en|email-new'                   => \$welcome_new,
57
    'en|email-new'                   => \$welcome_new,
56
    'p|preserve-extended-attributes' => \$ext_preserve,
58
    'p|preserve-extended-attributes' => \$ext_preserve,
57
    'pf|preserve-field=s'            => \@preserve_fields,
59
    'pf|preserve-field=s'            => \@preserve_fields,
Lines 60-65 GetOptions( Link Here
60
) or pod2usage(2);
62
) or pod2usage(2);
61
63
62
pod2usage(1) if $help;
64
pod2usage(1) if $help;
65
pod2usage(q|--ee and --et are mutually exclusive|) if $update_dateexpiry_from_today && $update_dateexpiry_from_existing;
63
pod2usage(q|--file is required|) unless $csv_file;
66
pod2usage(q|--file is required|) unless $csv_file;
64
pod2usage(q|--matchpoint is required|) unless $matchpoint;
67
pod2usage(q|--matchpoint is required|) unless $matchpoint;
65
68
Lines 74-90 open( $handle, "<", $csv_file ) or die $!; Link Here
74
77
75
my $return = $Import->import_patrons(
78
my $return = $Import->import_patrons(
76
    {
79
    {
77
        file                         => $handle,
80
        file                            => $handle,
78
        defaults                     => \%defaults,
81
        defaults                        => \%defaults,
79
        matchpoint                   => $matchpoint,
82
        matchpoint                      => $matchpoint,
80
        overwrite_cardnumber         => $overwrite_cardnumber,
83
        overwrite_cardnumber            => $overwrite_cardnumber,
81
        overwrite_passwords          => $overwrite_passwords,
84
        overwrite_passwords             => $overwrite_passwords,
82
        preserve_extended_attributes => $ext_preserve,
85
        preserve_extended_attributes    => $ext_preserve,
83
        preserve_fields              => \@preserve_fields,
86
        preserve_fields                 => \@preserve_fields,
84
        update_dateexpiry            => $update_dateexpiry,
87
        update_dateexpiry               => $update_dateexpiry,
85
        update_dateexpiry_from_today => $update_dateexpiry_from_today,
88
        update_dateexpiry_from_today    => $update_dateexpiry_from_today,
86
        send_welcome                 => $welcome_new,
89
        update_dateexpiry_from_existing => $update_dateexpiry_from_existing,
87
        dry_run                      => !$confirm,
90
        send_welcome                    => $welcome_new,
91
        dry_run                         => !$confirm,
88
    }
92
    }
89
);
93
);
90
94
Lines 189-194 If a matching patron is found, extend the expiration date of their account using Link Here
189
=item B<-et|--expiration-from-today>
193
=item B<-et|--expiration-from-today>
190
194
191
If a matching patron is found, extend the expiration date of their account using today's date as the base
195
If a matching patron is found, extend the expiration date of their account using today's date as the base
196
Cannot by used in conjunction with --expiration-from-existing
197
198
=item B<-ee|--expiration-from-existing>
199
200
If a matching patron is found, extend the expiration date of their account using the patron's current expiration date as the base
201
Cannot by used in conjunction with --expiration-from-today
192
202
193
=item B<-v|--verbose>
203
=item B<-v|--verbose>
194
204
(-)a/t/db_dependent/Koha/Patrons/Import.t (-1 / +13 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 => 178;
21
use Test::More tests => 180;
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 220-225 is( $patron_3c->dateexpiry, dt_from_string->add( months => 99, end_of_month => ' Link Here
220
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" );
220
is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" );
221
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" );
221
is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" );
222
222
223
# test update_dateexpiry_from_current
224
my $filename_3d = make_csv($temp_dir, $csv_headers, $csv_one_line_b);
225
open(my $handle_3d, "<", $filename_3d) or die "cannot open < $filename_3: $!";
226
$patron_3c->dateexpiry('1980-01-01')->store();
227
my $params_3d = { file => $handle_3d, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ], update_dateexpiry => 1, update_dateexpiry_from_existing => 1 };
228
warning_is { $patrons_import->import_patrons($params_3d) }
229
    undef,
230
    "No warning raised by import_patrons";
231
$patron_3c = Koha::Patrons->find({ cardnumber => '1000' });
232
is( $patron_3c->dateexpiry, '1988-04-01', "Expiration date is correct with update_dateexpiry_from_existing => 1" );
233
# /test update_dateexpiry_from_current
234
223
# Given ... valid file handle, good matchpoint that does not match and conflicting userid.
235
# Given ... valid file handle, good matchpoint that does not match and conflicting userid.
224
my $filename_3b = make_csv($temp_dir, $csv_headers, $csv_one_line_a);
236
my $filename_3b = make_csv($temp_dir, $csv_headers, $csv_one_line_a);
225
open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!";
237
open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!";
(-)a/tools/import_borrowers.pl (-11 / +11 lines)
Lines 113-128 if ( $op eq 'cud-import' && $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
113
    my $update_dateexpiry = $input->param('update_dateexpiry');
113
    my $update_dateexpiry = $input->param('update_dateexpiry');
114
    my $return = $Import->import_patrons(
114
    my $return = $Import->import_patrons(
115
        {
115
        {
116
            file                         => $handle,
116
            file                            => $handle,
117
            defaults                     => \%defaults,
117
            defaults                        => \%defaults,
118
            matchpoint                   => $matchpoint,
118
            matchpoint                      => $matchpoint,
119
            overwrite_cardnumber         => scalar $input->param( 'overwrite_cardnumber' ),
119
            overwrite_cardnumber            => scalar $input->param('overwrite_cardnumber'),
120
            overwrite_passwords          => $overwrite_passwords,
120
            overwrite_passwords             => $overwrite_passwords,
121
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
121
            preserve_extended_attributes    => scalar $input->param('ext_preserve') || 0,
122
            preserve_fields              => \@preserve_fields,
122
            preserve_fields                 => \@preserve_fields,
123
            update_dateexpiry            => $update_dateexpiry ? 1 : 0,
123
            update_dateexpiry               => $update_dateexpiry ? 1 : 0,
124
            update_dateexpiry_from_today => $update_dateexpiry eq "now" ? 1 : 0,
124
            update_dateexpiry_from_today    => $update_dateexpiry eq "now" ? 1 : 0,
125
            send_welcome                 => $welcome_new,
125
            update_dateexpiry_from_existing => $update_dateexpiry eq "dateexpiry" ? 1 : 0,
126
            send_welcome                    => $welcome_new,
126
        }
127
        }
127
    );
128
    );
128
129
129
- 

Return to bug 34621