From 153877f10fd615213fb22f850965ca374b8c02c8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Dec 2015 11:10:33 +0000 Subject: [PATCH] Bug 15240: Do not process issues with a date due later than today MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit There is no need to do this job in Perl, MySQL could do it instead. The idea is to only retrieve the issues info which could be overdued. To test: 1/ Run the script 2/ Apply the patch 3/ Run the script again, notice the exact same results but execution time is faster Signed-off-by: Chris Cormack Signed-off-by: Marcel de Rooy Signed-off-by: Brendan A Gallagher (cherry picked from commit 0d36c27678a6968304990759657e2312338763eb) Signed-off-by: Julian Maurice (cherry picked from commit e46923af8829f7da9eb3b94e89831b32e68df040) Signed-off-by: Frédéric Demians --- misc/cronjobs/overdue_notices.pl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 908f3fc831..d749b50ab5 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -455,6 +455,7 @@ SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS($date)-TO_DAYS AND b.branchcode = items.homebranch AND biblio.biblionumber = biblioitems.biblionumber AND issues.borrowernumber = ? + AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0 END_SQL my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? "; @@ -500,15 +501,14 @@ END_SQL # itemcount is interpreted here as the number of items in the overdue range defined by the current notice or all overdues < max if(-list-all). # - my $borrower_sql = <<'END_SQL'; -SELECT issues.borrowernumber, firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email, smsalertnumber, phone, cardnumber, -TO_DAYS(?)-TO_DAYS(date_due) as difference, date_due + my $borrower_sql = <<"END_SQL"; +SELECT issues.borrowernumber, firstname, surname, address, address2, city, zipcode, country, email, emailpro, B_email, smsalertnumber, phone, cardnumber, date_due FROM issues,borrowers,categories WHERE issues.borrowernumber=borrowers.borrowernumber AND borrowers.categorycode=categories.categorycode +AND TO_DAYS($date)-TO_DAYS(issues.date_due) >= 0 END_SQL my @borrower_parameters; - push @borrower_parameters, $date_to_run->datetime(); if ($branchcode) { $borrower_sql .= ' AND issues.branchcode=? '; push @borrower_parameters, $branchcode; @@ -527,8 +527,6 @@ END_SQL my $borrowernumber; while ( my $data = $sth->fetchrow_hashref ) { - next unless ( DateTime->compare( $date_to_run, dt_from_string($data->{date_due})) ) == 1; - # check the borrower has at least one item that matches my $days_between; if ( C4::Context->preference('OverdueNoticeCalendar') ) @@ -617,8 +615,6 @@ END_SQL my $j = 0; my $exceededPrintNoticesMaxLines = 0; while ( my $item_info = $sth2->fetchrow_hashref() ) { - next unless ( DateTime->compare( $date_to_run, dt_from_string($item_info->{date_due})) ) == 1; - if ( C4::Context->preference('OverdueNoticeCalendar') ) { my $calendar = Koha::Calendar->new( branchcode => $branchcode ); -- 2.39.5