Skip to content

Commit 866b6df

Browse files
committed
api(task): ensure sequence_id always starts at 1
1 parent 2b14e46 commit 866b6df

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/Http/Controllers/Api/Client/Servers/ScheduleTaskController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public function store(StoreTaskRequest $request, Server $server, Schedule $sched
5656
$sequenceId = ($lastTask->sequence_id ?? 0) + 1;
5757
$requestSequenceId = $request->integer('sequence_id', $sequenceId);
5858

59+
// Ensure that the sequence id is at least 1.
60+
if ($requestSequenceId < 1) {
61+
$requestSequenceId = 1;
62+
}
63+
5964
// If the sequence id from the request is greater than or equal to the next available
6065
// sequence id, we don't need to do anything special. Otherwise, we need to update
6166
// the sequence id of all tasks that are greater than or equal to the request sequence
@@ -105,6 +110,10 @@ public function update(StoreTaskRequest $request, Server $server, Schedule $sche
105110

106111
$this->connection->transaction(function () use ($request, $schedule, $task) {
107112
$sequenceId = $request->integer('sequence_id', $task->sequence_id);
113+
// Ensure that the sequence id is at least 1.
114+
if ($sequenceId < 1) {
115+
$sequenceId = 1;
116+
}
108117

109118
// Shift all other tasks in the schedule up or down to make room for the new task.
110119
if ($sequenceId < $task->sequence_id) {

0 commit comments

Comments
 (0)