Wähle eine Stelle auch aus der Website-Datei eines Films ohne Fassung als Kartenbild
CI Feature / test (push) Successful in 1m57s
Deploy Test / test (push) Successful in 1m57s
Deploy Test / deploy (push) Successful in 26s

Der Regler „Bild aus dem Film“ der Medienkarte blieb bei einem Film nur mit Website-Datei
(zum Beispiel ein Teaser) aus, weil er eine bereitgestellte Fassung verlangte. Die Stelle
kommt jetzt aus der Website-Datei (Herkunft frame:0@Sekunde, wie im Medienmanager), mit
Vorschau über die Redaktionsroute und Übernahme als Bild-Medium in bis zu 1600 px Breite.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-22 08:41:36 +01:00
1 parent 631502c064
commit 1413e0640f
6 files changed
+247 -18

No files matched your search

@@ -107,20 +107,31 @@ protected function imageSourceFields(): array
->view('filament.cms.filmbild-feld')
->dehydrated(false)
->visible(fn (Get $get): bool => $this->filmFor($get('element')) !== null)
->viewData(function (Get $get): array {
$film = $this->filmFor($get('element'));
$stills = app(FilmStill::class);
$version = $film instanceof ContentElement ? $stills->version($film) : null;
->viewData(fn (Get $get): array => $this->filmFieldData($this->filmFor($get('element')))),
];
}
return [
'film' => $film,
'filmTitle' => $film instanceof ContentElement ? (string) ($film->display_title ?: $film->working_title) : '',
'filmVersionId' => $version?->id,
'filmHasThumbnail' => $film instanceof ContentElement && is_string($film->thumbnail_path) && $film->thumbnail_path !== '',
'filmThumbnailUrl' => $film instanceof ContentElement ? ThumbnailRef::url('editorial.card', 'element', (int) $film->id, $film->thumbnail_path) : null,
'filmStartSecond' => $film instanceof ContentElement ? ($stills->thumbnailSecond($film) ?? '0') : '0',
];
}),
/**
* Anzeigedaten des Felds „Bild aus dem Film“. Die Stelle kommt aus der bereitgestellten Fassung, bei einem Film
* nur mit Website-Datei aus dieser (Route content.website-frame).
*
* @return array<string, mixed>
*/
protected function filmFieldData(?ContentElement $film): array
{
$stills = app(FilmStill::class);
$version = $film instanceof ContentElement ? $stills->version($film) : null;
return [
'film' => $film,
'filmTitle' => $film instanceof ContentElement ? (string) ($film->display_title ?: $film->working_title) : '',
'filmVersionId' => $version?->id,
'filmWebsiteFrameUrl' => $film instanceof ContentElement && $version === null && $stills->websiteFile($film) !== null
? route('content.website-frame', ['element' => $film])
: null,
'filmHasThumbnail' => $film instanceof ContentElement && is_string($film->thumbnail_path) && $film->thumbnail_path !== '',
'filmThumbnailUrl' => $film instanceof ContentElement ? ThumbnailRef::url('editorial.card', 'element', (int) $film->id, $film->thumbnail_path) : null,
'filmStartSecond' => $film instanceof ContentElement ? ($stills->thumbnailSecond($film) ?? '0') : '0',
];
}
+45 -1
View File
@@ -15,6 +15,8 @@
/**
* Legt ein Bild aus einem Film als gewöhnliches Bild-Medium im Medienmanager ab (Medien- und Materialkarte).
*
* - Die Stelle kommt aus der bereitgestellten Fassung, bei einem Film ohne solche Fassung (zum Beispiel ein Teaser nur
* mit Website-Datei) aus der Website-Datei (`teaser/`, Herkunft `frame:0@Sekunde`).
* - Zwei Wege: das Vorschaubild des Films übernehmen oder eine Stelle (Sekunde) wählen. Beides ist eine
* ausdrückliche Handlung der Redaktion; erst dadurch entsteht ein Bild, das für die Website freigegeben werden kann.
* - Das Bild wird einmal gezogen und gespeichert (WebsiteIntake legt es an, die Warteschlange leitet es ab und gibt
@@ -65,6 +67,23 @@ public function version(ContentElement $film): ?ContentElementVersion
->first();
}
/**
* Die Website-Datei, aus der Stellen gezogen werden, wenn es keine bereitgestellte Fassung gibt (Film nur mit
* Website-Datei). Sonst null.
*/
public function websiteFile(ContentElement $film): ?string
{
$path = $film->preview_path;
if ($this->version($film) instanceof ContentElementVersion
|| ! is_string($path) || $path === '' || str_contains($path, '..') || ! str_starts_with($path, 'teaser/')
|| ! Storage::disk('media_derived')->exists($path)) {
return null;
}
return $path;
}
/** Sekunde der Stelle, aus der das aktuelle Vorschaubild des Films stammt, sonst null. */
public function thumbnailSecond(ContentElement $film): ?string
{
@@ -85,7 +104,11 @@ public function fromSecond(ContentElement $film, float $seconds, ?User $actor =
$version = $this->version($film);
if (! $version instanceof ContentElementVersion) {
throw new DomainRuleException('Der Film hat noch keine bereitgestellte Fassung.');
if ($this->websiteFile($film) !== null) {
return $this->fromWebsiteFrame($film, $seconds, $actor);
}
throw new DomainRuleException('Der Film hat weder eine bereitgestellte Fassung noch eine Website-Datei.');
}
return $this->fromFrame($film, $version, $seconds, $actor);
@@ -158,6 +181,27 @@ private function fromFrame(ContentElement $film, ContentElementVersion $version,
return $this->store($film, $key, $bytes, 'Fassung '.$version->number.', '.str_replace('.', ',', $second).' s', $actor);
}
private function fromWebsiteFrame(ContentElement $film, float $seconds, ?User $actor): ContentElement
{
$second = $this->secondText($seconds);
$key = 'frame:0@'.$second;
$existing = $this->existing($film, $key);
if ($existing instanceof ContentElement) {
$this->reused = true;
return $existing;
}
$bytes = $this->deriver->websiteFileJpeg($film, (float) $second, self::WIDTH);
if (! is_string($bytes)) {
throw new DomainRuleException('Aus dieser Stelle der Website-Datei ließ sich kein Bild erzeugen.');
}
return $this->store($film, $key, $bytes, 'Website-Datei, '.str_replace('.', ',', $second).' s', $actor);
}
private function guard(ContentElement $film): void
{
$refusal = $this->refusal($film);
+10 -1
View File
@@ -215,6 +215,15 @@ public function frameJpeg(ContentElementVersion $version, float $seconds, int $w
* Einzelbild aus der Website-Datei eines Films (`teaser/`), für Medien ohne Inhaltsfassung.
*/
public function jpegAtWebsiteFile(ContentElement $element, float $seconds): ?string
{
return $this->websiteFileJpeg($element, $seconds, 640);
}
/**
* Einzelbild aus der Website-Datei in der gewünschten Breite, nie über die Breite der Datei hinaus (Standbild für
* die Medienkarte, FilmStill).
*/
public function websiteFileJpeg(ContentElement $element, float $seconds, int $width): ?string
{
$file = $element->preview_path;
@@ -222,7 +231,7 @@ public function jpegAtWebsiteFile(ContentElement $element, float $seconds): ?str
return null;
}
return $this->jpegFromFile($file, $seconds, 640);
return $this->jpegFromFile($file, $seconds, $width);
}
private function jpegFromFile(string $file, float $seconds, int $width): ?string
@@ -169,6 +169,7 @@ ### Bild aus dem Film
`FilmStill` zieht das Einzelbild **einmal** und legt es über `WebsiteIntake` als gewöhnliches Bild-Medium (`output_class = bild`) im Medienmanager ab. Die Warteschlange leitet es ab und gibt genau diese Ableitung frei, wie bei jedem Upload aus dem CMS. Die Karte speichert die Kennung dieses Bildes in `refs.image`.
- **Film nur mit Website-Datei (22.11.2026):** Hat ein Film keine bereitgestellte Fassung, aber eine Website-Datei (`teaser/…`, zum Beispiel ein Teaser), kommt die Stelle aus dieser Datei (Regler und Vorschau über `content.website-frame`, Herkunft `frame:0@Sekunde`, höchstens die Breite der Datei). Vorher blieb der Regler dafür aus („keine bereitgestellte Fassung“).
- **Kein Neuziehen:** Seitenaufrufe lesen nur die gespeicherte Datei; `ffmpeg` läuft nur beim Übernehmen und in der Vorschau des Dialogs (Route `editorial.frame`, nur angemeldete Redaktion). Test: `FilmStillTest` zählt die Extraktionen.
- **Einmal je Stelle:** `film_still_sources` (additive Tabelle) ordnet Film, Quelle (`frame:{Fassung}@{Sekunde}` oder `file:{SHA-256}`) und Bild zu. Dieselbe Stelle, auch über „Vorschaubild übernehmen“ eines Filmbilds aus derselben Stelle, ergibt dasselbe Medium. Ein archiviertes oder bei der Verarbeitung gescheitertes Bild wird nicht wiederverwendet; die Stelle lässt sich dann neu übernehmen.
- **Wiederverwendung ehrlich melden:** Wird ein schon übernommenes Bild gewählt, sagt die Meldung, wie es steht (bereits freigegeben, wird verarbeitet oder Website-Freigabe zurückgenommen). Eine zurückgenommene Freigabe bleibt zurückgenommen; das Bild erscheint öffentlich erst nach erneuter Freigabe im Medienmanager (Reiter „Website“).
@@ -8,7 +8,8 @@
@php
$pfad = $getStatePath();
$ziel = preg_replace('/[^.]+$/', 'image', $pfad);
$framePfad = $filmVersionId !== null ? route('editorial.frame', ['version' => $filmVersionId]) : null;
$framePfad = $filmVersionId !== null ? route('editorial.frame', ['version' => $filmVersionId]) : ($filmWebsiteFrameUrl ?? null);
$ausWebsiteDatei = $filmVersionId === null && ($filmWebsiteFrameUrl ?? null) !== null;
@endphp
<x-dynamic-component :component="$getFieldWrapperView()" :field="$field">
<div class="luf-filmbild"
@@ -16,7 +17,7 @@
show() { if (this.second !== '' && ! isNaN(Number(this.second)) && Number(this.second) >= 0) { this.shown = this.second; } } }">
<p class="luf-filmbild-lead">
Aus dem Film „{{ $filmTitle }}“ ein Bild für die Website übernehmen. Das Bild wird einmal gespeichert und im
Medienmanager als Bild angelegt. Der Film selbst wird nicht veröffentlicht; die Karte spielt nichts ab.
Medienmanager als Bild angelegt. Der Film selbst wird nicht veröffentlicht.@if ($ausWebsiteDatei) Die Stelle kommt aus der Website-Datei des Films.@endif
</p>
@if ($framePfad !== null)
<div class="luf-filmbild-regler">
@@ -34,7 +35,7 @@
</x-filament::button>
</div>
@else
<p class="luf-filmbild-lead">Der Film hat noch keine bereitgestellte Fassung; eine Stelle lässt sich erst danach wählen.</p>
<p class="luf-filmbild-lead">Der Film hat weder eine bereitgestellte Fassung noch eine Website-Datei; eine Stelle lässt sich erst danach wählen.</p>
@endif
@if ($filmHasThumbnail)
<div class="luf-filmbild-aktuell">
+163
View File
@@ -0,0 +1,163 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Domain\Media\FilmStill;
use App\Domain\Media\FilmStillSource;
use App\Domain\Media\ThumbnailDeriver;
use App\Filament\Resources\Pages\Pages\EditPage;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Bild aus einem Film nur mit Website-Datei (zum Beispiel ein Teaser) für die Medienkarte: Die Stelle kommt aus der
* Website-Datei, weil es keine bereitgestellte Fassung gibt. Die Bildextraktion (ffmpeg) ist durch einen Stub ersetzt.
*/
class FilmStillWebsiteFileTest extends TestCase
{
use RefreshDatabase;
/** @var object{calls: list<array{second: float, width: int}>, fail: bool} */
private object $extractor;
protected function setUp(): void
{
parent::setUp();
Storage::fake('cms_incoming');
Storage::fake('media_derived');
Storage::fake('media_public');
Storage::fake('media_originals');
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
$this->extractor = new class($this->jpeg()) extends ThumbnailDeriver
{
/** @var list<array{second: float, width: int}> */
public array $calls = [];
public bool $fail = false;
public function __construct(private readonly string $jpeg) {}
public function websiteFileJpeg(ContentElement $element, float $seconds, int $width): ?string
{
$this->calls[] = ['second' => $seconds, 'width' => $width];
return $this->fail ? null : $this->jpeg;
}
};
$this->app->instance(ThumbnailDeriver::class, $this->extractor);
}
public function test_a_frame_of_the_website_file_becomes_one_image_medium(): void
{
$film = $this->teaser();
$editor = User::factory()->redakteur()->create();
$still = app(FilmStill::class)->fromSecond($film, 7.5, $editor)->refresh();
$this->assertSame('bild', $still->output_class);
$this->assertSame('Standbild: Teaser Denkpause (Website-Datei, 7,5 s)', $still->display_title);
$this->assertSame('Szene aus dem Film „Teaser Denkpause“', $still->website_alt);
$this->assertSame(0, $still->versions()->count(), 'Es entsteht keine Inhaltsfassung.');
$this->assertSame([['second' => 7.5, 'width' => FilmStill::WIDTH]], $this->extractor->calls);
$this->assertSame('frame:0@7.5', FilmStillSource::query()->where('film_element_id', $film->id)->value('source_key'));
$this->assertSame($still->id, FilmStillSource::query()->value('still_element_id'));
}
public function test_the_same_frame_of_the_website_file_is_never_extracted_twice(): void
{
$film = $this->teaser();
$first = app(FilmStill::class)->fromSecond($film, 3);
$again = app(FilmStill::class)->fromSecond($film, 3.0);
$this->assertSame($first->id, $again->id);
$this->assertCount(1, $this->extractor->calls);
}
public function test_a_film_with_neither_a_version_nor_a_website_file_is_refused(): void
{
$film = app(ContentService::class)->createElement('film', 'film', 'Leer');
$this->assertNull(app(FilmStill::class)->websiteFile($film));
$this->expectException(DomainRuleException::class);
$this->expectExceptionMessage('weder eine bereitgestellte Fassung noch eine Website-Datei');
app(FilmStill::class)->fromSecond($film, 3);
}
public function test_a_frame_that_cannot_be_extracted_creates_nothing(): void
{
$film = $this->teaser();
$this->extractor->fail = true;
$before = ContentElement::query()->count();
try {
app(FilmStill::class)->fromSecond($film, 3);
$this->fail('Ohne Bild darf nichts angelegt werden.');
} catch (DomainRuleException $exception) {
$this->assertStringContainsString('Website-Datei', $exception->getMessage());
}
$this->assertSame($before, ContentElement::query()->count());
}
public function test_the_editor_adopts_a_frame_of_the_website_file_into_the_card_image(): void
{
$film = $this->teaser();
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
$page = Page::query()->create(['path' => '/teaser-bild']);
app(PageService::class)->saveRevision($page, [
['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['element' => $film->id]]]],
], null, null, null);
$component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]);
$component->call('adoptFilmFrame', 'data.ziel.image', $film->id, '7.5');
$still = ContentElement::query()->where('output_class', 'bild')->latest('id')->firstOrFail();
$this->assertSame($still->id, $component->get('data.ziel.image'));
$component->assertNotified('Im Medienmanager angelegt: „Standbild: Teaser Denkpause (Website-Datei, 7,5 s)“');
}
public function test_the_card_field_offers_the_slider_with_the_website_file_for_such_a_film(): void
{
$film = $this->teaser();
$widget = app(WidgetRegistry::class)->get('media_card');
$data = (new \ReflectionMethod($widget, 'filmFieldData'))->invoke($widget, $film);
$this->assertNull($data['filmVersionId']);
$this->assertSame(route('content.website-frame', ['element' => $film]), $data['filmWebsiteFrameUrl'], 'Der Regler zeigt Stellen der Website-Datei.');
$this->assertSame('0', $data['filmStartSecond']);
}
private function teaser(): ContentElement
{
$film = app(ContentService::class)->createElement('film', 'film', 'Teaser Denkpause');
$film->forceFill(['preview_path' => 'teaser/'.$film->id.'/datei.mp4'])->save();
Storage::disk('media_derived')->put($film->preview_path, 'x');
return $film->fresh();
}
private function jpeg(): string
{
$image = imagecreatetruecolor(1600, 900);
imagefill($image, 0, 0, imagecolorallocate($image, 40, 120, 90));
ob_start();
imagejpeg($image);
return (string) ob_get_clean();
}
}