security->isGranted('ROLE_USER')) { throw new AccessDeniedException('Access denied: ROLE_USER required.'); } $task = $this->taskRepository->find($taskId); if (null === $task) { throw new InvalidArgumentException(sprintf('Task with ID %d not found.', $taskId)); } $recurrenceType = RecurrenceType::from($type); $recurrence = new TaskRecurrence(); $recurrence->setType($recurrenceType); $recurrence->setInterval($interval); if (null !== $daysOfWeek) { $recurrence->setDaysOfWeek($daysOfWeek); } if (null !== $dayOfMonth) { $recurrence->setDayOfMonth($dayOfMonth); } if (null !== $weekOfMonth) { $recurrence->setWeekOfMonth($weekOfMonth); } if (null !== $endDate) { $recurrence->setEndDate(new DateTimeImmutable($endDate)); } if (null !== $maxOccurrences) { $recurrence->setMaxOccurrences($maxOccurrences); } $task->setRecurrence($recurrence); $this->entityManager->persist($recurrence); $this->entityManager->flush(); $this->calDavService->syncTask($task); $this->entityManager->flush(); return json_encode([ 'id' => $recurrence->getId(), 'type' => $recurrence->getType()?->value, 'interval' => $recurrence->getInterval(), 'daysOfWeek' => $recurrence->getDaysOfWeek(), 'dayOfMonth' => $recurrence->getDayOfMonth(), 'weekOfMonth' => $recurrence->getWeekOfMonth(), 'endDate' => $recurrence->getEndDate()?->format('Y-m-d'), 'maxOccurrences' => $recurrence->getMaxOccurrences(), 'taskId' => $task->getId(), ]); } }