From 81b2c7262c0dbaefec18644a38ca4f7c5e23080c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 13 Jan 2022 06:21:15 +0100 Subject: [PATCH] Bug 29690: Prevent detail.pl to crash if MARCXML is invalid 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: Fridolin Somers --- catalogue/detail.pl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index bc28f29cc1..1146aa78d8 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -95,7 +95,7 @@ if ( not defined $record ) { exit; } -eval { $biblio->metadata->record }; +my $marc_record = eval { $biblio->metadata->record }; $template->param( decoding_error => $@ ); if($query->cookie("holdfor")){ @@ -145,8 +145,6 @@ $template->param( normalized_isbn => $isbn, ); -my $marcnotesarray = $biblio->get_marc_notes({ marcflavour => $marcflavour }); - my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; my $dbh = C4::Context->dbh; @@ -221,7 +219,7 @@ if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { $template->param( ComponentPartsQuery => $biblio->get_components_query ); } } else { # check if we should show analytics anyway - $show_analytics = 1 if @{$biblio->get_marc_components(1)}; # count matters here, results does not + $show_analytics = 1 if $marc_record && @{$biblio->get_marc_components(1)}; # count matters here, results does not $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->messages}; } @@ -452,7 +450,7 @@ $template->param( ); $template->param( - MARCNOTES => $marcnotesarray, + MARCNOTES => $marc_record ? $biblio->get_marc_notes({ marcflavour => $marcflavour }) : (), itemdata_ccode => $itemfields{ccode}, itemdata_enumchron => $itemfields{enumchron}, itemdata_uri => $itemfields{uri}, -- 2.34.0