From 063d401217fe9992b168028d5fa6b05df2d1c8a4 Mon Sep 17 00:00:00 2001 From: Barton Chittenden Date: Sun, 6 May 2018 12:49:52 -0700 Subject: [PATCH] Bug 5789 - Fines don't work when items have null homebranch 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. Signed-off-by: Pierre-Luc Lapointe --- misc/cronjobs/fines.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index 87c732e..08105ae 100755 --- a/misc/cronjobs/fines.pl +++ b/misc/cronjobs/fines.pl @@ -110,8 +110,15 @@ for my $overdue ( @{$overdues} ) { ( $control eq 'ItemHomeLibrary' ) ? $overdue->{homebranch} : ( $control eq 'PatronLibrary' ) ? $borrower->{branchcode} : $overdue->{branchcode}; + # In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here). + + unless( defined $branchcode ) { + warn( "Item home branch, borrower branch code or issues branchcode " + . "not defined. Cannot process fine for borrower cardnumber '$borrower->{cardnumber}', " + . "item barcode '$overdue->{branchcode}'"); + next; + } -# In final case, CircControl must be PickupLibrary. (branchcode comes from issues table here). if ( !exists $is_holiday{$branchcode} ) { $is_holiday{$branchcode} = set_holiday( $branchcode, $today ); } -- 2.7.4