File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments