Skip to content

Commit e72f8d7

Browse files
RotationConfigForm: Add new rotation at the bottom of the list
The new rotation has always priority 0
1 parent 8e4d0d1 commit e72f8d7

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

application/forms/RotationConfigForm.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,20 @@ private function createRotation(int $priority): Generator
311311
}
312312

313313
$changedAt = time() * 1000;
314+
315+
$rotationsToMove = Rotation::on($this->db)
316+
->columns('id')
317+
->filter(Filter::equal('schedule_id', $this->scheduleId))
318+
->orderBy('priority', SORT_DESC);
319+
320+
foreach ($rotationsToMove as $rotation) {
321+
$this->db->update(
322+
'rotation',
323+
['priority' => new Expression('priority + 1'), 'changed_at' => $changedAt],
324+
['id = ?' => $rotation->id]
325+
);
326+
}
327+
314328
$data['changed_at'] = $changedAt;
315329
$this->db->insert('rotation', $data);
316330
$rotationId = $this->db->lastInsertId();
@@ -381,12 +395,7 @@ public function addRotation(): void
381395
$transactionStarted = $this->db->beginTransaction();
382396
}
383397

384-
$this->createRotation($this->db->fetchScalar(
385-
(new Select())
386-
->from('rotation')
387-
->columns(new Expression('MAX(priority) + 1'))
388-
->where(['schedule_id = ?' => $this->scheduleId])
389-
) ?? 0)->send(true);
398+
$this->createRotation(0)->send(true);
390399

391400
if ($transactionStarted) {
392401
$this->db->commitTransaction();

0 commit comments

Comments
 (0)