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 645-651 sub merge_with { Link Here
645
            ];
646
            ];
646
            $attributes->delete; # We need to delete before trying to merge them to prevent exception on unique and repeatable
647
            $attributes->delete; # We need to delete before trying to merge them to prevent exception on unique and repeatable
647
            for my $attribute ( @$new_attributes ) {
648
            for my $attribute ( @$new_attributes ) {
648
                $self->add_extended_attribute($attribute);
649
                try {
650
                    $self->add_extended_attribute($attribute);
651
                } catch {
652
                    # Don't block the merge if there is a non-repeatable attribute that cannot be added to the current patron.
653
                    unless ( $_->isa('Koha::Exceptions::Patron::Attribute::NonRepeatable') ) {
654
                        $_->rethrow;
655
                    }
656
                };
649
            }
657
            }
650
658
651
            while (my ($r, $field) = each(%$RESULTSET_PATRON_ID_MAPPING)) {
659
            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 1688-1694 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1688
    is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" );
1687
    is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" );
1689
1688
1690
    subtest 'extended attributes' => sub {
1689
    subtest 'extended attributes' => sub {
1691
        plan tests => 5;
1690
        plan tests => 8;
1692
1691
1693
        my $keep_patron =
1692
        my $keep_patron =
1694
          $builder->build_object( { class => 'Koha::Patrons' } );
1693
          $builder->build_object( { class => 'Koha::Patrons' } );
Lines 1775-1781 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1775
        $keep_patron->delete;
1774
        $keep_patron->delete;
1776
        $merge_patron->delete;
1775
        $merge_patron->delete;
1777
1776
1778
        # Recreate but expect an exception because 2 "normal" attributes will be in the resulting patron
1777
        # Recreate but don't expect an exception if 2 non-repeatable attributes exist, pick the one from the patron we keep
1779
        $keep_patron =
1778
        $keep_patron =
1780
          $builder->build_object( { class => 'Koha::Patrons' } );
1779
          $builder->build_object( { class => 'Koha::Patrons' } );
1781
        $merge_patron =
1780
        $merge_patron =
Lines 1792-1802 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1792
            ]
1791
            ]
1793
        );
1792
        );
1794
1793
1795
        throws_ok {
1794
        $keep_patron->merge_with( [ $merge_patron->borrowernumber ] );
1796
            $keep_patron->merge_with( [ $merge_patron->borrowernumber ] );
1795
        $merged_attributes = $keep_patron->extended_attributes;
1797
        }
1796
        is( $merged_attributes->count, 4 );
1798
        'Koha::Exceptions::Patron::Attribute::NonRepeatable',
1797
        compare_attributes(
1799
            'Exception thrown trying to merge several non-repeatable attributes';
1798
            $merged_attributes,
1799
            ['from attr 1'],
1800
            $attribute_type_normal_1->code
1801
        );
1802
        compare_attributes(
1803
            $merged_attributes,
1804
            ['to attr 2'],
1805
            $attribute_type_normal_2->code
1806
        );
1807
        compare_attributes(
1808
            $merged_attributes,
1809
            [ 'from attr repeatable', 'to attr repeatable' ],
1810
            $attribute_type_repeatable->code
1811
        );
1812
1800
    };
1813
    };
1801
1814
1802
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
1815
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
1803
- 

Return to bug 29059