From 0f2c38f16a08c814751287f02fcf7ddd92325c23 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 Signed-off-by: David Nind Signed-off-by: Tomas Cohen Arazi --- Koha/Biblio.pm | 35 ++++++++++++++--------------------- t/db_dependent/Koha/Biblio.t | 7 +++++-- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 7b0422e9bd..afecf22ca6 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') ) { @@ -657,9 +655,8 @@ Returns the COinS (a span) which can be included in a biblio record sub get_coins { my ( $self ) = @_; - my $record; - eval { $record = $self->metadata->record }; - return if !$record; + my $record = eval { $self->metadata->record }; + unless ( $record ) { warn $@ ; return } my $pos7 = substr $record->leader(), 7, 1; my $pos6 = substr $record->leader(), 6, 1; @@ -852,9 +849,8 @@ sub is_serial { return 1 if $self->serial; - my $record; - eval { $record = $self->metadata->record }; - return 0 if !$record; + my $record = eval { $self->metadata->record }; + unless ( $record ) { warn $@ ; return 0 } return 1 if substr($record->leader, 7, 1) eq 's'; @@ -894,9 +890,8 @@ sub custom_cover_image_url { my $field = $+{field}; my $subfield = $+{subfield}; - my $record; - eval { $record = $self->metadata->record }; - return "" if !$record; + my $record = eval { $self->metadata->record }; + unless ( $record ) { warn $@ ; return q{} } my $value; if ( $subfield ) { @@ -957,9 +952,8 @@ sub get_marc_notes { my %hiddenlist = map { $_ => 1 } split( /,/, C4::Context->preference('NotesToHide')); - my $record; - eval { $record = $self->metadata->record }; - return [] if !$record; + my $record = eval { $self->metadata->record }; + unless ( $record ) { warn $@ ; return [] } $record = transformMARCXML4XSLT( $self->biblionumber, $record, $opac ); @@ -1140,9 +1134,8 @@ sub get_marc_host { return if C4::Context->preference('marcflavour') eq 'UNIMARC'; # TODO return if $params->{no_items} && $self->items->count > 0; - my $record; - eval { $record = $self->metadata->record }; - return if !$record; + my $record = eval { $self->metadata->record }; + unless ( $record ) { warn $@ ; return } # We pick the first $w with your MARCOrgCode or the first $w that has no # code (between parentheses) at all. diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 8aa5bbe5d9..e828b878f6 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.32.0