From 6ec5e00e6aef5529850e09cc7a29dce9a0632f01 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 20 Oct 2021 12:46:07 +0000 Subject: [PATCH] Bug 29284: Don't die on analytics searching error This patch adds an eval around the call to search for analytic records It pases a value to the template on the staff side, but logs the warning on the opac This seems similar to 'decoding_error' which is noted on staff side, but absent on OPAC The eval follows the patter used during searching To test: 1 - Add a title to catalog, with 245a: Digger does it all (not really!) 2 - Set searchEngine preference to: Elasticsearch 3 - The record does not load 4 - Apply patch 5 - The record loads, there is a note about analytics at the top fo the record 6 - View record in opac, no note 7 - Check logs on intranet and opac, searching error is logged Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall (cherry picked from commit ab13f33eaee2599beb376366524d92afa79df034) Signed-off-by: Victor Grousset/tuxayo --- catalogue/detail.pl | 12 +++++++++--- .../prog/en/modules/catalogue/detail.tt | 6 ++++++ opac/opac-detail.pl | 12 ++++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 8771c3057b..2a11add468 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -133,10 +133,16 @@ if ( $xslfile ) { ( C4::Context->preference('UseControlNumber') and $record->field('001') ) ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)' : "Host-item:($cleaned_title)"; - my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 ); + my ( $err, $result, $count ); + eval { + ( $err, $result, $count ) = + $searcher->simple_search_compat( $query, 0, 0 ); - warn "Warning from simple_search_compat: $err" - if $err; + }; + if ($err || $@){ + warn "Warning from simple_search_compat: $err.$@"; + $template->param( analytics_error => 1 ); + } my $variables = { show_analytics_link => $count > 0 ? 1 : 0 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 6f4b4ab02f..a6d99447bc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -80,6 +80,12 @@
Error: [% decoding_error | html %]
[% END %] + [% IF analytics_error %] +
+ + There was an error searching for analytic records, please see the logs for details. +
+ [% END %] [% IF ( ocoins ) %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index fe84b254e8..e07143a751 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -190,10 +190,14 @@ if ( $xslfile ) { ( C4::Context->preference('UseControlNumber') and $record->field('001') ) ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)' : "Host-item:($cleaned_title)"; - my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 ); - - warn "Warning from simple_search_compat: $err" - if $err; + my ( $err, $result, $count ); + eval { + ( $err, $result, $count ) = + $searcher->simple_search_compat( $query, 0, 0 ); + }; + if ($err || $@){ + warn "Warning from simple_search_compat: $err.$@"; + } my $variables = { anonymous_session => ($borrowernumber) ? 0 : 1, -- 2.39.5