From a25bd1daa5213ebdd9487e056b6cb5eb66055739 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 12 Nov 2019 11:04:42 +0100 Subject: [PATCH] Bug 23846: Display degraded view when MARCXML is invalid (staff detail) When an invalid bibliographic record is imported into the catalogue there is not warning or error. However the bibliographic record detail page will explode (Koha::Biblio::Metadata->record will raise an exception). This patch proposes to catch the exception on this view and display a warning about the situation. Note that editing/saving the record will fix the MARCXML data and so removes the warning (some black magic we should get rid of I suspect). Test plan: - Import a bibliographic record with invalid XML, you can add non printable characters, like 0x1F (CTRL-V 1F with vim) - Go to the detail page => Without this patch you get a 500 => With this patch applied you get a "degraded view" with a warning message, telling you what the error is. Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize (cherry picked from commit 068943f18d60edc231b59b6232fecabaf1c799ab) Signed-off-by: Fridolin Somers --- catalogue/detail.pl | 9 ++++++++- .../intranet-tmpl/prog/en/modules/catalogue/detail.tt | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index b7e4d6eced..18a5778c36 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -87,6 +87,9 @@ if ( not defined $record ) { exit; } +eval { $biblio->metadata->record }; +$template->param( decoding_error => $@ ); + if($query->cookie("holdfor")){ my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") ); $template->param( @@ -118,7 +121,11 @@ if ( $xslfile ) { } $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") ); -$template->param( ocoins => $biblio->get_coins ); + +# Catch the exception as Koha::Biblio::Metadata->record can explode if the MARCXML is invalid +# Do not propagate it as we already deal with it previously in this script +my $coins = eval { $biblio->get_coins }; +$template->param( ocoins => $coins ); # some useful variables for enhanced content; # in each case, we're grabbing the first value we find in diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt index a963b84804..9f145d5ad9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -64,6 +64,12 @@ [% ELSE %] [% INCLUDE 'cat-toolbar.inc' %] + [% IF decoding_error %] +
+ There is an error with this bibliographic record, the view may be degraded. +
Error: [% decoding_error %] +
+ [% END %] [% IF ( ocoins ) %] -- 2.39.5