From fc6e746a72852e2b971f37ac1dd6dc9ae8b80a98 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Mon, 13 Dec 2021 20:21:54 -1000 Subject: [PATCH] Bug 29690: Add eval on metadata record fetch in details.pl when invalid MARCXML Bug 23846 added support for invalid MARCXML. But now page details.pl fails again with software error. This comes from several Koha::Biblio calling $self->metadata->record without eval. Test plan : 1) Create a biblio record with invalid MARCXML (see Bug 29690) In koha-testing-docker there is biblionumber=369 2) Go to page cgi-bin/koha/catalogue/detail.pl?biblionumber=xxx 3) You see the page with a message : There is an error with this bibliographic record, the view may be degraded. Error: Invalid data, cannot decode metadata object ... Signed-off-by: Martin Renvoize --- Koha/Biblio.pm | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index c4c12128af..2101fe28bc 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -563,15 +563,18 @@ sub get_components_query { my $builder = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); - my $marc = $self->metadata->record; + + my $record; + eval { $record = $self->metadata->record }; + return if !$record; my $searchstr; if ( C4::Context->preference('UseControlNumber') ) { - my $pf001 = $marc->field('001') || undef; + my $pf001 = $record->field('001') || undef; if ( defined($pf001) ) { $searchstr = "("; - my $pf003 = $marc->field('003') || undef; + my $pf003 = $record->field('003') || undef; if ( !defined($pf003) ) { # search for 773$w='Host001' @@ -591,7 +594,7 @@ sub get_components_query { } } else { - my $cleaned_title = $marc->subfield('245', "a"); + my $cleaned_title = $record->subfield('245', "a"); $cleaned_title =~ tr|/||; $cleaned_title = $builder->clean_search_term($cleaned_title); $searchstr = "Host-item:($cleaned_title)"; @@ -650,7 +653,9 @@ Returns the COinS (a span) which can be included in a biblio record sub get_coins { my ( $self ) = @_; - my $record = $self->metadata->record; + my $record; + eval { $record = $self->metadata->record }; + return if !$record; my $pos7 = substr $record->leader(), 7, 1; my $pos6 = substr $record->leader(), 6, 1; @@ -940,7 +945,11 @@ sub get_marc_notes { my %hiddenlist = map { $_ => 1 } split( /,/, C4::Context->preference('NotesToHide')); - my $record = $self->metadata->record; + + my $record; + eval { $record = $self->metadata->record }; + return if !$record; + $record = transformMARCXML4XSLT( $self->biblionumber, $record, $opac ); foreach my $field ( $record->field($scope) ) { -- 2.20.1