From d522d80c5cdb1f9c097e028499815dca6e9259cf Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 27 Mar 2019 13:55:05 +0000 Subject: [PATCH] Bug 22593: Fix bad ternaries after bug 22008 A series of ternaries were introduced when we moved to add_debit which defaulted to 'user 0' should a userenv not be set. This was incorrect as userenv may well not be set (during cronscript runs for example) and the new constraint would not allow such a default. We switch to 'undef' here to satisfy the constraint. Test plan 1) Ensure you have data in your system that would be caught by the longoverdues cronjob. 2) Ensure you're sysprefs are setup to charge for lost items 3) Run the script and varify it runs to completion without errors Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- C4/Accounts.pm | 7 +++---- C4/Circulation.pm | 2 +- C4/Reserves.pm | 2 +- Koha/Hold.pm | 2 +- Koha/Patron.pm | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 3fdf2d71b3..39b2bda305 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -106,7 +106,7 @@ sub chargelostitem{ amount => $processfee, description => $description, note => $processingfeenote, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, type => 'processing', item_id => $itemnumber, @@ -121,7 +121,7 @@ sub chargelostitem{ amount => $replacementprice, description => $description, note => undef, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, type => 'lost_item', item_id => $itemnumber, @@ -146,8 +146,7 @@ sub manualinvoice { deprecated "C4::Accounts::manualinvoice is deprecated in favor of Koha::Account->add_debit"; - my $manager_id = 0; - $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; + my $manager_id = C4::Context->userenv ? C4::Context->userenv->{'number'} : undef; my $dbh = C4::Context->dbh; my $insert; my $amountleft = $amount; diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 7ab1db7e82..e51bc33b7d 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3221,7 +3221,7 @@ sub AddIssuingCharge { amount => $charge, description => $description, note => undef, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, type => 'rent', item_id => $checkout->itemnumber, diff --git a/C4/Reserves.pm b/C4/Reserves.pm index de7e3f0a2c..09d36288e3 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -573,7 +573,7 @@ sub ChargeReserveFee { amount => $fee, description => "Reserve Charge - " . $title, note => undef, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, sip => undef, invoice_type => undef, diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 3b3aba8b26..37c7fa1c26 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -370,7 +370,7 @@ sub cancel { $account->add_debit( { amount => $charge, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, type => 'hold_expired', item_id => $self->itemnumber diff --git a/Koha/Patron.pm b/Koha/Patron.pm index bc7c8110c1..cc1892b855 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -850,7 +850,7 @@ sub add_enrolment_fee_if_needed { $self->account->add_debit( { amount => $enrolment_fee, - user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef, library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, type => 'account' } -- 2.39.5