Prevent fines failure on NULL borrowernumber.
authorJoe Atzberger <joe.atzberger@liblime.com>
Fri, 23 Jan 2009 22:22:40 +0000 (16:22 -0600)
committerGalen Charlton <galen.charlton@liblime.com>
Mon, 11 May 2009 22:43:38 +0000 (17:43 -0500)
The problem is that we do not ensure that the issues table has valid
borrowernumber in each line.  This is exacerbated by Getoverdues()
returning data sorted BY borrowernumber.  So one NULL borrowernumber
in issues prevented ALL fines from being assessed.  The actual error
from fines.pl cron log is:
  No branchcode argument to new.  Should be C4::Calendar->new(branchcode => $branchcode)
  at /home/user/kohaclone/misc/cronjobs/fines.pl line 98

This patch deals only with getting fines to avoid crashing.  It does
not fix the underlying data integrity problem.

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
misc/cronjobs/fines.pl

index 0e28357..de9e8cf 100755 (executable)
@@ -89,6 +89,10 @@ for (my $i=0; $i<scalar(@$data); $i++) {
     my $datedue = C4::Dates->new($data->[$i]->{'date_due'},'iso');
     my $datedue_days = Date_to_Days(split(/-/,$datedue->output('iso')));
     my $due_str = $datedue->output();
+    unless (defined $data->[$i]->{'borrowernumber'}) {
+        print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
+        next;   # Note: this doesn't solve everything.  After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up.
+    }
     my $borrower = BorType($data->[$i]->{'borrowernumber'});
     my $branchcode = ($control eq 'ItemHomeLibrary') ? $data->[$i]->{homebranch} :
                      ($control eq 'PatronLibrary'  ) ?   $borrower->{branchcode} :