From 866b6df4b09daa00e08b06427bf9e6285a982a44 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Tue, 24 Jan 2023 16:18:38 -0700 Subject: [PATCH] api(task): ensure `sequence_id` always starts at `1` --- .../Api/Client/Servers/ScheduleTaskController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php b/app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php index 53f5f7dc8..e2e4389a1 100644 --- a/app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php +++ b/app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php @@ -56,6 +56,11 @@ class ScheduleTaskController extends ClientApiController $sequenceId = ($lastTask->sequence_id ?? 0) + 1; $requestSequenceId = $request->integer('sequence_id', $sequenceId); + // Ensure that the sequence id is at least 1. + if ($requestSequenceId < 1) { + $requestSequenceId = 1; + } + // If the sequence id from the request is greater than or equal to the next available // sequence id, we don't need to do anything special. Otherwise, we need to update // the sequence id of all tasks that are greater than or equal to the request sequence @@ -105,6 +110,10 @@ class ScheduleTaskController extends ClientApiController $this->connection->transaction(function () use ($request, $schedule, $task) { $sequenceId = $request->integer('sequence_id', $task->sequence_id); + // Ensure that the sequence id is at least 1. + if ($sequenceId < 1) { + $sequenceId = 1; + } // Shift all other tasks in the schedule up or down to make room for the new task. if ($sequenceId < $task->sequence_id) {