From 7cbfd8b2d8ea830ff942c0a49609999e938eb3d7 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi <tomascohen@gmail.com> Date: Mon, 11 Aug 2014 12:09:16 -0300 Subject: [PATCH] [PASSED QA] Bug 12745: Add a sanity check for QueryParser configuration on about.pl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 <veron@veron.ch> Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> With the typo in the path (non existing file), 'no warnings' is stil shown below the warnings. The follow-up fixes that. --- about.pl | 29 ++++++++++++++++++++++++ koha-tmpl/intranet-tmpl/prog/en/modules/about.tt | 23 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/about.pl b/about.pl index 8b9c1e7..b197cd3 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 d434624..23b3bb0 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 @@ <p>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.</p> [% END %] <h2>Warnings regarding the system configuration</h2> - [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || warnNoActiveCurrency %] + [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || + warnNoActiveCurrency || QueryParserError %] <table> <caption>Preferences and parameters</caption> [% IF (warnPrefBiblioAddsAuthorities) %] @@ -119,6 +120,19 @@ [% IF warnNoActiveCurrency %] <tr><th scope="row"><b>Warning</b> </th><td>No active currency is defined. Please go to <a href="/cgi-bin/koha/admin/currency.pl">Administration > Currencies and exchange rates</a> and mark one currency as active.</td></tr> [% END %] + [% IF QueryParserError %] + <tr><th scope="row"><b>Warning</b> </th><td> + You have set UseQueryParser but there was a problem inititializing QueryParser. + [% IF QueryParserError.fallback %] + The 'queryparser_config' entry is missing in your configuration file. + <strong>[% QueryParserError.file %]</strong> was used instead without success. + [% ELSE %] + The following configuration file was used without success: <strong>[% QueryParserError.file %]</strong>. + [% END %] + </td> + </tr> + [% END %] + </table> [% END %] [% IF xml_config_warnings.size %] @@ -129,6 +143,13 @@ <tr><th scope="row"><b>Warning</b> </th><td>The <zebra_bib_index_mode> entry is missing in your configuration file. It should be set to <strong>dom</strong> or <strong>grs1</strong>. It will default to <strong>grs1</strong> but this could change in the future.</td></tr> [% ELSIF config_entry.error == 'zebra_auth_index_mode_warn' %] <tr><th scope="row"><b>Warning</b> </th><td>The <zebra_auth_index_mode> entry is missing in your configuration file. It should be set to <strong>dom</strong> or <strong>grs1</strong>. It will default to <strong>dom</strong> but this could change in the future.</td></tr> + [% ELSIF config_entry.error == 'queryparser_entry_missing' %] + <tr> + <th scope="row"><b>Warning</b></th> + <td>You have set UseQueryParser but the 'queryparser_config' entry is missing in your configuration + file. <strong>[% config_entry.file %]</strong> is used as a fallback. + </td> + </tr> [% END %] [% END %] </table> -- 1.9.1