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

(-)a/C4/Members.pm (-5 / +7 lines)
Lines 415-423 sub AddMember { Link Here
415
        }
415
        }
416
    }
416
    }
417
417
418
    my $p = Koha::Patron->new( { userid => $data{userid} } );
418
    # generate a proper login if none provided
419
    # generate a proper login if none provided
419
    $data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} )
420
    $data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} )
420
      if ( $data{'userid'} eq '' || !Check_Userid( $data{'userid'} ) );
421
      if ( $data{'userid'} eq '' || ! $p->has_valid_userid );
421
422
422
    # add expiration date if it isn't already there
423
    # add expiration date if it isn't already there
423
    $data{dateexpiry} ||= $category->get_expiry_date;
424
    $data{dateexpiry} ||= $category->get_expiry_date;
Lines 523-529 sub Check_Userid { Link Here
523
    $borrowernumber is optional (i.e. it can contain a blank value). A value is passed when generating a new userid for an existing borrower. When a new userid is created for a new borrower, a blank value is passed to this sub.
524
    $borrowernumber is optional (i.e. it can contain a blank value). A value is passed when generating a new userid for an existing borrower. When a new userid is created for a new borrower, a blank value is passed to this sub.
524
525
525
    return :
526
    return :
526
        new userid ($firstname.$surname if there is a $firstname, or $surname if there is no value in $firstname) plus offset (0 if the $newuid is unique, or a higher numeric value if Check_Userid finds an existing match for the $newuid in the database).
527
        new userid ($firstname.$surname if there is a $firstname, or $surname if there is no value in $firstname) plus offset (0 if the $newuid is unique, or a higher numeric value if not unique).
527
528
528
=cut
529
=cut
529
530
Lines 531-546 sub Generate_Userid { Link Here
531
  my ($borrowernumber, $firstname, $surname) = @_;
532
  my ($borrowernumber, $firstname, $surname) = @_;
532
  my $newuid;
533
  my $newuid;
533
  my $offset = 0;
534
  my $offset = 0;
534
  #The script will "do" the following code and increment the $offset until Check_Userid = 1 (i.e. until $newuid comes back as unique)
535
  my $patron = Koha::Patron->new;
536
  #The script will "do" the following code and increment the $offset until the generated userid is unique
535
  do {
537
  do {
536
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
538
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
537
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
539
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
538
    $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
540
    $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
539
    $newuid = unac_string('utf-8',$newuid);
541
    $newuid = unac_string('utf-8',$newuid);
540
    $newuid .= $offset unless $offset == 0;
542
    $newuid .= $offset unless $offset == 0;
543
    $patron->userid( $newuid );
541
    $offset++;
544
    $offset++;
542
545
   } while (! $patron->has_valid_userid );
543
   } while (!Check_Userid($newuid,$borrowernumber));
544
546
545
   return $newuid;
547
   return $newuid;
546
}
548
}
(-)a/Koha/Patrons/Import.pm (-6 / +6 lines)
Lines 163-174 sub import_patrons { Link Here
163
        $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ) unless $borrower{dateexpiry};
163
        $borrower{dateexpiry} = Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} ) unless $borrower{dateexpiry};
164
164
165
        my $borrowernumber;
165
        my $borrowernumber;
166
        my $member;
166
        my ( $member, $patron );
167
        if ( defined($matchpoint) && ( $matchpoint eq 'cardnumber' ) && ( $borrower{'cardnumber'} ) ) {
167
        if ( defined($matchpoint) && ( $matchpoint eq 'cardnumber' ) && ( $borrower{'cardnumber'} ) ) {
168
            $member = Koha::Patrons->find( { cardnumber => $borrower{'cardnumber'} } );
168
            $patron = Koha::Patrons->find( { cardnumber => $borrower{'cardnumber'} } );
169
        }
169
        }
170
        elsif ( defined($matchpoint) && ($matchpoint eq 'userid') && ($borrower{'userid'}) ) {
170
        elsif ( defined($matchpoint) && ($matchpoint eq 'userid') && ($borrower{'userid'}) ) {
171
            $member = Koha::Patrons->find( { userid => $borrower{userid} } );
171
            $patron = Koha::Patrons->find( { userid => $borrower{userid} } );
172
        }
172
        }
173
        elsif ($extended) {
173
        elsif ($extended) {
174
            if ( defined($matchpoint_attr_type) ) {
174
            if ( defined($matchpoint_attr_type) ) {
Lines 182-189 sub import_patrons { Link Here
182
            }
182
            }
183
        }
183
        }
184
184
185
        if ($member) {
185
        if ($patron) {
186
            $member = $member->unblessed;
186
            $member = $patron->unblessed;
187
            $borrowernumber = $member->{'borrowernumber'};
187
            $borrowernumber = $member->{'borrowernumber'};
188
        } else {
188
        } else {
189
            $member = {};
189
            $member = {};
Lines 203-209 sub import_patrons { Link Here
203
        # Check if the userid provided does not exist yet
203
        # Check if the userid provided does not exist yet
204
        if ( defined($matchpoint) and $matchpoint ne 'userid' and exists $borrower{userid}
204
        if ( defined($matchpoint) and $matchpoint ne 'userid' and exists $borrower{userid}
205
                 and $borrower{userid}
205
                 and $borrower{userid}
206
             and not Check_Userid( $borrower{userid}, $borrower{borrowernumber} ) ) {
206
             and ( $patron and not $patron->userid($borrower{userid})->has_valid_userid ) ) {
207
             push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
207
             push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
208
             $invalid++;
208
             $invalid++;
209
             next LINE;
209
             next LINE;
(-)a/members/memberentry.pl (-2 / +3 lines)
Lines 348-354 if ($op eq 'save' || $op eq 'insert'){ Link Here
348
  # the edited values list when editing certain sub-forms. Get it straight
348
  # the edited values list when editing certain sub-forms. Get it straight
349
  # from the DB if absent.
349
  # from the DB if absent.
350
  my $userid = $newdata{ userid } // $borrower_data->{ userid };
350
  my $userid = $newdata{ userid } // $borrower_data->{ userid };
351
  unless (Check_Userid($userid,$borrowernumber)) {
351
  my $p = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : Koha::Patron->new;
352
  $p->userid( $userid );
353
  unless ( $p->has_valid_userid ) {
352
    push @errors, "ERROR_login_exist";
354
    push @errors, "ERROR_login_exist";
353
  }
355
  }
354
356
355
- 

Return to bug 19936