2026-09-29 16:59:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
namespace App\Cqs\Actions\Ranges;
|
2026-09-29 16:59:07 +02:00
|
|
|
|
|
|
|
|
use App\Contracts\Action;
|
|
|
|
|
use App\Contracts\ActionInput;
|
2026-11-15 20:31:37 +01:00
|
|
|
use App\Contracts\HandlesFailure;
|
|
|
|
|
use App\Contracts\HandlesSuccess;
|
2026-11-14 16:06:12 +01:00
|
|
|
use App\Lib\PublicS3Disk;
|
2026-11-15 20:31:37 +01:00
|
|
|
use App\Traits\TracksPendingStoragePaths;
|
2026-11-14 16:06:12 +01:00
|
|
|
use Uwil\Storage\Contracts\StorageService;
|
2026-09-29 16:59:07 +02:00
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
|
|
/**
|
2026-11-10 14:28:00 +01:00
|
|
|
* @implements \App\Contracts\Action<\App\Cqs\Actions\Ranges\DeleteRangeInput, bool>
|
2026-11-15 20:31:37 +01:00
|
|
|
* @implements \App\Contracts\HandlesSuccess<\App\Cqs\Actions\Ranges\DeleteRangeInput, bool>
|
|
|
|
|
* @implements \App\Contracts\HandlesFailure<\App\Cqs\Actions\Ranges\DeleteRangeInput>
|
2026-09-29 16:59:07 +02:00
|
|
|
*/
|
2026-11-15 20:31:37 +01:00
|
|
|
final class DeleteRange implements Action, HandlesFailure, HandlesSuccess
|
2026-09-29 16:59:07 +02:00
|
|
|
{
|
2026-11-15 20:31:37 +01:00
|
|
|
use TracksPendingStoragePaths;
|
|
|
|
|
|
2026-11-14 16:06:12 +01:00
|
|
|
public function __construct(
|
|
|
|
|
protected readonly StorageService $storageService,
|
|
|
|
|
protected readonly PublicS3Disk $s3Disk,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-29 16:59:07 +02:00
|
|
|
/**
|
2026-11-10 14:28:00 +01:00
|
|
|
* @param \App\Cqs\Actions\Ranges\DeleteRangeInput $input
|
2026-09-29 16:59:07 +02:00
|
|
|
*/
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function __invoke(ActionInput $input): bool
|
|
|
|
|
{
|
|
|
|
|
Assert::isInstanceOf($input, DeleteRangeInput::class);
|
|
|
|
|
|
2026-11-15 20:31:37 +01:00
|
|
|
$picture = $input->range->picture;
|
2026-11-14 16:06:12 +01:00
|
|
|
$deletion = (bool) $input->range->deleteOrFail();
|
|
|
|
|
|
2026-11-15 20:31:37 +01:00
|
|
|
if ($deletion) {
|
|
|
|
|
$this->trackObsoletePath($input, $picture);
|
2026-11-14 16:06:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $deletion;
|
2026-09-29 16:59:07 +02:00
|
|
|
}
|
2026-11-15 20:31:37 +01:00
|
|
|
|
|
|
|
|
#[\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);
|
|
|
|
|
}
|
2026-09-29 16:59:07 +02:00
|
|
|
}
|