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 <chrisc@catalyst.net.nz>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit f228c9ee9f)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
(cherry picked from commit 1b4f18148b)

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2020-12-18 14:28:13 +01:00 committed by Andrew Fuerste-Henry
parent 09518a3773
commit 4d85ad1a8f
1 changed files with 6 additions and 4 deletions

View File

@ -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";