76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\ContentElementVersion;
|
|
use App\Domain\Media\ThumbnailDeriver;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
|
|
class DeriveThumbnail implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
public readonly string $subject,
|
|
public readonly int $subjectId,
|
|
public readonly ?string $incoming = null,
|
|
public readonly ?int $fromElement = null,
|
|
public readonly ?int $versionId = null,
|
|
public readonly ?float $atSecond = null,
|
|
) {}
|
|
|
|
public function handle(ThumbnailDeriver $deriver): void
|
|
{
|
|
if ($this->subject === 'komposition') {
|
|
$composition = Composition::query()->find($this->subjectId);
|
|
|
|
if ($composition === null) {
|
|
return;
|
|
}
|
|
|
|
if ($this->fromElement !== null) {
|
|
$element = ContentElement::query()->find($this->fromElement);
|
|
|
|
if ($element !== null) {
|
|
$deriver->forCompositionFromElement($composition, $element);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (is_string($this->incoming)) {
|
|
$deriver->forCompositionUpload($composition, $this->incoming);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
$element = ContentElement::query()->find($this->subjectId);
|
|
|
|
if ($element === null) {
|
|
return;
|
|
}
|
|
|
|
if ($this->versionId !== null && $this->atSecond !== null) {
|
|
$version = ContentElementVersion::query()->find($this->versionId);
|
|
|
|
if ($version instanceof ContentElementVersion) {
|
|
$deriver->forElementFrame($element, $version, $this->atSecond);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (is_string($this->incoming)) {
|
|
$deriver->forElementUpload($element, $this->incoming);
|
|
|
|
return;
|
|
}
|
|
|
|
$deriver->forElement($element);
|
|
}
|
|
}
|