From 0d36c27678a6968304990759657e2312338763eb 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 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 --- 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 e184edb2b3..c7a5873fac 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -454,6 +454,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 = ? "; @@ -499,15 +500,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; @@ -526,8 +526,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') ) @@ -616,8 +614,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