Bug 14570: Add about.pl entry for wrong relationship data
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 19 Aug 2019 13:32:06 +0000 (10:32 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 20 Aug 2019 15:06:36 +0000 (16:06 +0100)
This patch adds a check and an entry to the about.pl, for bad
relationship data. The checks are:

- 'relationship' containing '_bad_data' (generated by the atomicupdate
  on undef relationships.
- 'relationship' values that are not in the borrowerRelationship
syspref.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

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

index 4738c32..31b30db 100755 (executable)
--- a/about.pl
+++ b/about.pl
@@ -460,6 +460,52 @@ $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
         );
     }
 }
+
+# Guarantor relationships warnings
+{
+    my $dbh   = C4::Context->dbh;
+    my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
+        SELECT COUNT(*)
+        FROM (
+            SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
+            UNION ALL
+            SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
+    });
+
+    $bad_relationships_count = $bad_relationships_count->[0]->[0];
+
+    my @existing_relationships = $dbh->selectall_array(q{
+        SELECT DISTINCT(relationship)
+        FROM (
+            SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
+            UNION ALL
+            SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
+    });
+
+    my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
+    $valid_relationships{ _bad_data } = 1; # we handle this case in another way
+
+    my @wrong_relationships = grep { !$valid_relationships{ $_->[0] } } @existing_relationships;
+
+    if ( @wrong_relationships or $bad_relationships_count ) {
+
+        $template->param(
+            warnRelationships => 1,
+        );
+
+        if ( @wrong_relationships ) {
+            $template->param(
+                wrong_relationships => \@wrong_relationships
+            );
+        }
+        if ($bad_relationships_count) {
+            $template->param(
+                bad_relationships_count => $bad_relationships_count,
+            );
+        }
+    }
+}
+
 my %versions = C4::Context::get_versions();
 
 $template->param(
index 712dce7..5b8c1c4 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 || bad_yaml_prefs %]
+    [% 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 || warnRelationships %]
         [% 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 warnRelationships %]
+            <h2>Patron relationship problems</h2>
+            [% IF bad_relationships_count %]
+                <p>Your database contained guarantee/guarantor pairs with no defined relationship. They have been set the value '_bad_data' in the [% "borrowers.relationship" | $HtmlTags tag="strong" %] and/or [% "borrower_relationships.relationship" | $HtmlTags tag="strong" %] columns. Fix them manually by recreating those relationships, or have your system's administrator correct the values.</p>
+            [% END %]
+
+            [% IF wrong_relationships %]
+                <p>The following values have been used for guarantee/guarantor relationships, but do not exist in the 'borrowerRelationship' system preference:</p>
+                <ul>
+                    [% FOR rel IN wrong_relationships %]
+                        <li>[% rel.0 | html %]</li>
+                    [% END %]
+                </ul>
+                <p>If the relationship is one you want, please add it to the 'borrowerRelationship' system preference, otherwise have your system's administrator correct the values in [% "borrowers.relationship" | $HtmlTags tag="strong" %] and/or [% "borrower_relationships.relationship" | $HtmlTags tag="strong" %] in the database.</p>
+            [% END %]
+        [% END %]
+
         [% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatron || warnPrefAnonymousPatron_PatronDoesNotExist || warnNoActiveCurrency || QueryParserError || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || oauth2_missing_deps || bad_yaml_prefs || warnIssuingRules %]
             <h2>Warnings regarding the system configuration</h2>
             <table>