Skip to content

Commit

Permalink
[Improvement] Created new schedule for update if no id is sent (#416)
Browse files Browse the repository at this point in the history
* Created new schedule for update if no id is sent

* Apply php-cs-fixer changes

* Skip if no task found

---------

Co-authored-by: mattamon <[email protected]>
  • Loading branch information
mattamon and mattamon authored Sep 10, 2024
1 parent 78be334 commit dbf8196
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Schedule/Repository/ScheduleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Schedule/Schema/UpdateSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])]
Expand All @@ -44,7 +44,7 @@ public function __construct(

}

public function getId(): int
public function getId(): ?int
{
return $this->id;
}
Expand Down

0 comments on commit dbf8196

Please sign in to comment.