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

(-)a/C4/Members.pm (-5 / +7 lines)
Lines 398-406 sub AddMember { Link Here
398
        }
398
        }
399
    }
399
    }
400
400
401
    my $p = Koha::Patron->new( { userid => $data{userid} } );
401
    # generate a proper login if none provided
402
    # generate a proper login if none provided
402
    $data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} )
403
    $data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} )
403
      if ( $data{'userid'} eq '' || !Check_Userid( $data{'userid'} ) );
404
      if ( $data{'userid'} eq '' || ! $p->has_valid_userid );
404
405
405
    # add expiration date if it isn't already there
406
    # add expiration date if it isn't already there
406
    $data{dateexpiry} ||= $category->get_expiry_date;
407
    $data{dateexpiry} ||= $category->get_expiry_date;
Lines 506-512 sub Check_Userid { Link Here
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.
507
    $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.
507
508
508
    return :
509
    return :
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 Check_Userid finds an existing match for the $newuid in the database).
510
        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).
510
511
511
=cut
512
=cut
512
513
Lines 514-529 sub Generate_Userid { Link Here
514
  my ($borrowernumber, $firstname, $surname) = @_;
515
  my ($borrowernumber, $firstname, $surname) = @_;
515
  my $newuid;
516
  my $newuid;
516
  my $offset = 0;
517
  my $offset = 0;
517
  #The script will "do" the following code and increment the $offset until Check_Userid = 1 (i.e. until $newuid comes back as unique)
518
  my $patron = Koha::Patron->new;
519
  #The script will "do" the following code and increment the $offset until the generated userid is unique
518
  do {
520
  do {
519
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
521
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
520
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
522
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
521
    $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
523
    $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
522
    $newuid = unac_string('utf-8',$newuid);
524
    $newuid = unac_string('utf-8',$newuid);
523
    $newuid .= $offset unless $offset == 0;
525
    $newuid .= $offset unless $offset == 0;
526
    $patron->userid( $newuid );
524
    $offset++;
527
    $offset++;
525
528
   } while (! $patron->has_valid_userid );
526
   } while (!Check_Userid($newuid,$borrowernumber));
527
529
528
   return $newuid;
530
   return $newuid;
529
}
531
}
(-)a/members/memberentry.pl (-1 / +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
(-)a/tools/import_borrowers.pl (-7 / +6 lines)
Lines 233-243 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
233
        $borrower{dateenrolled} ||= $today;
233
        $borrower{dateenrolled} ||= $today;
234
        $borrower{dateexpiry}   ||= Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} );
234
        $borrower{dateexpiry}   ||= Koha::Patron::Categories->find( $borrower{categorycode} )->get_expiry_date( $borrower{dateenrolled} );
235
        my $borrowernumber;
235
        my $borrowernumber;
236
        my $member;
236
        my ( $member, $patron );
237
        if ( ($matchpoint eq 'cardnumber') && ($borrower{'cardnumber'}) ) {
237
        if ( ($matchpoint eq 'cardnumber') && ($borrower{'cardnumber'}) ) {
238
            $member = Koha::Patrons->find( { cardnumber => $borrower{'cardnumber'} } );
238
            $patron = Koha::Patrons->find( { cardnumber => $borrower{'cardnumber'} } );
239
        } elsif ( ($matchpoint eq 'userid') && ($borrower{'userid'}) ) {
239
        } elsif ( ($matchpoint eq 'userid') && ($borrower{'userid'}) ) {
240
            $member = Koha::Patrons->find( { userid => $borrower{'userid'} } );
240
            $patron = Koha::Patrons->find( { userid => $borrower{'userid'} } );
241
        } elsif ($extended) {
241
        } elsif ($extended) {
242
            if (defined($matchpoint_attr_type)) {
242
            if (defined($matchpoint_attr_type)) {
243
                foreach my $attr (@$patron_attributes) {
243
                foreach my $attr (@$patron_attributes) {
Lines 250-257 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
250
            }
250
            }
251
        }
251
        }
252
252
253
        if ($member) {
253
        if ($patron) {
254
            $member = $member->unblessed;
254
            $member = $patron->unblessed;
255
            $borrowernumber = $member->{'borrowernumber'};
255
            $borrowernumber = $member->{'borrowernumber'};
256
        } else {
256
        } else {
257
            $member = {};
257
            $member = {};
Lines 290-296 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
290
            # Check if the userid provided does not exist yet
290
            # Check if the userid provided does not exist yet
291
            if (  exists $borrower{userid}
291
            if (  exists $borrower{userid}
292
                     and $borrower{userid}
292
                     and $borrower{userid}
293
                 and not Check_Userid( $borrower{userid}, $borrower{borrowernumber} ) ) {
293
                 and not $patron->userid($borrower{userid})->has_valid_userid ) {
294
                push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
294
                push @errors, { duplicate_userid => 1, userid => $borrower{userid} };
295
                $invalid++;
295
                $invalid++;
296
                next LINE;
296
                next LINE;
297
- 

Return to bug 19936