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); if ($fromUserId !== $toUserId) { $this->references->check($job, $task->workTypeId(), $toUserId, [], $task); $task->assignTo($toUserId); } $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, ); }); } }