Skip to content
Snippets Groups Projects
Commit a45a2f34 authored by Quentin Ribac's avatar Quentin Ribac
Browse files

FEAT #17150 TIME 0:45 added fields status, last_execution in notifications_schedule (sql and php)

parent 194a908b
No related branches found
No related tags found
No related merge requests found
...@@ -323,8 +323,10 @@ CREATE TABLE notifications_schedule ...@@ -323,8 +323,10 @@ CREATE TABLE notifications_schedule
days_of_week jsonb, days_of_week jsonb,
start_time time, start_time time,
end_time time, end_time time,
frequency int, frequency INTEGER,
frequency_mode character varying(16), frequency_mode character varying(16),
status character varying(20) NOT NULL DEFAULT 'READY',
last_execution timestamp without time zone,
CONSTRAINT notifications_schedule_pkey PRIMARY KEY (id) CONSTRAINT notifications_schedule_pkey PRIMARY KEY (id)
) )
WITH (OIDS=FALSE); WITH (OIDS=FALSE);
...@@ -33,7 +33,7 @@ class NotificationsScheduleController ...@@ -33,7 +33,7 @@ class NotificationsScheduleController
} }
$body = $request->getParsedBody(); $body = $request->getParsedBody();
// label, type, months, daysOfMonth, daysOfWeek, startTime, endTime, frequency, frequencyMode // label, type, months, daysOfMonth, daysOfWeek, startTime, (endTime, frequency, frequencyMode)?
$err = NotificationsScheduleController::validateBody($body); $err = NotificationsScheduleController::validateBody($body);
if (!empty($err)) { if (!empty($err)) {
...@@ -81,16 +81,18 @@ class NotificationsScheduleController ...@@ -81,16 +81,18 @@ class NotificationsScheduleController
$notificationsSchedule = []; $notificationsSchedule = [];
foreach ($rawNotificationsSchedule as $key => $value) { foreach ($rawNotificationsSchedule as $key => $value) {
$notificationsSchedule[] = [ $notificationsSchedule[] = [
'id' => $value['id'], 'id' => $value['id'],
'label' => $value['label'], 'label' => $value['label'],
'type' => $value['type'], 'type' => $value['type'],
'months' => json_decode($value['months']), 'months' => json_decode($value['months']),
'daysOfMonth' => json_decode($value['days_of_month']), 'daysOfMonth' => json_decode($value['days_of_month']),
'daysOfWeek' => json_decode($value['days_of_week']), 'daysOfWeek' => json_decode($value['days_of_week']),
'startTime' => $value['start_time'], 'startTime' => $value['start_time'],
'endTime' => $value['end_time'], 'endTime' => $value['end_time'],
'frequency' => $value['frequency'], 'frequency' => $value['frequency'],
'frequencyMode' => $value['frequency_mode'], 'frequencyMode' => $value['frequency_mode'],
'status' => $value['status'],
'lastExecution' => $value['last_execution'],
]; ];
} }
...@@ -113,16 +115,18 @@ class NotificationsScheduleController ...@@ -113,16 +115,18 @@ class NotificationsScheduleController
} }
$notificationsScheduleItem = [ $notificationsScheduleItem = [
'id' => $rawNotificationsScheduleItem['id'], 'id' => $rawNotificationsScheduleItem['id'],
'label' => $rawNotificationsScheduleItem['label'], 'label' => $rawNotificationsScheduleItem['label'],
'type' => $rawNotificationsScheduleItem['type'], 'type' => $rawNotificationsScheduleItem['type'],
'months' => json_decode($rawNotificationsScheduleItem['months']), 'months' => json_decode($rawNotificationsScheduleItem['months']),
'daysOfMonth' => json_decode($rawNotificationsScheduleItem['days_of_month']), 'daysOfMonth' => json_decode($rawNotificationsScheduleItem['days_of_month']),
'daysOfWeek' => json_decode($rawNotificationsScheduleItem['days_of_week']), 'daysOfWeek' => json_decode($rawNotificationsScheduleItem['days_of_week']),
'startTime' => $rawNotificationsScheduleItem['start_time'], 'startTime' => $rawNotificationsScheduleItem['start_time'],
'endTime' => $rawNotificationsScheduleItem['end_time'], 'endTime' => $rawNotificationsScheduleItem['end_time'],
'frequency' => $rawNotificationsScheduleItem['frequency'], 'frequency' => $rawNotificationsScheduleItem['frequency'],
'frequencyMode' => $rawNotificationsScheduleItem['frequency_mode'], 'frequencyMode' => $rawNotificationsScheduleItem['frequency_mode'],
'status' => $rawNotificationsScheduleItem['status'],
'lastExecution' => $rawNotificationsScheduleItem['last_execution'],
]; ];
return $response->withJson(['notificationsScheduleItem' => $notificationsScheduleItem]); return $response->withJson(['notificationsScheduleItem' => $notificationsScheduleItem]);
...@@ -159,15 +163,17 @@ class NotificationsScheduleController ...@@ -159,15 +163,17 @@ class NotificationsScheduleController
NotificationsScheduleModel::update([ NotificationsScheduleModel::update([
'set' => [ 'set' => [
'label' => $body['label'], 'label' => $body['label'],
'type' => $body['type'], 'type' => $body['type'],
'months' => empty($body['months']) ? '[]' : json_encode($body['months']), 'months' => empty($body['months']) ? '[]' : json_encode($body['months']),
'days_of_month' => empty($body['daysOfMonth']) ? '[]' : json_encode($body['daysOfMonth']), 'days_of_month' => empty($body['daysOfMonth']) ? '[]' : json_encode($body['daysOfMonth']),
'days_of_week' => empty($body['daysOfWeek']) ? '[]' : json_encode($body['daysOfWeek']), 'days_of_week' => empty($body['daysOfWeek']) ? '[]' : json_encode($body['daysOfWeek']),
'start_time' => $body['startTime'], 'start_time' => $body['startTime'],
'end_time' => $body['endTime'], 'end_time' => $body['endTime'],
'frequency' => $body['frequency'], 'frequency' => $body['frequency'],
'frequency_mode' => $body['frequencyMode'], 'frequency_mode' => $body['frequencyMode'],
'status' => $body['status'],
'last_execution' => $body['lastExecution'],
], ],
'where' => ['id = ?'], 'where' => ['id = ?'],
'data' => [$args['id']] 'data' => [$args['id']]
...@@ -228,12 +234,12 @@ class NotificationsScheduleController ...@@ -228,12 +234,12 @@ class NotificationsScheduleController
return "Body daysOfWeek must contain numbers from 1-7 or only '*'"; return "Body daysOfWeek must contain numbers from 1-7 or only '*'";
} elseif (!(Validator::equals(['*'])->validate($body['months']) xor Validator::equals(['*'])->validate($body['daysOfWeek']))) { } elseif (!(Validator::equals(['*'])->validate($body['months']) xor Validator::equals(['*'])->validate($body['daysOfWeek']))) {
return "One and only one of body months and daysOfWeek must be ['*']"; return "One and only one of body months and daysOfWeek must be ['*']";
} elseif (!Validator::stringType()->time('H:i')->validate($body['startTime'])) { } elseif (!Validator::stringType()->time('H:i:s')->validate($body['startTime'])) {
return 'Body startTime is not a valid time'; return 'Body startTime is not a valid time, expecting hh:mm:ss';
} }
if (!empty($body['frequency'])) { if (!empty($body['frequency'])) {
if (!Validator::stringType()->time('H:i')->greaterThan($body['startTime'])->validate($body['endTime'])) { if (!Validator::stringType()->time('H:i:s')->greaterThan($body['startTime'])->validate($body['endTime'])) {
return 'Body endTime is not a valid time or is before startTime'; return 'Body endTime is not a valid time or is before startTime, expecting hh:mm:ss';
} elseif (!Validator::intType()->positive()->validate($body['frequency'])) { } elseif (!Validator::intType()->positive()->validate($body['frequency'])) {
return 'Body frequency is not a number or is less than 0'; return 'Body frequency is not a number or is less than 0';
} elseif (!Validator::stringType()->in(NotificationsScheduleController::FREQUENCY_MODES)->validate($body['frequencyMode'])) { } elseif (!Validator::stringType()->in(NotificationsScheduleController::FREQUENCY_MODES)->validate($body['frequencyMode'])) {
......
...@@ -75,7 +75,7 @@ class NotificationsScheduleModel ...@@ -75,7 +75,7 @@ class NotificationsScheduleModel
'end_time' => $args['end_time'], 'end_time' => $args['end_time'],
'frequency' => $args['frequency'], 'frequency' => $args['frequency'],
'frequency_mode' => $args['frequency_mode'], 'frequency_mode' => $args['frequency_mode'],
] ],
]); ]);
return $nextSequenceId; return $nextSequenceId;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment