[Koha-bugs] [Bug 5789] Fines don't work when items have null homebranch

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Sun May 6 22:07:28 CEST 2018


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=5789

--- Comment #9 from Barton Chittenden <barton at bywatersolutions.com> ---
(In reply to Saiful Amin from comment #7)
> I've done some more digging into this and found that it was indeed a data
> issue, the item itself was missing. Single record caused the failure.
> 
> I feel that the error message does not do justice to the error. The script
> should not crash on faulty data. The final fix that I would suggest is this
> (as suggested in Comment #3):
> 
>   109     my $branchcode =
>   110         ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch}
>   111       : ( $control eq 'PatronLibrary' )   ? $borrower->{branchcode}
>   112       :                                     $overdue->{branchcode};
> + 113     if (!defined $branchcode ) {
> + 114         carp "ERROR in getting branchcode. Skipping record.\n";
> + 115         next;
> + 116     }
>   117
>   118 # In final case, CircControl must be PickupLibrary. (branchcode comes
> from issues table here).
>   119     if ( !exists $is_holiday{$branchcode} ) {
>   120         $is_holiday{$branchcode} = set_holiday( $branchcode, $today );

As luck would have it, I was writing my patch at the same time that you were
writing this; mine has the same logic but gives a bit more detail about which
item failed. Here's my test plan:

    When the CircControl system preference is set to 'the library the item is
from' and items.homebranch is not set,
    fines.pl will stop processing witha fatal error that looks something like
this:

        Use of uninitialized value $branchcode in exists at
/home/koha/kohaclone/misc/cronjobs/fines.pl line 110
        No branchcode argument passed to Koha::Calendar->new at
/home/koha/kohaclone/misc/cronjobs/fines.pl line 169.

    This patch will check the value of $branchcode before it is used. If
$branchcode is undefined, a warning will
    be issued and, processing will be skipped for that item, and continue for
the next item.

    To test:

    1) Set CircControl to  'the library the item is from'
    2) Check out items and back-date them to be overdue
    3) Set homebranch of one of the items to NULL
    4) Run misc/cronjobs/fines.pl, note that processing stops at that item.
    5) Apply patch
    6) Repeat step 4. not that processing completes.
    7) Check logs, you should see a warning message for the item missing its
homebranch.
    8) Sign off.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.
You are watching all bug changes.


More information about the Koha-bugs mailing list