From 1357076ad7721e48a7aa99a32e363bfc8df17065 Mon Sep 17 00:00:00 2001
From: Jean-Laurent <jean-laurent.duzant@xelians.fr>
Date: Thu, 17 Mar 2022 11:38:16 +0100
Subject: [PATCH] FIX #19971 TIME 0:05 use event_id to create/update the
 correct script

---
 .../notification/controllers/NotificationController.php    | 4 ++--
 .../controllers/NotificationScheduleController.php         | 5 +++--
 .../models/NotificationScheduleModelAbstract.php           | 7 ++++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/app/notification/controllers/NotificationController.php b/src/app/notification/controllers/NotificationController.php
index a4e89f08354..5eb17d62ec1 100755
--- a/src/app/notification/controllers/NotificationController.php
+++ b/src/app/notification/controllers/NotificationController.php
@@ -132,7 +132,7 @@ class NotificationController
         if (NotificationModel::create($data)) {
             if (PHP_OS == 'Linux') {
                 $notificationAdded = NotificationModel::getByNotificationId(['notificationId' => $data['notification_id'], 'select' => ['notification_sid']]);
-                NotificationScheduleModel::createScriptNotification(['notification_sid' => $notificationAdded['notification_sid'], 'notification_id' => $data['notification_id']]);
+                NotificationScheduleModel::createScriptNotification(['notification_sid' => $notificationAdded['notification_sid'], 'event_id' => $data['event_id'], 'notification_id' => $data['notification_id']]);
             }
 
             HistoryController::add([
@@ -173,7 +173,7 @@ class NotificationController
         $notification = NotificationModel::getById(['notification_sid' => $data['notification_sid']]);
 
         if (PHP_OS == 'Linux') {
-            NotificationScheduleModel::createScriptNotification(['notification_sid' => $data['notification_sid'], 'notification_id' => $notification['notification_id']]);
+            NotificationScheduleModel::createScriptNotification(['notification_sid' => $data['notification_sid'], 'event_id' => $data['event_id'], 'notification_id' => $notification['notification_id']]);
         }
 
         HistoryController::add([
diff --git a/src/app/notification/controllers/NotificationScheduleController.php b/src/app/notification/controllers/NotificationScheduleController.php
index c93df8334b0..0ccc18ab0ba 100755
--- a/src/app/notification/controllers/NotificationScheduleController.php
+++ b/src/app/notification/controllers/NotificationScheduleController.php
@@ -144,7 +144,8 @@ class NotificationScheduleController
             $errors[] = 'notification_sid is not a numeric';
         }
         if (!Validator::notEmpty()->validate($data['notification_sid']) ||
-            !Validator::notEmpty()->validate($data['notification_id'])) {
+            !Validator::notEmpty()->validate($data['notification_id'])  ||
+            !Validator::notEmpty()->validate($data['event_id'])) {
             $errors[] = 'one of arguments is empty';
         }
 
@@ -155,7 +156,7 @@ class NotificationScheduleController
         $notification_sid = $data['notification_sid'];
         $notification_id  = $data['notification_id'];
 
-        NotificationScheduleModel::createScriptNotification(['notification_sid' => $notification_sid, 'notification_id' => $notification_id]);
+        NotificationScheduleModel::createScriptNotification(['notification_sid' => $notification_sid, 'event_id' => $event_id, 'notification_id' => $notification_id]);
 
         return $response->withJson(true);
     }
diff --git a/src/app/notification/models/NotificationScheduleModelAbstract.php b/src/app/notification/models/NotificationScheduleModelAbstract.php
index 40f52b2b239..f40fd32d0c2 100755
--- a/src/app/notification/models/NotificationScheduleModelAbstract.php
+++ b/src/app/notification/models/NotificationScheduleModelAbstract.php
@@ -131,10 +131,11 @@ abstract class NotificationScheduleModelAbstract
 
     public static function createScriptNotification(array $aArgs)
     {
-        ValidatorModel::notEmpty($aArgs, ['notification_sid', 'notification_id']);
+        ValidatorModel::notEmpty($aArgs, ['notification_sid', 'notification_id', 'event_id']);
         ValidatorModel::intVal($aArgs, ['notification_sid']);
 
         $notification_id = $aArgs['notification_id'];
+        $event_id = $aArgs['event_id'];
 
         //Creer le script sh pour les notifications
         $filename = 'notification';
@@ -166,9 +167,9 @@ abstract class NotificationScheduleModelAbstract
         fwrite($file_open, "\n");
         fwrite($file_open, 'cd $path');
         fwrite($file_open, "\n");
-        if ($notification_id == 'BASKETS') {
+        if ($event_id == 'baskets') {
             fwrite($file_open, 'php \'basket_event_stack.php\' -c '.$ConfigNotif.' -n '.$notification_id);
-        } elseif ($notification_id == 'RELANCE1' || $notification_id == 'RELANCE2' || $notification_id == 'RET1' || $notification_id == 'RET2') {
+        } elseif ($notification_id == 'RELANCE1' || $notification_id == 'RELANCE2' || $event_id == 'alert1' || $event_id == 'alert2') {
             fwrite($file_open, 'php \'stack_letterbox_alerts.php\' -c '.$ConfigNotif);
             fwrite($file_open, "\n");
             fwrite($file_open, 'php \'process_event_stack.php\' -c '.$ConfigNotif.' -n '.$notification_id);
-- 
GitLab