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

(-)a/Koha/Patron.pm (-3 / +8 lines)
Lines 885-891 sub generate_userid { Link Here
885
    my ($self) = @_;
885
    my ($self) = @_;
886
    my $userid;
886
    my $userid;
887
    my $offset = 0;
887
    my $offset = 0;
888
    my $patron = Koha::Patron->new;
888
    my $existing_userid = $self->userid;
889
    my $firstname = $self->firstname // q{};
889
    my $firstname = $self->firstname // q{};
890
    my $surname = $self->surname // q{};
890
    my $surname = $self->surname // q{};
891
    #The script will "do" the following code and increment the $offset until the generated userid is unique
891
    #The script will "do" the following code and increment the $offset until the generated userid is unique
Lines 895-903 sub generate_userid { Link Here
895
      $userid = lc(($firstname)? "$firstname.$surname" : $surname);
895
      $userid = lc(($firstname)? "$firstname.$surname" : $surname);
896
      $userid = unac_string('utf-8',$userid);
896
      $userid = unac_string('utf-8',$userid);
897
      $userid .= $offset unless $offset == 0;
897
      $userid .= $offset unless $offset == 0;
898
      $patron->userid( $userid );
898
      $self->userid( $userid );
899
      $offset++;
899
      $offset++;
900
     } while (! $patron->has_valid_userid );
900
     } while (! $self->has_valid_userid );
901
902
     # Resetting to the previous value as the callers do not expect
903
     # this method to modify the userid attribute
904
     # This will be done later (move of AddMember and ModMember)
905
     $self->userid( $existing_userid );
901
906
902
     return $userid;
907
     return $userid;
903
908
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +6 lines)
Lines 1186-1192 subtest 'userid_is_valid' => sub { Link Here
1186
};
1186
};
1187
1187
1188
subtest 'generate_userid' => sub {
1188
subtest 'generate_userid' => sub {
1189
    plan tests => 6;
1189
    plan tests => 7;
1190
1190
1191
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1191
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1192
    my $patron_category = $builder->build_object(
1192
    my $patron_category = $builder->build_object(
Lines 1224-1229 subtest 'generate_userid' => sub { Link Here
1224
    $userid = $new_patron->generate_userid;
1224
    $userid = $new_patron->generate_userid;
1225
    is( $userid, $expected_userid_patron_1 . '2', 'generate_userid should generate the userid we expect' );
1225
    is( $userid, $expected_userid_patron_1 . '2', 'generate_userid should generate the userid we expect' );
1226
1226
1227
    $patron_1 = Koha::Patrons->find($borrowernumber);
1228
    $patron_1->userid(undef);
1229
    $userid = $patron_1->generate_userid;
1230
    is( $userid, $expected_userid_patron_1, 'generate_userid should generate the userid we expect' );
1231
1227
    # Cleanup
1232
    # Cleanup
1228
    $patron_1->delete;
1233
    $patron_1->delete;
1229
    $patron_2->delete;
1234
    $patron_2->delete;
1230
- 

Return to bug 19936