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

(-)a/Koha/Patron/Attribute.pm (-2 / +20 lines)
Lines 18-23 package Koha::Patron::Attribute; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Database;
20
use Koha::Database;
21
use Koha::Exceptions;
21
use Koha::Exceptions::Patron::Attribute;
22
use Koha::Exceptions::Patron::Attribute;
22
use Koha::Patron::Attribute::Types;
23
use Koha::Patron::Attribute::Types;
23
use Koha::AuthorisedValues;
24
use Koha::AuthorisedValues;
Lines 46-52 sub store { Link Here
46
47
47
    my $self = shift;
48
    my $self = shift;
48
49
49
    my $type = $self->type;
50
    my $type;
51
52
    if ( $self->in_storage ) {
53
        $type = $self->type;
54
    }
55
    else {
56
        $type = Koha::Patron::Attribute::Types->find( $self->code );
57
    }
50
58
51
    Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code )
59
    Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code )
52
        unless $type;
60
        unless $type;
Lines 72-78 sub type { Link Here
72
80
73
    my $self = shift;
81
    my $self = shift;
74
82
75
    return scalar Koha::Patron::Attribute::Types->find( $self->code );
83
    return Koha::Patron::Attribute::Type->_new_from_dbic( $self->_result->code );
76
}
84
}
77
85
78
=head3 authorised_value
86
=head3 authorised_value
Lines 138-143 sub to_api_mapping { Link Here
138
146
139
=head3 repeatable_ok
147
=head3 repeatable_ok
140
148
149
    if ( $attr->repeatable_ok( $type ) ) { ... }
150
141
Checks if the attribute type is repeatable and returns a boolean representing
151
Checks if the attribute type is repeatable and returns a boolean representing
142
whether storing the current object state would break the repeatable constraint.
152
whether storing the current object state would break the repeatable constraint.
143
153
Lines 147-152 sub repeatable_ok { Link Here
147
157
148
    my ( $self, $type ) = @_;
158
    my ( $self, $type ) = @_;
149
159
160
    Koha::Exceptions::MissingParameter->throw( "The type parameter is mandatory" )
161
        unless $type;
162
150
    my $ok = 1;
163
    my $ok = 1;
151
    if ( !$type->repeatable ) {
164
    if ( !$type->repeatable ) {
152
        my $params = {
165
        my $params = {
Lines 165-170 sub repeatable_ok { Link Here
165
178
166
=head3 unique_ok
179
=head3 unique_ok
167
180
181
    if ( $attr->unique_ok( $type ) ) { ... }
182
168
Checks if the attribute type is marked as unique and returns a boolean representing
183
Checks if the attribute type is marked as unique and returns a boolean representing
169
whether storing the current object state would break the unique constraint.
184
whether storing the current object state would break the unique constraint.
170
185
Lines 174-179 sub unique_ok { Link Here
174
189
175
    my ( $self, $type ) = @_;
190
    my ( $self, $type ) = @_;
176
191
192
    Koha::Exceptions::MissingParameter->throw( "The type parameter is mandatory" )
193
        unless $type;
194
177
    my $ok = 1;
195
    my $ok = 1;
178
    if ( $type->unique_id ) {
196
    if ( $type->unique_id ) {
179
        my $params = { code => $self->code, attribute => $self->attribute };
197
        my $params = { code => $self->code, attribute => $self->attribute };
(-)a/members/memberentry.pl (-2 / +2 lines)
Lines 412-420 if ($op eq 'save' || $op eq 'insert'){ Link Here
412
      for my $attr ( @$extended_patron_attributes ) {
412
      for my $attr ( @$extended_patron_attributes ) {
413
          $attr->{borrowernumber} = $borrowernumber if $borrowernumber;
413
          $attr->{borrowernumber} = $borrowernumber if $borrowernumber;
414
          my $attribute = Koha::Patron::Attribute->new($attr);
414
          my $attribute = Koha::Patron::Attribute->new($attr);
415
          if ( !$attribute->unique_ok ) {
415
          my $attr_type = Koha::Patron::Attribute::Types->find($attr->{code});
416
          if ( !$attribute->unique_ok( $attr_type ) ) {
416
              push @errors, "ERROR_extended_unique_id_failed";
417
              push @errors, "ERROR_extended_unique_id_failed";
417
              my $attr_type = Koha::Patron::Attribute::Types->find($attr->{code});
418
              $template->param(
418
              $template->param(
419
                  ERROR_extended_unique_id_failed_code => $attr->{code},
419
                  ERROR_extended_unique_id_failed_code => $attr->{code},
420
                  ERROR_extended_unique_id_failed_value => $attr->{attribute},
420
                  ERROR_extended_unique_id_failed_value => $attr->{attribute},
(-)a/opac/opac-memberentry.pl (-2 / +2 lines)
Lines 107-114 my $conflicting_attribute = 0; Link Here
107
107
108
foreach my $attr (@$attributes) {
108
foreach my $attr (@$attributes) {
109
    my $attribute = Koha::Patron::Attribute->new($attr);
109
    my $attribute = Koha::Patron::Attribute->new($attr);
110
    if ( !$$attribute->unique_ok ) {
110
    my $attr_type = Koha::Patron::Attribute::Types->find($attr->{code});
111
        my $attr_type = Koha::Patron::Attribute::Types->find($attr->{code});
111
    if ( !$$attribute->unique_ok( $attr_type ) ) {
112
        $template->param(
112
        $template->param(
113
            extended_unique_id_failed_code => $attr->{code},
113
            extended_unique_id_failed_code => $attr->{code},
114
            extended_unique_id_failed_value => $attr->{attribute},
114
            extended_unique_id_failed_value => $attr->{attribute},
(-)a/t/db_dependent/Koha/Patron.t (-1 / +1 lines)
Lines 647-653 subtest 'extended_attributes' => sub { Link Here
647
            'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute',
647
            'Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute',
648
            'Exception thrown on missing mandatory attribute type';
648
            'Exception thrown on missing mandatory attribute type';
649
649
650
        is( $@->value, $attribute_type_1->code, 'Exception parameters are correct' );
650
        is( $@->type, $attribute_type_1->code, 'Exception parameters are correct' );
651
651
652
        is( $patron->extended_attributes->count, 0, 'Extended attributes storing rolled back' );
652
        is( $patron->extended_attributes->count, 0, 'Extended attributes storing rolled back' );
653
653
(-)a/t/db_dependent/Koha/Patron/Attribute.t (-2 / +35 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 2;
22
use Test::More tests => 4;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use Test::Exception;
25
use Test::Exception;
Lines 288-290 subtest 'type() tests' => sub { Link Here
288
288
289
    $schema->storage->txn_rollback;
289
    $schema->storage->txn_rollback;
290
};
290
};
291
- 
291
292
subtest 'repeatable_ok() tests' => sub {
293
294
    plan tests => 1;
295
296
    my $attr = Koha::Patron::Attribute->new(
297
        {
298
            attribute => 'something',
299
            code      => 'some code'
300
        }
301
    );
302
303
    throws_ok
304
        { $attr->repeatable_ok(); }
305
        'Koha::Exceptions::MissingParameter',
306
        'Exception on missing type attribute';
307
};
308
309
subtest 'unique_ok() tests' => sub {
310
311
    plan tests => 1;
312
313
    my $attr = Koha::Patron::Attribute->new(
314
        {
315
            attribute => 'something',
316
            code      => 'some code'
317
        }
318
    );
319
320
    throws_ok
321
        { $attr->unique_ok(); }
322
        'Koha::Exceptions::MissingParameter',
323
        'Exception on missing type attribute';
324
};

Return to bug 28031