From ab13f33eaee2599beb376366524d92afa79df034 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 --- 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 016225d814..4b1ad5c6ea 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -139,10 +139,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 7603f1646d..b35f54a724 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -101,6 +101,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 040af162e5..e374aa7d2e 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -196,10 +196,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