finder->ensureTask($jobId, $taskId); $stored = $this->files->store($uploadedFilePath, $taskId); try { return $this->transactions->run(function () use ($jobId, $taskId, $userId, $stored, $originalName, $caption): int { $this->finder->ensureTask($jobId, $taskId); return (int) $this->images->save(TaskImage::create($taskId, $userId, $stored, $originalName, $caption, $this->clock->now()))->id(); }); } catch (Throwable $exception) { $this->files->delete($stored->paths()); throw $exception; } } }