From c435c8c7d13110ab72efdf2877d3fc80f5487e72 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Thu, 28 Apr 2011 14:39:45 +0100 Subject: [PATCH] Bug 6280 : Don't generate invalid SQL in GetPendingIssues Change to parameter list in GetPendingIssues made it callable by an empty list resulting in invalid sql being sent to server. As this was occuring on most issues error log was filling up. Put safeguard in the routine Also don't bother calling when you have no need Some of the processing was needlessly obscure Signed-off-by: Owen Leonard Signed-off-by: Paul Poulain Signed-off-by: Chris Cormack --- C4/Members.pm | 19 +++++++++++++------ circ/circulation.pl | 8 ++++++-- members/moremember.pl | 9 ++++++--- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index ce694e590e..dcc168b9c4 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1032,13 +1032,19 @@ The keys include C fields except marc and marcxml. #' sub GetPendingIssues { - my (@borrowernumbers) = @_; + my @borrowernumbers = @_; + + unless (@borrowernumbers ) { # return a ref_to_array + return \@borrowernumbers; # to not cause surprise to caller + } # Borrowers part of the query my $bquery = ''; for (my $i = 0; $i < @borrowernumbers; $i++) { - $bquery .= " borrowernumber = ?"; - $bquery .= " OR" if ($i < (scalar(@borrowernumbers) - 1)); + $bquery .= ' borrowernumber = ?'; + if ($i < $#borrowernumbers ) { + $bquery .= ' OR'; + } } # must avoid biblioitems.* to prevent large marc and marcxml fields from killing performance @@ -1079,9 +1085,10 @@ sub GetPendingIssues { $sth->execute(@borrowernumbers); my $data = $sth->fetchall_arrayref({}); my $today = C4::Dates->new->output('iso'); - foreach (@$data) { - $_->{date_due} or next; - ($_->{date_due} lt $today) and $_->{overdue} = 1; + foreach (@{$data}) { + if ($_->{date_due} and $_->{date_due} lt $today) { + $_->{overdue} = 1; + } } return $data; } diff --git a/circ/circulation.pl b/circ/circulation.pl index c34db54344..da4878f94e 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -463,8 +463,11 @@ if ($borrower) { #push @borrowernumbers, $borrower->{'borrowernumber'}; # get each issue of the borrower & separate them in todayissues & previous issues - my ($issueslist) = GetPendingIssues($borrower->{'borrowernumber'}); - my ($relissueslist) = GetPendingIssues(@relborrowernumbers); + my $issueslist = GetPendingIssues($borrower->{'borrowernumber'}); + my $relissueslist = []; + if ( @relborrowernumbers ) { + $relissueslist = GetPendingIssues(@relborrowernumbers); + } build_issue_data($issueslist, 0); build_issue_data($relissueslist, 1); @@ -477,6 +480,7 @@ if ($borrower) { else { @todaysissues = sort { $b->{'timestamp'} cmp $a->{'timestamp'} } @todaysissues; } + if ( C4::Context->preference( "previousIssuesDefaultSortOrder" ) eq 'asc' ){ @previousissues = sort { $a->{'date_due'} cmp $b->{'date_due'} } @previousissues; } diff --git a/members/moremember.pl b/members/moremember.pl index 9292fd0d96..bfaa4029f1 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -236,9 +236,12 @@ if ( C4::Context->preference('OPACPrivacy') ) { # my @borrowernumbers = GetMemberRelatives($borrowernumber); my $issue = GetPendingIssues($borrowernumber); -my $relissue = GetPendingIssues(@borrowernumbers); -my $issuecount = scalar(@$issue); -my $relissuecount = scalar(@$relissue); +my $relissue = []; +if ( @borrowernumbers ) { + $relissue = GetPendingIssues(@borrowernumbers); +} +my $issuecount = @{$issue}; +my $relissuecount = @{$relissue}; my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} ); my $today = POSIX::strftime("%Y-%m-%d", localtime); # iso format my @issuedata; -- 2.39.5