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

(-)a/C4/Members.pm (-5 / +7 lines)
Lines 397-405 sub AddMember { Link Here
397
        }
397
        }
398
    }
398
    }
399
399
400
    my $p = Koha::Patron->new( { userid => $data{userid} } );
400
    # generate a proper login if none provided
401
    # generate a proper login if none provided
401
    $data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} )
402
    $data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} )
402
      if ( $data{'userid'} eq '' || !Check_Userid( $data{'userid'} ) );
403
      if ( $data{'userid'} eq '' || ! $p->has_valid_userid );
403
404
404
    # add expiration date if it isn't already there
405
    # add expiration date if it isn't already there
405
    $data{dateexpiry} ||= $category->get_expiry_date;
406
    $data{dateexpiry} ||= $category->get_expiry_date;
Lines 505-511 sub Check_Userid { Link Here
505
    $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.
506
    $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.
506
507
507
    return :
508
    return :
508
        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).
509
        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).
509
510
510
=cut
511
=cut
511
512
Lines 513-528 sub Generate_Userid { Link Here
513
  my ($borrowernumber, $firstname, $surname) = @_;
514
  my ($borrowernumber, $firstname, $surname) = @_;
514
  my $newuid;
515
  my $newuid;
515
  my $offset = 0;
516
  my $offset = 0;
516
  #The script will "do" the following code and increment the $offset until Check_Userid = 1 (i.e. until $newuid comes back as unique)
517
  my $patron = Koha::Patron->new;
518
  #The script will "do" the following code and increment the $offset until the generated userid is unique
517
  do {
519
  do {
518
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
520
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
519
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
521
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
520
    $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
522
    $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
521
    $newuid = unac_string('utf-8',$newuid);
523
    $newuid = unac_string('utf-8',$newuid);
522
    $newuid .= $offset unless $offset == 0;
524
    $newuid .= $offset unless $offset == 0;
525
    $patron->userid( $newuid );
523
    $offset++;
526
    $offset++;
524
527
   } while (! $patron->has_valid_userid );
525
   } while (!Check_Userid($newuid,$borrowernumber));
526
528
527
   return $newuid;
529
   return $newuid;
528
}
530
}
(-)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 349-355 if ($op eq 'save' || $op eq 'insert'){ Link Here
349
  # the edited values list when editing certain sub-forms. Get it straight
349
  # the edited values list when editing certain sub-forms. Get it straight
350
  # from the DB if absent.
350
  # from the DB if absent.
351
  my $userid = $newdata{ userid } // $borrower_data->{ userid };
351
  my $userid = $newdata{ userid } // $borrower_data->{ userid };
352
  unless (Check_Userid($userid,$borrowernumber)) {
352
  my $p = $borrowernumber ? Koha::Patrons->find( $borrowernumber ) : Koha::Patron->new;
353
  $p->userid( $userid );
354
  unless ( $p->has_valid_userid ) {
353
    push @errors, "ERROR_login_exist";
355
    push @errors, "ERROR_login_exist";
354
  }
356
  }
355
357
356
- 

Return to bug 19936