From ce1ed2fab4255e9e0cc7785afed27135a16ec04e Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 11 Aug 2014 12:09:16 -0300 Subject: [PATCH] Bug 12745: Add a sanity check for QueryParser configuration on about.pl MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently there's no way for the user to know he has a bad QueryParser configuration. Koha would just fallback to not using it. This patch adds a check for QueryParser configuration sanity in about.pl To test: - Have UseQueryParser = "Don't try" - Go to More > About Koha > System information - No QueryParser-related warnings - Set UseQueryParser = "Try" - Go to More > About Koha > System information - On a normal setup you shouldn't have any QueryParser-related warnings - Edit your koha-conf.xml file and change the queryparser_config entry to a non-existent filename. - Reload More > About Koha > System information => SUCCESS: a warning message tells you the filename used, and says it failed. - Now just delete the entry in koha-conf.xml - Reload More > About Koha > System information => SUCCESS: a warning message tells you don't have the queryparser_entry in your koha-conf.xml file. Subtest: a - The file /etc/koha/searchengine/queryparser.yaml exists: => SUCCESS: a warning saying it used a fallback is shown b - The file doesn't exist => SUCCESS: Missing entry warning, plus a failure message for the fallback. - Sign off :-D Regards To+ Sponsored-by: Universidad Nacional de Cordoba Followed test plan. Works as expected. Signed-off-by: Marc Véron Signed-off-by: Katrin Fischer With the typo in the path (non existing file), 'no warnings' is stil shown below the warnings. The follow-up fixes that. Signed-off-by: Tomas Cohen Arazi --- about.pl | 29 +++++++++++++++++++ .../intranet-tmpl/prog/en/modules/about.tt | 23 ++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/about.pl b/about.pl index 8b9c1e75b5..b197cd36a3 100755 --- a/about.pl +++ b/about.pl @@ -92,6 +92,35 @@ if ( ! defined C4::Context->config('zebra_auth_index_mode') ) { }; } +# Test QueryParser configuration sanity +if ( C4::Context->preference( 'UseQueryParser' ) ) { + # Get the QueryParser configuration file name + my $queryparser_file = C4::Context->config( 'queryparser_config' ); + my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml'; + # Check QueryParser is functional + my $QParser = C4::Context->queryparser(); + my $queryparser_error = {}; + if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) { + # Error initializing the QueryParser object + # Get the used queryparser.yaml file path to report the user + $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1; + $queryparser_error->{ file } = ( defined $queryparser_file ) + ? $queryparser_file + : $queryparser_fallback_file; + # Report error data to the template + $template->param( QueryParserError => $queryparser_error ); + } else { + # Check for an absent queryparser_config entry in koha-conf.xml + if ( ! defined $queryparser_file ) { + # Not an error but a warning for the missing entry in koha-conf-xml + push @xml_config_warnings, { + error => 'queryparser_entry_missing', + file => $queryparser_fallback_file + }; + } + } +} + $template->param( kohaVersion => $kohaVersion, osVersion => $osVersion, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt index d434624be9..23b3bb0b76 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -104,7 +104,8 @@

Please log in instead with a regular staff account. To create a staff account, create a library, a patron category 'Staff' and add a new patron. Then give this patron permissions from 'More' in the toolbar.

[% END %]

Warnings regarding the system configuration

- [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || warnNoActiveCurrency %] + [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || + warnNoActiveCurrency || QueryParserError %] [% IF (warnPrefBiblioAddsAuthorities) %] @@ -119,6 +120,19 @@ [% IF warnNoActiveCurrency %] [% END %] + [% IF QueryParserError %] + + + [% END %] +
Preferences and parameters
Warning No active currency is defined. Please go to Administration > Currencies and exchange rates and mark one currency as active.
Warning + You have set UseQueryParser but there was a problem inititializing QueryParser. + [% IF QueryParserError.fallback %] + The 'queryparser_config' entry is missing in your configuration file. + [% QueryParserError.file %] was used instead without success. + [% ELSE %] + The following configuration file was used without success: [% QueryParserError.file %]. + [% END %] +
[% END %] [% IF xml_config_warnings.size %] @@ -129,6 +143,13 @@ Warning The <zebra_bib_index_mode> entry is missing in your configuration file. It should be set to dom or grs1. It will default to grs1 but this could change in the future. [% ELSIF config_entry.error == 'zebra_auth_index_mode_warn' %] Warning The <zebra_auth_index_mode> entry is missing in your configuration file. It should be set to dom or grs1. It will default to dom but this could change in the future. + [% ELSIF config_entry.error == 'queryparser_entry_missing' %] + + Warning + You have set UseQueryParser but the 'queryparser_config' entry is missing in your configuration + file. [% config_entry.file %] is used as a fallback. + + [% END %] [% END %] -- 2.39.5