diff --git a/bin/scheduler.php b/bin/scheduler.php index 2b14ea7ebebc8c4ab409a6d1b2d72a8439679add..5ad1cda1e39811e54e8a92791fdfd6dc81895453 100644 --- a/bin/scheduler.php +++ b/bin/scheduler.php @@ -3,6 +3,7 @@ use Configuration\models\ConfigurationModel; use Document\models\DocumentModel; use Email\controllers\EmailController; +use History\controllers\HistoryController; use Notification\models\NotificationsScheduleModel; use Notification\models\NotificationStackModel; use SrcCore\controllers\LanguageController; @@ -27,10 +28,17 @@ $GLOBALS['id'] = $restUser['id']; $configuration = ConfigurationModel::getByIdentifier(['identifier' => 'customization']); $configuration = $configuration[0]; -$configuration = json_decode($configuration['value'], true); -$applicationUrl = $configuration['applicationUrl']; +$configuration['value'] = json_decode($configuration['value'], true); +$applicationUrl = $configuration['value']['applicationUrl']; if (empty($applicationUrl)) { + HistoryController::add([ + 'code' => 'KO', + 'objectType' => 'configurations', + 'objectId' => $configuration['id'], + 'type' => 'ERROR', + 'message' => "{schedulerError} : Cannot run scheduler : no applicationUrl defined" + ]); echo "Cannot run scheduler : no applicationUrl defined\n"; exit(1); } @@ -182,7 +190,7 @@ function sendNotifications(array $args) 'data' => [$stackIds] ]); - return true; + return $stackIds; } diff --git a/bin/scheduler.sh b/bin/scheduler.sh deleted file mode 100644 index 82c5e8093de409ab8ee6c45cd378c5d0cb779546..0000000000000000000000000000000000000000 --- a/bin/scheduler.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -cd /var/www/html/MaarchParapheur/ -filePath='/var/www/html/MaarchParapheur/bin/scheduler.php' -php $filePath /var/www/html/MaarchParapheur/config/ diff --git a/lang/fr.json b/lang/fr.json index 45e8c1580998d78a7284bc0e6a4a99e97cb43142..5cc8a243ac8d4d8dd30d38679b3641a4e5133319 100755 --- a/lang/fr.json +++ b/lang/fr.json @@ -572,7 +572,7 @@ "scheduleUpdated": "Planification modifiée", "frequency": "Fréquence", "notificationDocumentsAddedBody": "Bonjour,<br/><br/>Des documents vous ont été transmis sur Maarch Parapheur.<br/><br/>", - "notificationTemplateTable": "<table style=\"border: 1pt solid #000000; width: 1582px; height: 77px;\" border=\"1\" frame=\"box\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td><span style=\"font-family: arial,helvetica,sans-serif; font-size: small;\"><strong>Objet</strong></span></td>\n<td><span style=\"font-family: arial,helvetica,sans-serif; font-size: small;\"><strong>Liens</strong></span></td>\n</tr>\n{{rows}}\n</tbody>\n</table>", + "notificationTemplateTable": "<table style=\"border: 1pt solid #000000; width: 582px; height: 77px;\" border=\"1\" frame=\"box\" cellspacing=\"1\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td><span style=\"font-family: arial,helvetica,sans-serif; font-size: small;\"><strong>Objet</strong></span></td>\n<td><span style=\"font-family: arial,helvetica,sans-serif; font-size: small;\"><strong>Liens</strong></span></td>\n</tr>\n{{rows}}\n</tbody>\n</table>", "notificationTemplateRow": "<tr>\n<td><span style=\"font-family: arial,helvetica,sans-serif; font-size: small;\">{{object}}</span></td>\n<td><span style=\"font-family: arial,helvetica,sans-serif;\"><a href=\"{{link}}\">Voir</a></span></td>\n</tr>", "notificationDocumentsAddedSubject": "[Maarch Parapheur] Nouveaux documents à traiter", "applicationUrl": "URL de l'application", @@ -599,6 +599,7 @@ "schedulerInitialized": "Planificateur initialisé", "scheduleDeleted": "Planification supprimée", "manage_notificationsDesc": "Planifier les récapitulatifs d'évènements", - "notifications_schedule": "Planification de notifications" + "notifications_schedule": "Planification de notifications", + "schedulerError": "Erreur planificateur " } } diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php index 508468180ceb009b87724a0b2e49a11403b129a2..68bd43e020a84a442db409a439ad704c451526f8 100755 --- a/src/app/document/controllers/DocumentController.php +++ b/src/app/document/controllers/DocumentController.php @@ -18,6 +18,7 @@ use Attachment\controllers\AttachmentController; use Docserver\models\AdrModel; use Email\controllers\EmailController; use Group\controllers\PrivilegeController; +use Notification\models\NotificationStackModel; use Respect\Validation\Validator; use setasign\Fpdi\Tcpdf\Fpdi; use SrcCore\controllers\UrlController; @@ -969,6 +970,11 @@ class DocumentController $historyMessagePart = "{actionDoneInPlaceOf} {$user} : "; } + NotificationStackModel::delete([ + 'where' => ['main_document_id = ?', 'type = ?', 'recipient_id = ?'], + 'data' => [$args['id'], 'next_user', $GLOBALS['id']] + ]); + HistoryController::add([ 'code' => 'OK', 'objectType' => 'main_documents', diff --git a/src/app/email/controllers/EmailController.php b/src/app/email/controllers/EmailController.php index 5eca8813a32b74489a75966ef06c14a0aa5d36f1..b8e576559bef0dfc305112bc4b95cbbb0edb6252 100644 --- a/src/app/email/controllers/EmailController.php +++ b/src/app/email/controllers/EmailController.php @@ -298,7 +298,7 @@ class EmailController $schedule = NotificationsScheduleModel::get([ 'select' => ['id'], 'where' => ['type = ?'], - 'data' => ['typist_' . $args['mode']] + 'data' => ['next_user'] ]); $schedule = array_column($schedule, 'id'); if (!empty($nextUser['preferences']['notifications']['summaries'])) { @@ -323,7 +323,7 @@ class EmailController $schedule = NotificationsScheduleModel::get([ 'select' => ['id'], 'where' => ['type = ?'], - 'data' => ['typist_' . $args['mode']] + 'data' => ['next_user'] ]); $schedule = array_column($schedule, 'id'); if (!empty($nextSubstituteUser['preferences']['notifications']['summaries'])) { diff --git a/src/app/notifications/controllers/NotificationsScheduleController.php b/src/app/notifications/controllers/NotificationsScheduleController.php index d964e8c42fabc12cab0e1c272fbdc31ea601dc9f..bb6075aec6d20b8ef6f4de7ea6c144484bb387c7 100644 --- a/src/app/notifications/controllers/NotificationsScheduleController.php +++ b/src/app/notifications/controllers/NotificationsScheduleController.php @@ -227,6 +227,9 @@ class NotificationsScheduleController if (empty($configuration['value']['schedulerPath']) || !is_file($configuration['value']['schedulerPath'])) { $schedulerScript = NotificationsScheduleController::createSchedulerScript(); + if (!empty($schedulerScript['errors'])) { + return $response->withStatus(500)->withJson(['errors' => $schedulerScript['errors']]); + } $configuration['value']['schedulerPath'] = $schedulerScript['path']; } @@ -324,6 +327,10 @@ class NotificationsScheduleController $fullPath = $corePath . 'bin/' . $filename; + if (!is_writable($corePath . 'bin/')) { + return ['errors' => 'Cannot create scheduler script in ' . $corePath . 'bin/']; + } + $file_open = fopen($fullPath, 'w+'); fwrite($file_open, '#!/bin/sh');