50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Media\ThumbnailDeriver;
|
|
use App\Domain\Media\WebsiteRelease;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class AcceptWebsiteImage implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
public int $elementId,
|
|
public string $incoming,
|
|
public ?int $actorId = null,
|
|
) {}
|
|
|
|
public function handle(ThumbnailDeriver $deriver, WebsiteRelease $release): void
|
|
{
|
|
$element = ContentElement::query()->find($this->elementId);
|
|
|
|
if (! $element instanceof ContentElement) {
|
|
return;
|
|
}
|
|
|
|
$deriver->forWebsiteImage($element, $this->incoming);
|
|
$element->refresh();
|
|
|
|
if ($release->derivedPath($element) === null) {
|
|
return;
|
|
}
|
|
|
|
if ($this->incomingIsDisposable()) {
|
|
Storage::disk('cms_incoming')->delete($this->incoming);
|
|
}
|
|
|
|
PublishWebsiteMedia::dispatch($element->id, 'release', $this->actorId);
|
|
}
|
|
|
|
private function incomingIsDisposable(): bool
|
|
{
|
|
return (str_starts_with($this->incoming, 'cms/') || str_starts_with($this->incoming, 'vorschau/'))
|
|
&& ! str_contains($this->incoming, '..');
|
|
}
|
|
}
|