* @implements \App\Contracts\HandlesSuccess<\App\Cqs\Actions\Ranges\DeleteRangeInput, bool> * @implements \App\Contracts\HandlesFailure<\App\Cqs\Actions\Ranges\DeleteRangeInput> */ final class DeleteRange implements Action, HandlesFailure, HandlesSuccess { use TracksPendingStoragePaths; public function __construct( protected readonly StorageService $storageService, protected readonly PublicS3Disk $s3Disk, ) { } /** * @param \App\Cqs\Actions\Ranges\DeleteRangeInput $input */ #[\Override] public function __invoke(ActionInput $input): bool { Assert::isInstanceOf($input, DeleteRangeInput::class); $picture = $input->range->picture; $deletion = (bool) $input->range->deleteOrFail(); if ($deletion) { $this->trackObsoletePath($input, $picture); } return $deletion; } #[\Override] public function onSuccess(ActionInput $input, mixed $result): void { foreach ($this->pullObsoletePaths($input) as $path) { if ($this->storageService->fileExistsOnDisk($path, $this->s3Disk->disk)) { $this->storageService->removeFromDisk($path, $this->s3Disk->disk); } } } #[\Override] public function onFailure(ActionInput $input, \Throwable $exception): void { $this->clearTrackedPaths($input); } }