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

(-)a/Koha/Patron.pm (-1 / +9 lines)
Lines 23-28 use Modern::Perl; Link Here
23
use List::MoreUtils qw( any uniq );
23
use List::MoreUtils qw( any uniq );
24
use JSON qw( to_json );
24
use JSON qw( to_json );
25
use Unicode::Normalize qw( NFKD );
25
use Unicode::Normalize qw( NFKD );
26
use Try::Tiny;
26
27
27
use C4::Context;
28
use C4::Context;
28
use C4::Log qw( logaction );
29
use C4::Log qw( logaction );
Lines 646-652 sub merge_with { Link Here
646
            ];
647
            ];
647
            $attributes->delete; # We need to delete before trying to merge them to prevent exception on unique and repeatable
648
            $attributes->delete; # We need to delete before trying to merge them to prevent exception on unique and repeatable
648
            for my $attribute ( @$new_attributes ) {
649
            for my $attribute ( @$new_attributes ) {
649
                $self->add_extended_attribute($attribute);
650
                try {
651
                    $self->add_extended_attribute($attribute);
652
                } catch {
653
                    # Don't block the merge if there is a non-repeatable attribute that cannot be added to the current patron.
654
                    unless ( $_->isa('Koha::Exceptions::Patron::Attribute::NonRepeatable') ) {
655
                        $_->rethrow;
656
                    }
657
                };
650
            }
658
            }
651
659
652
            while (my ($r, $field) = each(%$RESULTSET_PATRON_ID_MAPPING)) {
660
            while (my ($r, $field) = each(%$RESULTSET_PATRON_ID_MAPPING)) {
(-)a/t/db_dependent/Koha/Patrons.t (-9 / +21 lines)
Lines 26-32 use Test::MockModule; Link Here
26
use Time::Fake;
26
use Time::Fake;
27
use DateTime;
27
use DateTime;
28
use JSON;
28
use JSON;
29
use Data::Dumper;
30
use utf8;
29
use utf8;
31
30
32
use C4::Circulation qw( AddIssue AddReturn );
31
use C4::Circulation qw( AddIssue AddReturn );
Lines 1676-1682 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1676
    is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" );
1675
    is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" );
1677
1676
1678
    subtest 'extended attributes' => sub {
1677
    subtest 'extended attributes' => sub {
1679
        plan tests => 5;
1678
        plan tests => 8;
1680
1679
1681
        my $keep_patron =
1680
        my $keep_patron =
1682
          $builder->build_object( { class => 'Koha::Patrons' } );
1681
          $builder->build_object( { class => 'Koha::Patrons' } );
Lines 1763-1769 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1763
        $keep_patron->delete;
1762
        $keep_patron->delete;
1764
        $merge_patron->delete;
1763
        $merge_patron->delete;
1765
1764
1766
        # Recreate but expect an exception because 2 "normal" attributes will be in the resulting patron
1765
        # Recreate but don't expect an exception if 2 non-repeatable attributes exist, pick the one from the patron we keep
1767
        $keep_patron =
1766
        $keep_patron =
1768
          $builder->build_object( { class => 'Koha::Patrons' } );
1767
          $builder->build_object( { class => 'Koha::Patrons' } );
1769
        $merge_patron =
1768
        $merge_patron =
Lines 1780-1790 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1780
            ]
1779
            ]
1781
        );
1780
        );
1782
1781
1783
        throws_ok {
1782
        $keep_patron->merge_with( [ $merge_patron->borrowernumber ] );
1784
            $keep_patron->merge_with( [ $merge_patron->borrowernumber ] );
1783
        $merged_attributes = $keep_patron->extended_attributes;
1785
        }
1784
        is( $merged_attributes->count, 4 );
1786
        'Koha::Exceptions::Patron::Attribute::NonRepeatable',
1785
        compare_attributes(
1787
            'Exception thrown trying to merge several non-repeatable attributes';
1786
            $merged_attributes,
1787
            ['from attr 1'],
1788
            $attribute_type_normal_1->code
1789
        );
1790
        compare_attributes(
1791
            $merged_attributes,
1792
            ['to attr 2'],
1793
            $attribute_type_normal_2->code
1794
        );
1795
        compare_attributes(
1796
            $merged_attributes,
1797
            [ 'from attr repeatable', 'to attr repeatable' ],
1798
            $attribute_type_repeatable->code
1799
        );
1800
1788
    };
1801
    };
1789
1802
1790
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
1803
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
1791
- 

Return to bug 29059