From aa4d3263874054d7263fb53ef6e2b4a9aacff37c Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 15 Mar 2016 11:00:42 +0000 Subject: [PATCH] Bug 9805 [QA Followup] - Stop calling GetMember repeatedly --- C4/Circulation.pm | 77 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 5506af4..f708161 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2986,18 +2986,24 @@ sub AddRenewal { return; } + my $borrower = C4::Members::GetMemberDetails( $borrowernumber ); + return unless $borrower; + # If the due date wasn't specified, calculate it by adding the # book's loan length to today's date or the current due date # based on the value of the RenewalPeriodBase syspref. unless ($datedue) { + my $itemtype = + C4::Context->preference('item-level_itypes') + ? $biblio->{'itype'} + : $biblio->{'itemtype'}; - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return; - my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; + $datedue = + C4::Context->preference('RenewalPeriodBase') eq 'date_due' + ? dt_from_string( $issuedata->{date_due} ) + : DateTime->now( time_zone => C4::Context->tz() ); - $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? - dt_from_string( $issuedata->{date_due} ) : - DateTime->now( time_zone => C4::Context->tz()); - $datedue = CalcDateDue($datedue, $itemtype, $issuedata->{'branchcode'}, $borrower, 'is a renewal'); + $datedue = CalcDateDue( $datedue, $itemtype, $issuedata->{'branchcode'}, $borrower, 'is a renewal' ); } # Update the issues record to have the new due date, and a new count @@ -3013,7 +3019,6 @@ sub AddRenewal { # Update the renewal count on the item, and tell zebra to reindex $renews = $biblio->{'renewals'} + 1; - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); my $schema = Koha::Database->new()->schema(); my $rule = $schema->resultset('DefaultBranchCircRule')->single( { branchcode => _GetCircControlBranch( $item, $borrower ) } ); $rule ||= $schema->resultset('DefaultCircRule')->single(); @@ -3059,27 +3064,27 @@ sub AddRenewal { } # Send a renewal slip according to checkout alert preferencei - if ( C4::Context->preference('RenewalSendNotice') eq '1') { - my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ); - my $circulation_alert = 'C4::ItemCirculationAlertPreference'; - my %conditions = ( - branchcode => $branch, - categorycode => $borrower->{categorycode}, - item_type => $item->{itype}, - notification => 'CHECKOUT', - ); - if ($circulation_alert->is_enabled_for(\%conditions)) { - SendCirculationAlert({ - type => 'RENEWAL', - item => $item, - borrower => $borrower, - branch => $branch, - }); - } + if ( C4::Context->preference('RenewalSendNotice') eq '1' ) { + my $circulation_alert = 'C4::ItemCirculationAlertPreference'; + my %conditions = ( + branchcode => $branch, + categorycode => $borrower->{categorycode}, + item_type => $item->{itype}, + notification => 'CHECKOUT', + ); + if ( $circulation_alert->is_enabled_for( \%conditions ) ) { + SendCirculationAlert( + { + type => 'RENEWAL', + item => $item, + borrower => $borrower, + branch => $branch, + } + ); + } } # Remove any OVERDUES related debarment if the borrower has no overdues - my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); if ( $borrowernumber && $borrower->{'debarred'} && !C4::Members::HasOverdues( $borrowernumber ) @@ -3089,15 +3094,19 @@ sub AddRenewal { } # Log the renewal - UpdateStats({branch => $branch, - type => 'renew', - amount => $charge, - itemnumber => $itemnumber, - itemtype => $item->{itype}, - borrowernumber => $borrowernumber, - ccode => $item->{'ccode'}} - ); - return $datedue; + UpdateStats( + { + branch => $branch, + type => 'renew', + amount => $charge, + itemnumber => $itemnumber, + itemtype => $item->{itype}, + borrowernumber => $borrowernumber, + ccode => $item->{'ccode'} + } + ); + + return $datedue; } sub GetRenewCount { -- 2.1.4