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 39-44 my $help; Link Here
39
my @preserve_fields;
39
my @preserve_fields;
40
my $update_dateexpiry;
40
my $update_dateexpiry;
41
my $update_dateexpiry_from_today;
41
my $update_dateexpiry_from_today;
42
my $update_dateexpiry_from_existing;
42
43
43
GetOptions(
44
GetOptions(
44
    'c|confirm'                      => \$confirm,
45
    'c|confirm'                      => \$confirm,
Lines 49-54 GetOptions( Link Here
49
    'op|overwrite_passwords'         => \$overwrite_passwords,
50
    'op|overwrite_passwords'         => \$overwrite_passwords,
50
    'ue|update-expiration'           => \$update_dateexpiry,
51
    'ue|update-expiration'           => \$update_dateexpiry,
51
    'et|expiration-from-today'       => \$update_dateexpiry_from_today,
52
    'et|expiration-from-today'       => \$update_dateexpiry_from_today,
53
    'ee|expiration-from-existing'    => \$update_dateexpiry_from_existing,
52
    'en|email-new'                   => \$welcome_new,
54
    'en|email-new'                   => \$welcome_new,
53
    'p|preserve-extended-attributes' => \$ext_preserve,
55
    'p|preserve-extended-attributes' => \$ext_preserve,
54
    'pf|preserve-field=s'            => \@preserve_fields,
56
    'pf|preserve-field=s'            => \@preserve_fields,
Lines 57-62 GetOptions( Link Here
57
) or pod2usage(2);
59
) or pod2usage(2);
58
60
59
pod2usage(1) if $help;
61
pod2usage(1) if $help;
62
pod2usage(q|--ee and --et are mutually exclusive|) if $update_dateexpiry_from_today && $update_dateexpiry_from_existing;
60
pod2usage(q|--file is required|) unless $csv_file;
63
pod2usage(q|--file is required|) unless $csv_file;
61
pod2usage(q|--matchpoint is required|) unless $matchpoint;
64
pod2usage(q|--matchpoint is required|) unless $matchpoint;
62
65
Lines 67-83 open( $handle, "<", $csv_file ) or die $!; Link Here
67
70
68
my $return = $Import->import_patrons(
71
my $return = $Import->import_patrons(
69
    {
72
    {
70
        file                         => $handle,
73
        file                            => $handle,
71
        defaults                     => \%defaults,
74
        defaults                        => \%defaults,
72
        matchpoint                   => $matchpoint,
75
        matchpoint                      => $matchpoint,
73
        overwrite_cardnumber         => $overwrite_cardnumber,
76
        overwrite_cardnumber            => $overwrite_cardnumber,
74
        overwrite_passwords          => $overwrite_passwords,
77
        overwrite_passwords             => $overwrite_passwords,
75
        preserve_extended_attributes => $ext_preserve,
78
        preserve_extended_attributes    => $ext_preserve,
76
        preserve_fields              => \@preserve_fields,
79
        preserve_fields                 => \@preserve_fields,
77
        update_dateexpiry            => $update_dateexpiry,
80
        update_dateexpiry               => $update_dateexpiry,
78
        update_dateexpiry_from_today => $update_dateexpiry_from_today,
81
        update_dateexpiry_from_today    => $update_dateexpiry_from_today,
79
        send_welcome                 => $welcome_new,
82
        update_dateexpiry_from_existing => $update_dateexpiry_from_existing,
80
        dry_run                      => !$confirm,
83
        send_welcome                    => $welcome_new,
84
        dry_run                         => !$confirm,
81
    }
85
    }
82
);
86
);
83
87
Lines 165-170 If a matching patron is found, extend the expiration date of their account using Link Here
165
=item B<-et|--expiration-from-today>
169
=item B<-et|--expiration-from-today>
166
170
167
If a matching patron is found, extend the expiration date of their account using today's date as the base
171
If a matching patron is found, extend the expiration date of their account using today's date as the base
172
Cannot by used in conjunction with --expiration-from-existing
173
174
=item B<-ee|--expiration-from-existing>
175
176
If a matching patron is found, extend the expiration date of their account using the patron's current expiration date as the base
177
Cannot by used in conjunction with --expiration-from-today
168
178
169
=item B<-v|--verbose>
179
=item B<-v|--verbose>
170
180
(-)a/t/db_dependent/Koha/Patrons/Import.t (-1 / +14 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
my $result_3d;
234
# /test update_dateexpiry_from_current
235
223
# Given ... valid file handle, good matchpoint that does not match and conflicting userid.
236
# 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);
237
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: $!";
238
open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!";
(-)a/tools/import_borrowers.pl (-11 / +11 lines)
Lines 117-132 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
117
    my $update_dateexpiry = $input->param('update_dateexpiry');
117
    my $update_dateexpiry = $input->param('update_dateexpiry');
118
    my $return = $Import->import_patrons(
118
    my $return = $Import->import_patrons(
119
        {
119
        {
120
            file                         => $handle,
120
            file                            => $handle,
121
            defaults                     => \%defaults,
121
            defaults                        => \%defaults,
122
            matchpoint                   => $matchpoint,
122
            matchpoint                      => $matchpoint,
123
            overwrite_cardnumber         => scalar $input->param( 'overwrite_cardnumber' ),
123
            overwrite_cardnumber            => scalar $input->param('overwrite_cardnumber'),
124
            overwrite_passwords          => $overwrite_passwords,
124
            overwrite_passwords             => $overwrite_passwords,
125
            preserve_extended_attributes => scalar $input->param( 'ext_preserve' ) || 0,
125
            preserve_extended_attributes    => scalar $input->param('ext_preserve') || 0,
126
            preserve_fields              => \@preserve_fields,
126
            preserve_fields                 => \@preserve_fields,
127
            update_dateexpiry            => $update_dateexpiry ? 1 : 0,
127
            update_dateexpiry               => $update_dateexpiry ? 1 : 0,
128
            update_dateexpiry_from_today => $update_dateexpiry eq "now" ? 1 : 0,
128
            update_dateexpiry_from_today    => $update_dateexpiry eq "now" ? 1 : 0,
129
            send_welcome                 => $welcome_new,
129
            update_dateexpiry_from_existing => $update_dateexpiry eq "dateexpiry" ? 1 : 0,
130
            send_welcome                    => $welcome_new,
130
        }
131
        }
131
    );
132
    );
132
133
133
- 

Return to bug 34621