File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -311,6 +311,20 @@ private function createRotation(int $priority): Generator
311
311
}
312
312
313
313
$ 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
+
314
328
$ data ['changed_at ' ] = $ changedAt ;
315
329
$ this ->db ->insert ('rotation ' , $ data );
316
330
$ rotationId = $ this ->db ->lastInsertId ();
@@ -381,12 +395,7 @@ public function addRotation(): void
381
395
$ transactionStarted = $ this ->db ->beginTransaction ();
382
396
}
383
397
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 );
390
399
391
400
if ($ transactionStarted ) {
392
401
$ this ->db ->commitTransaction ();
You can’t perform that action at this time.
0 commit comments