transactions->run(function () use ($jobId, $data, $actorUserId): void { $job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId); $before = $job->details(); $changes = $job->changeDetails($this->detailsFactory->build($data, $before)); $job->recordCompletion($this->clock->now()); if ($changes === []) { return; } $job = $this->jobs->save($job); $this->jobs->recordChanges($jobId, $actorUserId, $changes); $added = PeopleAddedToJob::between($before, $job, $actorUserId); if ($added !== null) { $this->events->dispatch($added); } }); } }