43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cqs\Actions\Slides;
|
|
|
|
use App\Contracts\Action;
|
|
use App\Contracts\ActionInput;
|
|
use App\Lib\PublicS3Disk;
|
|
use Uwil\Storage\Contracts\StorageService;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Action<\App\Cqs\Actions\Slides\DeleteSlideInput, bool>
|
|
*/
|
|
final class DeleteSlide implements Action
|
|
{
|
|
public function __construct(
|
|
private readonly StorageService $storageService,
|
|
private readonly PublicS3Disk $s3Disk,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param \App\Cqs\Actions\Slides\DeleteSlideInput $input
|
|
*/
|
|
#[\Override]
|
|
public function __invoke(ActionInput $input): bool
|
|
{
|
|
Assert::isInstanceOf($input, DeleteSlideInput::class);
|
|
|
|
$deletion = (bool) $input->slide->deleteOrFail();
|
|
|
|
if (
|
|
$deletion && $input->slide->picture && $this->storageService
|
|
->fileExistsOnDisk($input->slide->picture, $this->s3Disk->disk)
|
|
) {
|
|
$this->storageService->removeFromDisk($input->slide->picture, $this->s3Disk->disk);
|
|
}
|
|
|
|
return $deletion;
|
|
}
|
|
}
|