Bugzilla – Attachment 107798 Details for
Bug 26132
Improve readability of TooMany
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26132: Remove raw SQL query for patron_maxissueqty
Bug-26132-Remove-raw-SQL-query-for-patronmaxissueq.patch (text/plain), 4.14 KB, created by
Nick Clemens (kidclamp)
on 2020-08-04 19:02:18 UTC
(
hide
)
Description:
Bug 26132: Remove raw SQL query for patron_maxissueqty
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2020-08-04 19:02:18 UTC
Size:
4.14 KB
patch
obsolete
>From 47b396f594451c796627d86e317ab48051790136 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 4 Aug 2020 12:12:56 +0200 >Subject: [PATCH] Bug 26132: Remove raw SQL query for patron_maxissueqty > >Same as before but for patron_maxissueqty > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > C4/Circulation.pm | 43 ++++++++++++++++++------------------------- > 1 file changed, 18 insertions(+), 25 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index d0d67184db..c95be4bf89 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -427,12 +427,12 @@ sub TooMany { > ); > > >+ my $patron = Koha::Patrons->find($borrower->{borrowernumber}); > # if a rule is found and has a loan limit set, count > # how many loans the patron already has that meet that > # rule > if (defined($maxissueqty_rule) and $maxissueqty_rule->rule_value ne "") { > >- my $patron = Koha::Patrons->find($borrower->{borrowernumber}); > my $checkouts = $patron->checkouts->search( {}, { prefetch => 'item' } ); > if ( $maxissueqty_rule->branchcode ) { > if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { >@@ -517,38 +517,31 @@ sub TooMany { > # Now count total loans against the limit for the branch > my $branch_borrower_circ_rule = GetBranchBorrowerCircRule($branch, $cat_borrower); > if (defined($branch_borrower_circ_rule->{patron_maxissueqty}) and $branch_borrower_circ_rule->{patron_maxissueqty} ne '') { >- my @bind_params = (); >- my $branch_count_query = q| >- SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts >- FROM issues >- JOIN items USING (itemnumber) >- WHERE borrowernumber = ? >- |; >- push @bind_params, $borrower->{borrowernumber}; >- >- if (C4::Context->preference('CircControl') eq 'PickupLibrary') { >- $branch_count_query .= " AND issues.branchcode = ? "; >- push @bind_params, $branch; >+ my $checkouts = $patron->checkouts->search({}, { prefetch => 'item' }); >+ if ( C4::Context->preference('CircControl') eq 'PickupLibrary' ) { >+ $checkouts = $checkouts->search({ 'me.branchcode' => $branch }); > } elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { > ; # if branch is the patron's home branch, then count all loans by patron > } else { >- $branch_count_query .= " AND items.homebranch = ? "; >- push @bind_params, $branch; >+ $checkouts = $checkouts->search({ 'item.homebranch' => $branch }); > } >- my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $branch_count_query, {}, @bind_params ); >+ >+ my $checkout_count = $checkouts->count; >+ my $onsite_checkout_count = $checkouts->search({ onsite_checkout => 1 })->count; > my $max_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxissueqty}; > my $max_onsite_checkouts_allowed = $branch_borrower_circ_rule->{patron_maxonsiteissueqty} || undef; > >- my $qty_over = _check_max_qty({ >- checkout_count => $checkout_count, >- onsite_checkout_count => $onsite_checkout_count, >- onsite_checkout => $onsite_checkout, >- max_checkouts_allowed => $max_checkouts_allowed, >- max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, >- switch_onsite_checkout => $switch_onsite_checkout >- }); >+ my $qty_over = _check_max_qty( >+ { >+ checkout_count => $checkout_count, >+ onsite_checkout_count => $onsite_checkout_count, >+ onsite_checkout => $onsite_checkout, >+ max_checkouts_allowed => $max_checkouts_allowed, >+ max_onsite_checkouts_allowed => $max_onsite_checkouts_allowed, >+ switch_onsite_checkout => $switch_onsite_checkout >+ } >+ ); > return $qty_over if defined $qty_over; >- > } > > if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{patron_maxissueqty}) ) { >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26132
:
107734
|
107735
|
107736
|
107737
|
107738
|
107796
|
107797
|
107798
|
107799
|
107800
|
107801
|
108147
|
108148
|
108149
|
108150
|
108151
|
108152
|
108153
|
113006
|
113007
|
113014
|
113034