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

(-)a/Koha/Patron/Attribute.pm (-11 / +12 lines)
Lines 46-56 sub store { Link Here
46
46
47
    my $self = shift;
47
    my $self = shift;
48
48
49
    my $type = $self->type;
50
49
    Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code )
51
    Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code )
50
        unless Koha::Patron::Attribute::Types->find( $self->code );
52
        unless $type;
51
53
52
    $self->_check_repeatable;
54
    $self->check_repeatable($type);
53
    $self->check_unique_id;
55
    $self->check_unique_id($type);
54
56
55
    return $self->SUPER::store();
57
    return $self->SUPER::store();
56
}
58
}
Lines 133-151 sub to_api_mapping { Link Here
133
135
134
=head2 Internal methods
136
=head2 Internal methods
135
137
136
=head3 _check_repeatable
138
=head3 check_repeatable
137
139
138
_check_repeatable checks if the attribute type is repeatable and throws and exception
140
check_repeatable checks if the attribute type is repeatable and throws and exception
139
if the attribute type isn't repeatable and there's already an attribute with the same
141
if the attribute type isn't repeatable and there's already an attribute with the same
140
code for the given patron.
142
code for the given patron.
141
143
142
=cut
144
=cut
143
145
144
sub _check_repeatable {
146
sub check_repeatable {
145
147
146
    my $self = shift;
148
    my ( $self, $type ) = @_;
147
149
148
    if ( !$self->type->repeatable ) {
150
    if ( !$type->repeatable ) {
149
        my $params = {
151
        my $params = {
150
            borrowernumber => $self->borrowernumber,
152
            borrowernumber => $self->borrowernumber,
151
            code           => $self->code
153
            code           => $self->code
Lines 171-179 code and value on the database. Link Here
171
173
172
sub check_unique_id {
174
sub check_unique_id {
173
175
174
    my $self = shift;
176
    my ( $self, $type ) = @_;
175
177
176
    if ( $self->type->unique_id ) {
178
    if ( $type->unique_id ) {
177
        my $params = { code => $self->code, attribute => $self->attribute };
179
        my $params = { code => $self->code, attribute => $self->attribute };
178
180
179
        $params->{borrowernumber} = { '!=' => $self->borrowernumber } if $self->borrowernumber;
181
        $params->{borrowernumber} = { '!=' => $self->borrowernumber } if $self->borrowernumber;
180
- 

Return to bug 28031