Bug 12745: Add a sanity check for QueryParser configuration on about.pl
authorTomas Cohen Arazi <tomascohen@gmail.com>
Mon, 11 Aug 2014 15:09:16 +0000 (12:09 -0300)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Fri, 15 Aug 2014 17:39:21 +0000 (14:39 -0300)
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.

Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

about.pl
koha-tmpl/intranet-tmpl/prog/en/modules/about.tt

index 8b9c1e7..b197cd3 100755 (executable)
--- 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,
index d434624..23b3bb0 100644 (file)
             <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) %]
             [% 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 &gt; 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 %]
             <tr><th scope="row"><b>Warning</b> </th><td>The &lt;zebra_bib_index_mode&gt; 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 &lt;zebra_auth_index_mode&gt; 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>