Bug 21502: Add check for YAML formatted system preferences to about page
authorJosef Moravec <josef.moravec@gmail.com>
Fri, 5 Oct 2018 13:43:54 +0000 (13:43 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 29 Apr 2019 12:44:07 +0000 (12:44 +0000)
So far there are these yaml formatted preferences:
    UpdateNotForLoanStatusOnCheckin
    OpacHiddenItems
    BibtexExportAdditionalFields
    RisExportAdditionalFields
    UpdateItemWhenLostFromHoldList
    MarcFieldsToOrder
    MarcItemFieldsToOrder

Test plan:
1) Add some badly formatted YAML into some of preferences listed above
2) Check the System information tab on About page for appropriate warnings

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

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

index 349dfc9..f0beceb 100755 (executable)
--- a/about.pl
+++ b/about.pl
@@ -32,6 +32,7 @@ use XML::Simple;
 use Config;
 use Search::Elasticsearch;
 use Try::Tiny;
+use YAML;
 
 use C4::Output;
 use C4::Auth;
@@ -385,6 +386,29 @@ if (  C4::Context->preference('WebBasedSelfCheck')
     );
 }
 
+# Test YAML system preferences
+# FIXME: This is list of current YAML formatted prefs, should by type of preference
+my @yaml_prefs = (
+    "UpdateNotForLoanStatusOnCheckin",
+    "OpacHiddenItems",
+    "BibtexExportAdditionalFields",
+    "RisExportAdditionalFields",
+    "UpdateItemWhenLostFromHoldList",
+    "MarcFieldsToOrder",
+    "MarcItemFieldsToOrder"
+);
+my @bad_yaml_prefs;
+foreach my $syspref (@yaml_prefs) {
+    my $yaml = C4::Context->preference( $syspref );
+    if ( $yaml ) {
+        eval { YAML::Load( "$yaml\n\n" ); };
+        if ($@) {
+            push @bad_yaml_prefs, $syspref;
+        }
+    }
+}
+$template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
+
 {
     my $dbh       = C4::Context->dbh;
     my $patrons = $dbh->selectall_arrayref(
index 2616a6e..36b33bc 100644 (file)
         </div>
 
         <div id="sysinfo">
-    [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || warnPrefAnonymousPatron_PatronDoesNotExist || warnNoActiveCurrency || QueryParserError || warnIsRootUser || xml_config_warnings.size || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || has_ai_issues || oauth2_missing_deps %]
+    [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || warnPrefAnonymousPatron_PatronDoesNotExist || warnNoActiveCurrency || QueryParserError || warnIsRootUser || xml_config_warnings.size || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || has_ai_issues || oauth2_missing_deps || bad_yaml_prefs %]
         [% IF (warnIsRootUser) %]
             <h2>Warning regarding current user</h2>
             <p>You are logged in as the database administrative user. This is not recommended because some parts of Koha will not function as expected when using this account.</p>
             <br/>
         [% END %]
 
-        [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || warnPrefAnonymousPatron_PatronDoesNotExist || warnNoActiveCurrency || QueryParserError || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || oauth2_missing_deps %]
+        [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || warnPrefAnonymousPatron_PatronDoesNotExist || warnNoActiveCurrency || QueryParserError || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || oauth2_missing_deps || bad_yaml_prefs %]
             <h2>Warnings regarding the system configuration</h2>
             <table>
                 <caption>Preferences and parameters</caption>
                     System preference 'RESTOAuth2ClientCredentials' is set, but the required Net::OAuth2::AuthorizationServer dependency is missing. The feature is disabled.
                     </td></tr>
                 [% END %]
+                [% IF bad_yaml_prefs %]
+                    <tr><th scope="row"><b>Warning</b> </th><td>
+                    Some YAML formatted system preferences have bad format: [% bad_yaml_prefs.join(', ') | html %]
+                    </td></tr>
+                [% END %]
             </table>
         [% END %]
 
             [% END %]
             </table>
         [% END %]
+
     [% ELSE %]
         <p>No warnings.</p>
     [% END %]