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

(-)a/Koha/Patrons.pm (+14 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
                rows => 1,
76
            }
77
        )->single;
78
    }
79
66
    return $patron;
80
    return $patron;
67
}
81
}
68
82
(-)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 3605-3611 subtest 'filter_by_expired_opac_registrations' => sub { Link Here
3605
3607
3606
subtest 'find_by_identifier() tests' => sub {
3608
subtest 'find_by_identifier() tests' => sub {
3607
3609
3608
    plan tests => 7;
3610
    plan tests => 9;
3609
3611
3610
    $schema->storage->txn_begin;
3612
    $schema->storage->txn_begin;
3611
3613
Lines 3645-3650 subtest 'find_by_identifier() tests' => sub { Link Here
3645
    $found_patron = Koha::Patrons->find_by_identifier(undef);
3647
    $found_patron = Koha::Patrons->find_by_identifier(undef);
3646
    is( $found_patron, undef, 'Returns undef for undef identifier' );
3648
    is( $found_patron, undef, 'Returns undef for undef identifier' );
3647
3649
3650
    # Test with unique attributes
3651
    my $unique_code = 'UA_' . int( rand(100000) );
3652
    Koha::Patron::Attribute::Type->new(
3653
        {
3654
            code        => $unique_code,
3655
            description => 'Unique Attribute',
3656
            unique_id   => 1,
3657
            repeatable  => 0,
3658
        }
3659
    )->store;
3660
3661
    my $non_unique_code = 'NUA_' . int( rand(100000) );
3662
    Koha::Patron::Attribute::Type->new(
3663
        {
3664
            code        => $non_unique_code,
3665
            description => 'Non-Unique Attribute',
3666
            unique_id   => 0,
3667
            repeatable  => 0,
3668
        }
3669
    )->store;
3670
3671
    my $patron_u = $builder->build_object( { class => 'Koha::Patrons' } );
3672
    my $val_u    = 'VAL_U_' . int( rand(100000) );
3673
    Koha::Patron::Attribute->new(
3674
        {
3675
            borrowernumber => $patron_u->borrowernumber,
3676
            code           => $unique_code,
3677
            attribute      => $val_u,
3678
        }
3679
    )->store;
3680
3681
    my $patron_nu = $builder->build_object( { class => 'Koha::Patrons' } );
3682
    my $val_nu    = 'VAL_NU_' . int( rand(100000) );
3683
    Koha::Patron::Attribute->new(
3684
        {
3685
            borrowernumber => $patron_nu->borrowernumber,
3686
            code           => $non_unique_code,
3687
            attribute      => $val_nu,
3688
        }
3689
    )->store;
3690
3691
    $found_patron = Koha::Patrons->find_by_identifier($val_u);
3692
    is( $found_patron ? $found_patron->id : undef, $patron_u->id, 'Found patron by unique attribute' );
3693
3694
    $found_patron = Koha::Patrons->find_by_identifier($val_nu);
3695
    is( $found_patron, undef, 'Did not find patron by non-unique attribute' );
3696
3648
    $schema->storage->txn_rollback;
3697
    $schema->storage->txn_rollback;
3649
};
3698
};
3650
3699
3651
- 

Return to bug 41383