From 5edd7fa29772677442e17c6a3a644ed81248955a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 14 Dec 2021 10:56:08 +0100 Subject: [PATCH] Bug 29690: Always warn if something is wrong with the metadata --- Koha/Biblio.pm | 10 ++++------ t/db_dependent/Koha/Biblio.t | 7 +++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index d5cf1cbb509..37a90e4f2b4 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -427,9 +427,8 @@ sub host_items { $analyticfield = '461'; } - my $record; - $record = eval { $self->metadata->record; }; - return if !$record; + my $record = eval { $self->metadata->record }; + unless ( $record ) { warn $@ ; return } my @itemnumbers; foreach my $field ( $record->field($analyticfield) ) { @@ -568,9 +567,8 @@ sub get_components_query { my $builder = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); - my $record; - eval { $record = $self->metadata->record }; - return if !$record; + my $record = eval { $self->metadata->record }; + unless ( $record ) { warn $@ ; return } my $searchstr; if ( C4::Context->preference('UseControlNumber') ) { diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 8331de65633..c9ac2bc96b6 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -565,7 +565,7 @@ subtest 'get_marc_components() tests' => sub { }; subtest 'get_components_query' => sub { - plan tests => 4; + plan tests => 5; my $biblio = $builder->build_sample_biblio(); my $biblionumber = $biblio->biblionumber; @@ -592,7 +592,10 @@ subtest 'get_components_query' => sub { $biblio->metadata->metadata('This is invalid for a MARC record')->store(); $biblio = Koha::Biblios->find( $biblio->biblionumber); - is($biblio->get_components_query, undef, "Invalid MARC record returns undefined and does not die"); + my $components_query; + warning_like { $biblio->get_components_query } + qr{^Invalid data, cannot decode metadata object}; + is( $components_query, undef, "Invalid MARC record returns undefined and does not die"); }; subtest 'orders() and active_orders() tests' => sub { -- 2.25.1