api(task): ensure sequence_id
always starts at 1
This commit is contained in:
parent
2b14e46eec
commit
866b6df4b0
1 changed files with 9 additions and 0 deletions
|
@ -56,6 +56,11 @@ class ScheduleTaskController extends ClientApiController
|
||||||
$sequenceId = ($lastTask->sequence_id ?? 0) + 1;
|
$sequenceId = ($lastTask->sequence_id ?? 0) + 1;
|
||||||
$requestSequenceId = $request->integer('sequence_id', $sequenceId);
|
$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
|
// 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
|
// 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
|
// 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) {
|
$this->connection->transaction(function () use ($request, $schedule, $task) {
|
||||||
$sequenceId = $request->integer('sequence_id', $task->sequence_id);
|
$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.
|
// Shift all other tasks in the schedule up or down to make room for the new task.
|
||||||
if ($sequenceId < $task->sequence_id) {
|
if ($sequenceId < $task->sequence_id) {
|
||||||
|
|
Loading…
Reference in a new issue