From 59523f9c858ee4de4ec76f83d556decd1aa6f73a Mon Sep 17 00:00:00 2001 From: Guillaume Heurtier <guillaume.heurtier@maarch.org> Date: Wed, 22 Feb 2023 15:45:07 +0100 Subject: [PATCH] FEAT #19031 TIME 1:00 fix notification schedule for php 8.1 --- .../NotificationsScheduleController.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/notifications/controllers/NotificationsScheduleController.php b/src/app/notifications/controllers/NotificationsScheduleController.php index 3ee84b48da..f8d3d71ac3 100644 --- a/src/app/notifications/controllers/NotificationsScheduleController.php +++ b/src/app/notifications/controllers/NotificationsScheduleController.php @@ -15,6 +15,7 @@ namespace Notification\controllers; use Configuration\models\ConfigurationModel; +use DateTime; use Notification\models\NotificationsScheduleModel; use Group\controllers\PrivilegeController; use History\controllers\HistoryController; @@ -79,6 +80,16 @@ class NotificationsScheduleController $notificationsSchedule = []; foreach ($rawNotificationsSchedule as $value) { + $startTime = null; + $endTime = null; + + if (!empty($value['start_time'])) { + $startTime = (new DateTime($value['start_time']))->format('H:i'); + } + if (!empty($value['end_time'])) { + $endTime = (new DateTime($value['end_time']))->format('H:i'); + } + $notificationsSchedule[] = [ 'id' => $value['id'], 'label' => $value['label'], @@ -86,8 +97,8 @@ class NotificationsScheduleController 'months' => json_decode($value['months']), 'daysOfMonth' => json_decode($value['days_of_month']), 'daysOfWeek' => json_decode($value['days_of_week']), - 'startTime' => (new \DateTime($value['start_time'] ?? ''))->format('H:i'), - 'endTime' => (new \DateTime($value['end_time'] ?? ''))->format('H:i'), + 'startTime' => $startTime, + 'endTime' => $endTime, 'frequency' => $value['frequency'], 'frequencyMode' => $value['frequency_mode'], 'status' => $value['status'], @@ -119,8 +130,8 @@ class NotificationsScheduleController 'months' => json_decode($rawNotificationsScheduleItem['months']), 'daysOfMonth' => json_decode($rawNotificationsScheduleItem['days_of_month']), 'daysOfWeek' => json_decode($rawNotificationsScheduleItem['days_of_week']), - 'startTime' => (new \DateTime($rawNotificationsScheduleItem['start_time']))->format('H:i'), - 'endTime' => !empty($rawNotificationsScheduleItem['end_time']) ? (new \DateTime($rawNotificationsScheduleItem['end_time']))->format('H:i') : null, + 'startTime' => (new DateTime($rawNotificationsScheduleItem['start_time']))->format('H:i'), + 'endTime' => !empty($rawNotificationsScheduleItem['end_time']) ? (new DateTime($rawNotificationsScheduleItem['end_time']))->format('H:i') : null, 'frequency' => $rawNotificationsScheduleItem['frequency'], 'frequencyMode' => $rawNotificationsScheduleItem['frequency_mode'], 'status' => $rawNotificationsScheduleItem['status'], @@ -262,7 +273,7 @@ class NotificationsScheduleController HistoryController::add([ 'code' => 'OK', 'objectType' => 'configurations', - 'objectId' => $configuration['id'] ?? null, + 'objectId' => $configuration['id'], 'type' => 'MODIFICATION', 'message' => "{schedulerScriptCreated} : {$configuration['value']['schedulerPath']}" ]); -- GitLab