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 634-640 sub merge_with { Link Here
634
            ];
635
            ];
635
            $attributes->delete; # We need to delete before trying to merge them to prevent exception on unique and repeatable
636
            $attributes->delete; # We need to delete before trying to merge them to prevent exception on unique and repeatable
636
            for my $attribute ( @$new_attributes ) {
637
            for my $attribute ( @$new_attributes ) {
637
                $self->add_extended_attribute($attribute);
638
                try {
639
                    $self->add_extended_attribute($attribute);
640
                } catch {
641
                    # Don't block the merge if there is a non-repeatable attribute that cannot be added to the current patron.
642
                    unless ( $_->isa('Koha::Exceptions::Patron::Attribute::NonRepeatable') ) {
643
                        $_->rethrow;
644
                    }
645
                };
638
            }
646
            }
639
647
640
            while (my ($r, $field) = each(%$RESULTSET_PATRON_ID_MAPPING)) {
648
            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 1658-1664 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1658
    is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" );
1657
    is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" );
1659
1658
1660
    subtest 'extended attributes' => sub {
1659
    subtest 'extended attributes' => sub {
1661
        plan tests => 5;
1660
        plan tests => 8;
1662
1661
1663
        my $keep_patron =
1662
        my $keep_patron =
1664
          $builder->build_object( { class => 'Koha::Patrons' } );
1663
          $builder->build_object( { class => 'Koha::Patrons' } );
Lines 1745-1751 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1745
        $keep_patron->delete;
1744
        $keep_patron->delete;
1746
        $merge_patron->delete;
1745
        $merge_patron->delete;
1747
1746
1748
        # Recreate but expect an exception because 2 "normal" attributes will be in the resulting patron
1747
        # Recreate but don't expect an exception if 2 non-repeatable attributes exist, pick the one from the patron we keep
1749
        $keep_patron =
1748
        $keep_patron =
1750
          $builder->build_object( { class => 'Koha::Patrons' } );
1749
          $builder->build_object( { class => 'Koha::Patrons' } );
1751
        $merge_patron =
1750
        $merge_patron =
Lines 1762-1772 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1762
            ]
1761
            ]
1763
        );
1762
        );
1764
1763
1765
        throws_ok {
1764
        $keep_patron->merge_with( [ $merge_patron->borrowernumber ] );
1766
            $keep_patron->merge_with( [ $merge_patron->borrowernumber ] );
1765
        $merged_attributes = $keep_patron->extended_attributes;
1767
        }
1766
        is( $merged_attributes->count, 4 );
1768
        'Koha::Exceptions::Patron::Attribute::NonRepeatable',
1767
        compare_attributes(
1769
            'Exception thrown trying to merge several non-repeatable attributes';
1768
            $merged_attributes,
1769
            ['from attr 1'],
1770
            $attribute_type_normal_1->code
1771
        );
1772
        compare_attributes(
1773
            $merged_attributes,
1774
            ['to attr 2'],
1775
            $attribute_type_normal_2->code
1776
        );
1777
        compare_attributes(
1778
            $merged_attributes,
1779
            [ 'from attr repeatable', 'to attr repeatable' ],
1780
            $attribute_type_repeatable->code
1781
        );
1782
1770
    };
1783
    };
1771
1784
1772
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
1785
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
1773
- 

Return to bug 29059