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

(-)a/Koha/Patrons/Import.pm (-6 / +8 lines)
Lines 138-144 sub import_patrons { Link Here
138
        # Popular spreadsheet applications make it difficult to force date outputs to be zero-padded, but we require it.
138
        # Popular spreadsheet applications make it difficult to force date outputs to be zero-padded, but we require it.
139
        $self->format_dates({borrower => \%borrower, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals, });
139
        $self->format_dates({borrower => \%borrower, lineraw => $borrowerline, line => $line_number, missing_criticals => \@missing_criticals, });
140
140
141
142
        if (@missing_criticals) {
141
        if (@missing_criticals) {
143
            foreach (@missing_criticals) {
142
            foreach (@missing_criticals) {
144
                $_->{borrowernumber} = $borrower{borrowernumber} || 'UNDEF';
143
                $_->{borrowernumber} = $borrower{borrowernumber} || 'UNDEF';
Lines 190-200 sub import_patrons { Link Here
190
            next;
189
            next;
191
        }
190
        }
192
191
193
        # generate a proper login if none provided
192
        # Check if the userid provided does not exist yet
194
        if ( $borrower{userid} eq '' || !Check_Userid( $borrower{userid} ) ) {
193
        if (  exists $borrower{userid}
195
            push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
194
                 and $borrower{userid}
196
            $invalid++;
195
             and not Check_Userid( $borrower{userid}, $borrower{borrowernumber} ) ) {
197
            next LINE;
196
             push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
197
             $invalid++;
198
             next LINE;
198
        }
199
        }
199
200
200
        if ($borrowernumber) {
201
        if ($borrowernumber) {
Lines 224-229 sub import_patrons { Link Here
224
                    $borrower{$col} = $member->{$col} if ( $member->{$col} );
225
                    $borrower{$col} = $member->{$col} if ( $member->{$col} );
225
                }
226
                }
226
            }
227
            }
228
227
            unless ( ModMember(%borrower) ) {
229
            unless ( ModMember(%borrower) ) {
228
                $invalid++;
230
                $invalid++;
229
231
(-)a/t/db_dependent/Koha/Patrons/Import.t (-7 / +11 lines)
Lines 19-26 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 122;
21
use Test::More tests => 122;
22
use Test::MockModule;
23
22
23
# To be replaced by t::lib::Mock
24
use Test::MockModule;
24
use Koha::Database;
25
use Koha::Database;
25
26
26
use File::Temp qw(tempfile tempdir);
27
use File::Temp qw(tempfile tempdir);
Lines 73-78 my $result_0 = $patrons_import->import_patrons($params_0); Link Here
73
is($result_0, undef, 'Got the expected undef from import_patrons with no file handle');
74
is($result_0, undef, 'Got the expected undef from import_patrons with no file handle');
74
75
75
# Given ... a file handle to file with headers only.
76
# Given ... a file handle to file with headers only.
77
my $ExtendedPatronAttributes = 0;
78
my $context = Test::MockModule->new('C4::Context'); # Necessary mocking for consistent test results.
79
$context->mock('preference', sub { my ($mod, $meth) = @_;
80
                                    if ( $meth eq 'ExtendedPatronAttributes' ) { return $ExtendedPatronAttributes; }
81
                                    if ( $meth eq 'dateformat' ) { return 'us'; }
82
                                });
83
84
76
my $csv_headers  = 'cardnumber,surname,firstname,title,othernames,initials,streetnumber,streettype,address,address2,city,state,zipcode,country,email,phone,mobile,fax,dateofbirth,branchcode,categorycode,dateenrolled,dateexpiry,userid,password';
85
my $csv_headers  = 'cardnumber,surname,firstname,title,othernames,initials,streetnumber,streettype,address,address2,city,state,zipcode,country,email,phone,mobile,fax,dateofbirth,branchcode,categorycode,dateenrolled,dateexpiry,userid,password';
77
my $res_header   = 'cardnumber, surname, firstname, title, othernames, initials, streetnumber, streettype, address, address2, city, state, zipcode, country, email, phone, mobile, fax, dateofbirth, branchcode, categorycode, dateenrolled, dateexpiry, userid, password';
86
my $res_header   = 'cardnumber, surname, firstname, title, othernames, initials, streetnumber, streettype, address, address2, city, state, zipcode, country, email, phone, mobile, fax, dateofbirth, branchcode, categorycode, dateenrolled, dateexpiry, userid, password';
78
my $csv_one_line = '1000,Nancy,Jenkins,Dr,,NJ,78,Circle,Bunting,El Paso,Henderson,Texas,79984,United States,ajenkins0@sourceforge.net,7-(388)559-6763,3-(373)151-4471,8-(509)286-4001,10/16/1965,CPL,PT,12/28/2014,07/01/2015,jjenkins0,DPQILy';
87
my $csv_one_line = '1000,Nancy,Jenkins,Dr,,NJ,78,Circle,Bunting,El Paso,Henderson,Texas,79984,United States,ajenkins0@sourceforge.net,7-(388)559-6763,3-(373)151-4471,8-(509)286-4001,10/16/1965,CPL,PT,12/28/2014,07/01/2015,jjenkins0,DPQILy';
Lines 144-154 is($result_3->{invalid}, 1, 'Got the expected 1 invalid result from import_patro Link Here
144
is($result_3->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with duplicate userid');
153
is($result_3->{overwritten}, 0, 'Got the expected 0 overwritten result from import_patrons with duplicate userid');
145
154
146
# Given ... a new input and mocked C4::Context
155
# Given ... a new input and mocked C4::Context
147
my $context = Test::MockModule->new('C4::Context');
156
$ExtendedPatronAttributes = 1; # Updates mocked C4::Preferences result.
148
$context->mock('preference', sub { my ($mod, $meth) = @_;
149
                                    if ( $meth eq 'ExtendedPatronAttributes' ) { return 1; }
150
                                    if ( $meth eq 'dateformat' ) { return 'us'; }
151
                                });
152
157
153
my $new_input_line = '1001,Donna,Sullivan,Mrs,Henry,DS,59,Court,Burrows,Reading,Salt Lake City,Pennsylvania,19605,United States,hsullivan1@purevolume.com,3-(864)009-3006,7-(291)885-8423,1-(879)095-5038,09/19/1970,LPL,PT,03/04/2015,07/01/2015,hsullivan1,8j6P6Dmap';
158
my $new_input_line = '1001,Donna,Sullivan,Mrs,Henry,DS,59,Court,Burrows,Reading,Salt Lake City,Pennsylvania,19605,United States,hsullivan1@purevolume.com,3-(864)009-3006,7-(291)885-8423,1-(879)095-5038,09/19/1970,LPL,PT,03/04/2015,07/01/2015,hsullivan1,8j6P6Dmap';
154
my $filename_4 = make_csv($temp_dir, $csv_headers, $new_input_line);
159
my $filename_4 = make_csv($temp_dir, $csv_headers, $new_input_line);
155
- 

Return to bug 12598