[Koha-patches] [PATCH] checkoverdues should not require $dbh
Joe Atzberger
joe.atzberger at liblime.com
Sat Jun 20 02:32:42 CEST 2009
Passing $dbh around is an ancient style that doesn't know
to use C4::Context. C4::Context->dbh is efficient, especially
for modules that already use Context, including almost all C4.
I also internalized $today into the SQL using NOW() in the query
and removed sth->finish. Even though I dislike the return style
that gives the count, then the array, I left it becuase I don't
have time to fix/test all the callers. However, I did convert
it so it doesn't require a $count variable and its own loop.
---
C4/Overdues.pm | 33 +++++++++++----------------------
1 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/C4/Overdues.pm b/C4/Overdues.pm
index 70ed23e..0815386 100644
--- a/C4/Overdues.pm
+++ b/C4/Overdues.pm
@@ -155,37 +155,26 @@ LEFT JOIN biblioitems USING (biblioitemnumber)
=head2 checkoverdues
-( $count, $overdueitems )=checkoverdues( $borrowernumber, $dbh );
+($count, $overdueitems) = checkoverdues($borrowernumber);
-Not exported
+Returns a count and a list of overdueitems for a given borrowernumber
=cut
sub checkoverdues {
-
-# From Main.pm, modified to return a list of overdueitems, in addition to a count
-#checks whether a borrower has overdue items
- my ( $borrowernumber, $dbh ) = @_;
- my @datearr = localtime;
- my $today =
- ( $datearr[5] + 1900 ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
- my @overdueitems;
- my $count = 0;
- my $sth = $dbh->prepare(
+ my $borrowernumber = shift or return;
+ my $sth = C4::Context->dbh->prepare(
"SELECT * FROM issues
- LEFT JOIN items ON issues.itemnumber = items.itemnumber
- LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
+ LEFT JOIN items ON issues.itemnumber = items.itemnumber
+ LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
WHERE issues.borrowernumber = ?
- AND issues.date_due < ?"
+ AND issues.date_due < NOW()"
);
- $sth->execute( $borrowernumber, $today );
- while ( my $data = $sth->fetchrow_hashref ) {
- push( @overdueitems, $data );
- $count++;
- }
- $sth->finish;
- return ( $count, \@overdueitems );
+ # FIXME: SELECT * across 4 tables? do we really need the marc AND marcxml blobs??
+ $sth->execute($borrowernumber);
+ my $results = $sth->fetchall_arrayref({});
+ return ( scalar(@$results), $results); # returning the count and the results is silly
}
=head2 CalcFine
--
1.5.6.5
More information about the Koha-patches
mailing list