From 7624ab0a96a795aeb7fec3852659c5861b4fef8d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 6 May 2021 10:50:07 +0200 Subject: [PATCH] Bug 28220: Handle NonRepeatable Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Patrons/Import.pm | 3 +++ t/db_dependent/Koha/Patrons/Import.t | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index e3880eda44..38b1c7f44d 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -402,6 +402,9 @@ sub import_patrons { push @errors, { patron_attribute_unique_id_constraint => 1, patron_id => $patron_id, attribute => $_->attribute }; } elsif ( $_->isa('Koha::Exceptions::Patron::Attribute::InvalidType') ) { push @errors, { patron_attribute_invalid_type => 1, patron_id => $patron_id, attribute_type_code => $_->type }; + } elsif ( $_->isa('Koha::Exceptions::Patron::Attribute::NonRepeatable') ) { + push @errors, { patron_attribute_non_repeatable => 1, patron_id => $patron_id, attribute => $_->attribute }; + } else { push @errors, { unknown_error => 1 }; } diff --git a/t/db_dependent/Koha/Patrons/Import.t b/t/db_dependent/Koha/Patrons/Import.t index edc9544944..c8ff7ada9c 100755 --- a/t/db_dependent/Koha/Patrons/Import.t +++ b/t/db_dependent/Koha/Patrons/Import.t @@ -845,7 +845,7 @@ subtest 'test_format_dates' => sub { subtest 'patron_attributes' => sub { - plan tests => 10; + plan tests => 16; t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); @@ -938,6 +938,8 @@ subtest 'patron_attributes' => sub { my $fh = build_csv({ %$attributes }); my $result = $patrons_import->import_patrons({file => $fh, matchpoint => 'cardnumber'}); + is( $result->{imported}, 0 ); + my $error = $result->{errors}->[0]; is( $error->{patron_attribute_invalid_type}, 1 ); is( $error->{patron_id}, $cardnumber ); @@ -948,6 +950,24 @@ subtest 'patron_attributes' => sub { } + { # NonRepeatable + my $attributes = { + $repeatable_attribute_type->code => ['my repeatable attribute 1', 'my repeatable attribute 2'], + $normal_attribute_type->code => ['my normal attribute 1', 'my normal attribute 2'], + }; + my $fh = build_csv({ %$attributes }); + my $result = $patrons_import->import_patrons({file => $fh, matchpoint => 'cardnumber'}); + is( $result->{imported}, 0 ); + + my $error = $result->{errors}->[0]; + is( $error->{patron_attribute_non_repeatable}, 1 ); + is( $error->{patron_id}, $cardnumber ); + is( $error->{attribute}->code, $normal_attribute_type->code ); + + my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); + is( $patron, undef ); + } + }; # got is { code => $code, attribute => $attribute } -- 2.39.5