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

(-)a/Koha/Exceptions/Patron/Attribute.pm (+16 lines)
Line 0 Link Here
1
package Koha::Exceptions::Patron::Attribute;
2
3
use Modern::Perl;
4
5
use Exception::Class (
6
7
    'Koha::Exceptions::Patron::Attribute' => {
8
        description => 'Something went wrong'
9
    },
10
    'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint' => {
11
        isa => 'Koha::Exceptions::Patron::Attribute',
12
        description => "unique_id set for attribute type and tried to add a new attribute for the same code"
13
    }
14
);
15
16
1;
(-)a/Koha/Patron/Attribute.pm (-1 / +28 lines)
Lines 17-22 package Koha::Patron::Attribute; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Database;
21
use Koha::Exceptions::Patron::Attribute;
20
use Koha::Patron::Attribute::Types;
22
use Koha::Patron::Attribute::Types;
21
23
22
use base qw(Koha::Object);
24
use base qw(Koha::Object);
Lines 31-36 Koha::Patron::Attribute - Koha Patron Attribute Object class Link Here
31
33
32
=cut
34
=cut
33
35
36
=head3 store
37
38
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
39
    try { $attribute->store }
40
    catch { handle_exception };
41
42
=cut
43
44
sub store {
45
46
    my $self = shift;
47
48
    if ( Koha::Patron::Attribute::Types->find( $self->code )->unique_id ) {
49
        my $attr_count
50
            = Koha::Database->new->schema->resultset( $self->_type )->search(
51
            {   borrowernumber => $self->borrowernumber,
52
                code           => $self->code
53
            }
54
            )->count;
55
        Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw()
56
            if $attr_count > 0;
57
    }
58
59
    return $self->SUPER::store();
60
}
61
34
=head3 opac_display
62
=head3 opac_display
35
63
36
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
64
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
37
- 

Return to bug 17828