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

(-)a/Koha/Patron.pm (-3 / +8 lines)
Lines 916-922 sub generate_userid { Link Here
916
    my ($self) = @_;
916
    my ($self) = @_;
917
    my $userid;
917
    my $userid;
918
    my $offset = 0;
918
    my $offset = 0;
919
    my $patron = Koha::Patron->new;
919
    my $existing_userid = $self->userid;
920
    my $firstname = $self->firstname // q{};
920
    my $firstname = $self->firstname // q{};
921
    my $surname = $self->surname // q{};
921
    my $surname = $self->surname // q{};
922
    #The script will "do" the following code and increment the $offset until the generated userid is unique
922
    #The script will "do" the following code and increment the $offset until the generated userid is unique
Lines 926-934 sub generate_userid { Link Here
926
      $userid = lc(($firstname)? "$firstname.$surname" : $surname);
926
      $userid = lc(($firstname)? "$firstname.$surname" : $surname);
927
      $userid = unac_string('utf-8',$userid);
927
      $userid = unac_string('utf-8',$userid);
928
      $userid .= $offset unless $offset == 0;
928
      $userid .= $offset unless $offset == 0;
929
      $patron->userid( $userid );
929
      $self->userid( $userid );
930
      $offset++;
930
      $offset++;
931
     } while (! $patron->has_valid_userid );
931
     } while (! $self->has_valid_userid );
932
933
     # Resetting to the previous value as the callers do not expect
934
     # this method to modify the userid attribute
935
     # This will be done later (move of AddMember and ModMember)
936
     $self->userid( $existing_userid );
932
937
933
     return $userid;
938
     return $userid;
934
939
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +6 lines)
Lines 1265-1271 subtest 'userid_is_valid' => sub { Link Here
1265
};
1265
};
1266
1266
1267
subtest 'generate_userid' => sub {
1267
subtest 'generate_userid' => sub {
1268
    plan tests => 6;
1268
    plan tests => 7;
1269
1269
1270
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1270
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1271
    my $patron_category = $builder->build_object(
1271
    my $patron_category = $builder->build_object(
Lines 1303-1308 subtest 'generate_userid' => sub { Link Here
1303
    $userid = $new_patron->generate_userid;
1303
    $userid = $new_patron->generate_userid;
1304
    is( $userid, $expected_userid_patron_1 . '2', 'generate_userid should generate the userid we expect' );
1304
    is( $userid, $expected_userid_patron_1 . '2', 'generate_userid should generate the userid we expect' );
1305
1305
1306
    $patron_1 = Koha::Patrons->find($borrowernumber);
1307
    $patron_1->userid(undef);
1308
    $userid = $patron_1->generate_userid;
1309
    is( $userid, $expected_userid_patron_1, 'generate_userid should generate the userid we expect' );
1310
1306
    # Cleanup
1311
    # Cleanup
1307
    $patron_1->delete;
1312
    $patron_1->delete;
1308
    $patron_2->delete;
1313
    $patron_2->delete;
1309
- 

Return to bug 19936