Bug 28220: Handle InvalidType

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2021-05-06 10:46:24 +02:00
parent fa100d8e5e
commit b369d32bdf
2 changed files with 22 additions and 3 deletions

View File

@ -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 };
}

View File

@ -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 );