From b369d32bdf3b035e9b3e91f1125c74571ba8a68e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 6 May 2021 10:46:24 +0200 Subject: [PATCH] Bug 28220: Handle InvalidType Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Patrons/Import.pm | 4 +++- t/db_dependent/Koha/Patrons/Import.t | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index 13597c3423..e3880eda44 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -397,9 +397,11 @@ sub import_patrons { }); } catch { $invalid++; + my $patron_id = defined $matchpoint ? $borrower{$matchpoint} : $matchpoint_attr_type; if ( $_->isa('Koha::Exceptions::Patron::Attribute::UniqueIDConstraint') ) { - my $patron_id = defined $matchpoint ? $borrower{$matchpoint} : $matchpoint_attr_type; 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 }; } 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 b343b60f86..edc9544944 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 => 6; + plan tests => 10; t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); @@ -906,7 +906,7 @@ subtest 'patron_attributes' => sub { $patron->delete; } - { + { # UniqueIDConstraint $builder->build_object( { class => 'Koha::Patron::Attributes', @@ -926,6 +926,23 @@ subtest 'patron_attributes' => sub { is( $error->{patron_id}, $cardnumber ); is( $error->{attribute}->code, $unique_attribute_type->code ); + my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); + is( $patron, undef, 'Patron is not created' ); + } + + { #InvalidType + my $attributes = { + $non_existent_attribute_type_code => ['my non-existent attribute'], + $normal_attribute_type->code => ['my attribute 1'], + }; + my $fh = build_csv({ %$attributes }); + + my $result = $patrons_import->import_patrons({file => $fh, matchpoint => 'cardnumber'}); + my $error = $result->{errors}->[0]; + is( $error->{patron_attribute_invalid_type}, 1 ); + is( $error->{patron_id}, $cardnumber ); + is( $error->{attribute_type_code}, $non_existent_attribute_type_code ); + my $patron = Koha::Patrons->find({cardnumber => $cardnumber}); is( $patron, undef ); -- 2.39.5