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

(-)a/Koha/Patrons.pm (+13 lines)
Lines 63-68 sub find_by_identifier { Link Here
63
    # If not found by userid, try cardnumber
63
    # If not found by userid, try cardnumber
64
    $patron = $self->search( { cardnumber => $identifier } )->next unless $patron;
64
    $patron = $self->search( { cardnumber => $identifier } )->next unless $patron;
65
65
66
    # If not found by cardnumber, try unique patron attributes
67
    unless ($patron) {
68
        $patron = $self->search(
69
            {
70
                'borrower_attributes.attribute' => $identifier,
71
                'code.unique_id'                => 1,
72
            },
73
            {
74
                join => { 'borrower_attributes' => 'code' },
75
            }
76
        )->next;
77
    }
78
66
    return $patron;
79
    return $patron;
67
}
80
}
68
81
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +50 lines)
Lines 39-44 use Koha::Holds; Link Here
39
use Koha::Old::Holds;
39
use Koha::Old::Holds;
40
use Koha::Patrons;
40
use Koha::Patrons;
41
use Koha::Old::Patrons;
41
use Koha::Old::Patrons;
42
use Koha::Patron::Attribute;
43
use Koha::Patron::Attribute::Type;
42
use Koha::Patron::Attribute::Types;
44
use Koha::Patron::Attribute::Types;
43
use Koha::Patron::Categories;
45
use Koha::Patron::Categories;
44
use Koha::Patron::Relationship;
46
use Koha::Patron::Relationship;
Lines 3582-3588 subtest 'filter_by_expired_opac_registrations' => sub { Link Here
3582
3584
3583
subtest 'find_by_identifier() tests' => sub {
3585
subtest 'find_by_identifier() tests' => sub {
3584
3586
3585
    plan tests => 7;
3587
    plan tests => 9;
3586
3588
3587
    $schema->storage->txn_begin;
3589
    $schema->storage->txn_begin;
3588
3590
Lines 3622-3627 subtest 'find_by_identifier() tests' => sub { Link Here
3622
    $found_patron = Koha::Patrons->find_by_identifier(undef);
3624
    $found_patron = Koha::Patrons->find_by_identifier(undef);
3623
    is( $found_patron, undef, 'Returns undef for undef identifier' );
3625
    is( $found_patron, undef, 'Returns undef for undef identifier' );
3624
3626
3627
    # Test with unique attributes
3628
    my $unique_code = 'UA_' . int( rand(100000) );
3629
    Koha::Patron::Attribute::Type->new(
3630
        {
3631
            code        => $unique_code,
3632
            description => 'Unique Attribute',
3633
            unique_id   => 1,
3634
            repeatable  => 0,
3635
        }
3636
    )->store;
3637
3638
    my $non_unique_code = 'NUA_' . int( rand(100000) );
3639
    Koha::Patron::Attribute::Type->new(
3640
        {
3641
            code        => $non_unique_code,
3642
            description => 'Non-Unique Attribute',
3643
            unique_id   => 0,
3644
            repeatable  => 0,
3645
        }
3646
    )->store;
3647
3648
    my $patron_u = $builder->build_object( { class => 'Koha::Patrons' } );
3649
    my $val_u    = 'VAL_U_' . int( rand(100000) );
3650
    Koha::Patron::Attribute->new(
3651
        {
3652
            borrowernumber => $patron_u->borrowernumber,
3653
            code           => $unique_code,
3654
            attribute      => $val_u,
3655
        }
3656
    )->store;
3657
3658
    my $patron_nu = $builder->build_object( { class => 'Koha::Patrons' } );
3659
    my $val_nu    = 'VAL_NU_' . int( rand(100000) );
3660
    Koha::Patron::Attribute->new(
3661
        {
3662
            borrowernumber => $patron_nu->borrowernumber,
3663
            code           => $non_unique_code,
3664
            attribute      => $val_nu,
3665
        }
3666
    )->store;
3667
3668
    $found_patron = Koha::Patrons->find_by_identifier($val_u);
3669
    is( $found_patron ? $found_patron->id : undef, $patron_u->id, 'Found patron by unique attribute' );
3670
3671
    $found_patron = Koha::Patrons->find_by_identifier($val_nu);
3672
    is( $found_patron, undef, 'Did not find patron by non-unique attribute' );
3673
3625
    $schema->storage->txn_rollback;
3674
    $schema->storage->txn_rollback;
3626
};
3675
};
3627
3676
3628
- 

Return to bug 41383