From ea529962f7171f815bc71f6849d5c326097c2d4d 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 searchign 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 --- catalogue/detail.pl | 12 +++++++++--- .../prog/en/modules/catalogue/detail.tt | 6 ++++++ opac/opac-detail.pl | 11 ++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/catalogue/detail.pl b/catalogue/detail.pl index b5801cca71..4efffed9b8 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -140,10 +140,16 @@ my $marcflavour = C4::Context->preference("marcflavour"); ( 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 7c2b961d6c..57f7ac3d1c 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 eb9a6866b1..36c64d4f60 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -210,10 +210,15 @@ my $ean = GetNormalizedEAN( $record, $marcflavour ); ( 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.$@"; + } my $variables = { anonymous_session => ($borrowernumber) ? 0 : 1, -- 2.20.1