transactions->run(function () use ($jobId, $taskId, $fromUserId, $toUserId, $from, $to): ScheduleResult { $job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId); $task = $this->tasks->findForJob($jobId, $taskId) ?? throw new TaskNotFound($jobId, $taskId); $assignees = $task->assigneeUserIds(); if ($fromUserId !== $toUserId) { $assignees = array_values(array_filter($assignees, fn (int $userId): bool => $userId !== $fromUserId)); if ($toUserId !== null) { $assignees[] = $toUserId; } } $this->references->check($job, $task->workTypeId(), $assignees, $task); $task->changeAssignees($assignees); $task->schedule($from, $to ?? $this->planner->defaultEnd($from, $task)); $task = $this->tasks->save($task); $extended = $this->planner->plan($task); $task = $this->tasks->save($task); return new ScheduleResult( (string) $task->plannedFrom()?->format('Y-m-d'), (string) $task->plannedTo()?->format('Y-m-d'), $extended, ); }); } }