From 984b05329d8e6d1c439b4832fb6217f4eaca7bbc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 18 Dec 2020 14:28:13 +0100 Subject: [PATCH] Bug 27276: Prevent borrowers-force-messaging-defaults.pl to crash MySQL 5.7 does not allow queries using 0000-00-00 Signed-off-by: Chris Cormack --- misc/maintenance/borrowers-force-messaging-defaults.pl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/misc/maintenance/borrowers-force-messaging-defaults.pl b/misc/maintenance/borrowers-force-messaging-defaults.pl index c446ca0f1c..c9a1ef727f 100755 --- a/misc/maintenance/borrowers-force-messaging-defaults.pl +++ b/misc/maintenance/borrowers-force-messaging-defaults.pl @@ -42,8 +42,7 @@ sub usage { sub force_borrower_messaging_defaults { my ($doit, $since, $not_expired, $no_overwrite, $category ) = @_; - $since = '0000-00-00' if (!$since); - print "Since: $since\n"; + print "Since: $since\n" if $since; my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; @@ -51,7 +50,10 @@ sub force_borrower_messaging_defaults { my $sql = q|SELECT DISTINCT bo.borrowernumber, bo.categorycode FROM borrowers bo LEFT JOIN borrower_message_preferences mp USING (borrowernumber) -WHERE bo.dateenrolled >= ?|; +WHERE 1| + if ( $since ) { + $sql .= " AND bo.dateenrolled >= ?"; + } if ($not_expired) { $sql .= " AND bo.dateexpiry >= NOW()" } @@ -60,7 +62,7 @@ WHERE bo.dateenrolled >= ?|; } $sql .= " AND bo.categorycode = ?" if $category; my $sth = $dbh->prepare($sql); - $sth->execute($since, $category || () ); + $sth->execute($since || (), $category || () ); my $cnt = 0; while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) { print "$borrowernumber: $categorycode\n"; -- 2.11.0