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

(-)a/Koha/Patron.pm (+19 lines)
Lines 1561-1568 sub extended_attributes { Link Here
1561
                $self->extended_attributes->filter_by_branch_limitations->delete;
1561
                $self->extended_attributes->filter_by_branch_limitations->delete;
1562
1562
1563
                # Insert the new ones
1563
                # Insert the new ones
1564
                my $new_types = {};
1564
                for my $attribute (@$attributes) {
1565
                for my $attribute (@$attributes) {
1565
                    $self->add_extended_attribute($attribute);
1566
                    $self->add_extended_attribute($attribute);
1567
                    $new_types->{$attribute->{code}} = 1;
1568
                }
1569
1570
                # Check globally mandatory types
1571
                my @required_attribute_types = 
1572
                    Koha::Patron::Attribute::Types->search(
1573
                        {
1574
                            mandatory => 1,
1575
                            'borrower_attribute_types_branches.b_branchcode' =>
1576
                              undef
1577
                        },
1578
                        { join => 'borrower_attribute_types_branches' }
1579
                    )->get_column('class');
1580
                for my $type ( @required_attribute_types ) {
1581
                    Koha::Exceptions::Object::FKConstraint->throw(
1582
                        broken_fk => "$type",
1583
                        value     => "$type",
1584
                    ) if !$new_types->{$type};
1566
                }
1585
                }
1567
            }
1586
            }
1568
        );
1587
        );
(-)a/t/db_dependent/Koha/Patron.t (-2 / +37 lines)
Lines 369-375 subtest 'is_superlibrarian() tests' => sub { Link Here
369
369
370
subtest 'extended_attributes' => sub {
370
subtest 'extended_attributes' => sub {
371
371
372
    plan tests => 14;
372
    plan tests => 15;
373
373
374
    my $schema = Koha::Database->new->schema;
374
    my $schema = Koha::Database->new->schema;
375
    $schema->storage->txn_begin;
375
    $schema->storage->txn_begin;
Lines 614-618 subtest 'extended_attributes' => sub { Link Here
614
        is( $patron->extended_attributes->count, 0, 'Extended attributes storing rolled back' );
614
        is( $patron->extended_attributes->count, 0, 'Extended attributes storing rolled back' );
615
    };
615
    };
616
616
617
    subtest 'globally mandatory attributes tests' => sub {
618
619
        plan tests => 3;
620
621
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
622
623
        my $attribute_type_1 = $builder->build_object(
624
            {
625
                class => 'Koha::Patron::Attribute::Types',
626
                value => { mandatory => 1 }
627
            }
628
        );
629
630
        my $attribute_type_2 = $builder->build_object(
631
            {
632
                class => 'Koha::Patron::Attribute::Types',
633
                value => { mandatory => 0 }
634
            }
635
        );
636
637
        is( $patron->extended_attributes->count, 0, 'Patron has no extended attributes' );
638
639
        throws_ok
640
            {
641
                $patron->extended_attributes(
642
                    [
643
                        { code => $attribute_type_2->code, attribute => 'b' }
644
                    ]
645
                );
646
            }
647
            'Koha::Exceptions::Object::FKConstraint',
648
            'Exception thrown on missing mandatory attribute type';
649
650
        is( $patron->extended_attributes->count, 0, 'Extended attributes storing rolled back' );
651
    };
652
617
    $schema->storage->txn_rollback;
653
    $schema->storage->txn_rollback;
618
};
654
};
619
- 

Return to bug 27857