From 59b02a9f49a16a119c7ad6c7696587ddd36e8882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20=27lastmikoi=27=20FALCK?= Date: Thu, 16 Mar 2023 15:07:48 +0100 Subject: [PATCH] FIX #24138 Fix box_birthdays SQL for postgres PR #21631's implementation causes issues with PostgreSQL and potentially other stricter RDBMSes, indeed doing an ORDER BY using a function is not supported. In this fix we're computing the day of each user birthday and employment day in the SELECT columns, and use those columns as a sorting key. --- htdocs/core/boxes/box_birthdays.php | 7 +++---- htdocs/core/boxes/box_birthdays_members.php | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/core/boxes/box_birthdays.php b/htdocs/core/boxes/box_birthdays.php index b84991d7be7..52ca0bc6359 100644 --- a/htdocs/core/boxes/box_birthdays.php +++ b/htdocs/core/boxes/box_birthdays.php @@ -85,19 +85,18 @@ class box_birthdays extends ModeleBoxes if ($user->rights->user->user->lire) { $tmparray = dol_getdate(dol_now(), true); - $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth as datea, 'birth' as typea, u.email, u.statut as status"; + $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth as datea, date_format(u.birth, '%d') as daya, 'birth' as typea, u.email, u.statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE u.entity IN (".getEntity('user').")"; $sql .= " AND u.statut = 1"; $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0); $sql .= ' UNION '; - $sql .= "SELECT u.rowid, u.firstname, u.lastname, u.dateemployment as datea, 'employment' as typea, u.email, u.statut as status"; + $sql .= "SELECT u.rowid, u.firstname, u.lastname, u.dateemployment as datea, date_format(u.dateemployment, '%d') as daya, 'employment' as typea, u.email, u.statut as status"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " WHERE u.entity IN (".getEntity('user').")"; $sql .= " AND u.statut = 1"; $sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0); - - $sql .= " ORDER BY datea ASC"; + $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year dol_syslog(get_class($this)."::loadBox", LOG_DEBUG); $result = $this->db->query($sql); diff --git a/htdocs/core/boxes/box_birthdays_members.php b/htdocs/core/boxes/box_birthdays_members.php index 222821128e3..1db11d492ed 100644 --- a/htdocs/core/boxes/box_birthdays_members.php +++ b/htdocs/core/boxes/box_birthdays_members.php @@ -85,12 +85,12 @@ class box_birthdays_members extends ModeleBoxes if ($user->rights->adherent->lire) { $tmparray = dol_getdate(dol_now(), true); - $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth"; + $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth, date_format(u.birth, '%d') as daya"; $sql .= " FROM ".MAIN_DB_PREFIX."adherent as u"; $sql .= " WHERE u.entity IN (".getEntity('adherent').")"; $sql .= " AND u.statut = ".Adherent::STATUS_VALIDATED; $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0); - $sql .= " ORDER BY u.birth ASC"; + $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year $sql .= $this->db->plimit($max, 0); dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);