Files
laraundfelix/app/Jobs/DeriveFilmRenditions.php
T
LarsandCursor c997eb500c
Deploy Test / test (push) Successful in 2m28s
Deploy Test / deploy (push) Failing after 14s
Leite Vorschaubilder und Filmstufen geschuetzt ab
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 09:40:59 +01:00

53 lines
1.4 KiB
PHP

<?php
namespace App\Jobs;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Media\FilmTranscoder;
use App\Domain\Media\MediaRendition;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Throwable;
class DeriveFilmRenditions implements ShouldQueue
{
use Queueable;
public int $timeout = 3600;
public function __construct(public readonly int $versionId) {}
public function handle(FilmTranscoder $transcoder): void
{
$version = ContentElementVersion::query()->with('element')->find($this->versionId);
$file = is_array($version?->metadata) ? ($version->metadata['file'] ?? null) : null;
if ($version === null || $version->element->output_class !== 'film' || ! is_string($file) || $file === '') {
return;
}
if (! $transcoder->available()) {
return;
}
try {
$rows = $transcoder->derive($version->id, $file);
} catch (Throwable) {
return;
}
foreach ($rows as $row) {
MediaRendition::query()->updateOrCreate(
[
'content_element_version_id' => $version->id,
'label' => $row['label'],
],
[
'role' => $row['role'],
'path' => $row['path'],
],
);
}
}
}