security->isGranted('ROLE_USER')) { throw new AccessDeniedException('Access denied: ROLE_USER required.'); } $task = $this->taskRepository->find($id); if (null === $task) { throw new InvalidArgumentException(sprintf('Task with ID %d not found.', $id)); } if (null !== $title) { $task->setTitle($title); } if (null !== $description) { $task->setDescription($description); } if (null !== $statusId) { $status = $this->taskStatusRepository->find($statusId); if (null === $status) { throw new InvalidArgumentException(sprintf('TaskStatus with ID %d not found.', $statusId)); } $task->setStatus($status); } if (null !== $priorityId) { $priority = $this->taskPriorityRepository->find($priorityId); if (null === $priority) { throw new InvalidArgumentException(sprintf('TaskPriority with ID %d not found.', $priorityId)); } $task->setPriority($priority); } if (null !== $effortId) { $effort = $this->taskEffortRepository->find($effortId); if (null === $effort) { throw new InvalidArgumentException(sprintf('TaskEffort with ID %d not found.', $effortId)); } $task->setEffort($effort); } if (null !== $assigneeId) { $assignee = $this->userRepository->find($assigneeId); if (null === $assignee) { throw new InvalidArgumentException(sprintf('User with ID %d not found.', $assigneeId)); } $task->setAssignee($assignee); } if (null !== $groupId) { $group = $this->taskGroupRepository->find($groupId); if (null === $group) { throw new InvalidArgumentException(sprintf('TaskGroup with ID %d not found.', $groupId)); } $task->setGroup($group); } if (null !== $tagIds) { // Clear existing tags and set new ones foreach ($task->getTags()->toArray() as $existingTag) { $task->removeTag($existingTag); } foreach ($tagIds as $tagId) { $tag = $this->taskTagRepository->find($tagId); if (null === $tag) { throw new InvalidArgumentException(sprintf('TaskTag with ID %d not found.', $tagId)); } $task->addTag($tag); } } if (null !== $archived) { $task->setArchived($archived); } if (null !== $scheduledStart) { $task->setScheduledStart(new DateTimeImmutable($scheduledStart)); } if (null !== $scheduledEnd) { $task->setScheduledEnd(new DateTimeImmutable($scheduledEnd)); } if (null !== $deadline) { $task->setDeadline(new DateTimeImmutable($deadline)); } if (null !== $syncToCalendar) { $task->setSyncToCalendar($syncToCalendar); } $this->entityManager->flush(); $this->calDavService->syncTask($task); $this->entityManager->flush(); return json_encode([ 'id' => $task->getId(), 'number' => $task->getNumber(), 'title' => $task->getTitle(), 'description' => $task->getDescription(), 'status' => Serializer::status($task->getStatus()), 'priority' => Serializer::priority($task->getPriority()), 'effort' => Serializer::effort($task->getEffort()), 'assignee' => Serializer::user($task->getAssignee()), 'group' => Serializer::groupRef($task->getGroup()), 'project' => Serializer::projectRef($task->getProject()), 'tags' => Serializer::tags($task->getTags()), 'archived' => $task->isArchived(), 'scheduledStart' => $task->getScheduledStart()?->format('c'), 'scheduledEnd' => $task->getScheduledEnd()?->format('c'), 'deadline' => $task->getDeadline()?->format('c'), 'syncToCalendar' => $task->isSyncToCalendar(), ]); } }