diff --git a/src/Schedule/Repository/ScheduleRepository.php b/src/Schedule/Repository/ScheduleRepository.php index 7ecd2d6ff..a4d2efb25 100644 --- a/src/Schedule/Repository/ScheduleRepository.php +++ b/src/Schedule/Repository/ScheduleRepository.php @@ -106,7 +106,12 @@ public function updateSchedules( $currentTasks = []; foreach ($schedules as $schedule) { - $task = $this->taskResolver->getById($schedule->getId()); + + if ($schedule->getId()) { + $task = $this->taskResolver->getById($schedule->getId()); + } else { + $task = $this->createSchedule($elementType, $id); + } if (!$task) { continue; diff --git a/src/Schedule/Schema/UpdateSchedule.php b/src/Schedule/Schema/UpdateSchedule.php index 3eb0835cd..863b93e14 100644 --- a/src/Schedule/Schema/UpdateSchedule.php +++ b/src/Schedule/Schema/UpdateSchedule.php @@ -30,8 +30,8 @@ final readonly class UpdateSchedule { public function __construct( - #[Property(description: 'id', type: 'integer', example: 666)] - private int $id, + #[Property(description: 'Id of schedule, if null a new one will be created', type: 'integer', example: 666)] + private ?int $id, #[Property(description: 'Date of schedule', type: 'integer', example: 1634025600)] private int $date, #[Property(description: 'Action', type: 'string', enum: ['publish', 'delete'])] @@ -44,7 +44,7 @@ public function __construct( } - public function getId(): int + public function getId(): ?int { return $this->id; }