Melde die Wiederverwendung eines Filmbilds ehrlich und erlaube das Löschen der Medien.

- Wird eine schon übernommene Stelle erneut gewählt, nennt die Meldung den tatsächlichen Stand: bereits freigegeben,
  wird verarbeitet oder Website-Freigabe zurückgenommen (bleibt zurückgenommen). Ein bei der Verarbeitung
  gescheitertes oder archiviertes Bild wird nicht wiederverwendet; die Herkunft zeigt dann auf das neue Bild.
- „Medium löschen“ erreicht jetzt Standbilder (film_still_sources: cascade) und übernommene CMS-Bilder
  (website_media_aliases: Zuordnung bleibt als Sperre, die frühere Adresse /medien/cms/… liefert 404, das Widget
  zeigt kein Bild). Vorher hätte der Fremdschlüssel das Löschen mit einem Fehler abgebrochen.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-21 19:36:07 +01:00
1 parent 886715af96
commit cd66561ca9
9 files changed
+197 -15

No files matched your search

@@ -127,6 +127,10 @@ public function url(mixed $value, bool $preview = false): ?string
$legacy = self::normalize($value);
if (is_string($legacy) && WebsiteMediaAlias::isRetired($legacy)) {
return null;
}
return is_string($legacy) ? PublicMedia::url($legacy) : null;
}
@@ -175,6 +179,10 @@ public function status(mixed $value): ?array
$id = $this->elementId($value);
if ($id === null && WebsiteMediaAlias::isRetired($value)) {
return ['public' => false, 'state' => 'missing', 'title' => basename((string) $value), 'note' => 'Das Medium wurde gelöscht.', 'thumb' => null, 'manageUrl' => null];
}
if ($id === null) {
return [
'public' => true,
+22 -8
View File
@@ -28,6 +28,9 @@ class FilmStill
/** Breite eines übernommenen Standbilds; die kleine Filmstufe (640 px) wäre auf der Website sichtbar unscharf. */
public const WIDTH = 1600;
/** Wahr, wenn der letzte Aufruf ein schon vorhandenes Bild geliefert hat (keine neue Extraktion). */
public bool $reused = false;
public function __construct(
private readonly ThumbnailDeriver $deriver,
private readonly WebsiteIntake $intake,
@@ -72,6 +75,7 @@ public function thumbnailSecond(ContentElement $film): ?string
public function fromSecond(ContentElement $film, float $seconds, ?User $actor = null): ContentElement
{
$this->reused = false;
$this->guard($film);
if ($seconds < 0 || $seconds > 7200) {
@@ -89,6 +93,7 @@ public function fromSecond(ContentElement $film, float $seconds, ?User $actor =
public function fromThumbnail(ContentElement $film, ?User $actor = null): ContentElement
{
$this->reused = false;
$this->guard($film);
// Stammt das Vorschaubild aus einer Filmstelle, wird dieselbe Stelle in voller Auflösung gezogen.
@@ -121,8 +126,15 @@ public function fromThumbnail(ContentElement $film, ?User $actor = null): Conten
}
$key = 'file:'.hash('sha256', $bytes);
$existing = $this->existing($film, $key);
return $this->existing($film, $key) ?? $this->store($film, $key, $bytes, 'Vorschaubild', $actor);
if ($existing instanceof ContentElement) {
$this->reused = true;
return $existing;
}
return $this->store($film, $key, $bytes, 'Vorschaubild', $actor);
}
private function fromFrame(ContentElement $film, ContentElementVersion $version, float $seconds, ?User $actor): ContentElement
@@ -132,6 +144,8 @@ private function fromFrame(ContentElement $film, ContentElementVersion $version,
$existing = $this->existing($film, $key);
if ($existing instanceof ContentElement) {
$this->reused = true;
return $existing;
}
@@ -158,7 +172,9 @@ private function existing(ContentElement $film, string $key): ?ContentElement
$source = FilmStillSource::query()->with('still')->where('film_element_id', $film->id)->where('source_key', $key)->first();
$still = $source?->still;
return $still instanceof ContentElement && $still->archived_at === null ? $still : null;
// Ein archiviertes oder an der Verarbeitung gescheitertes Bild wird nicht wiederverwendet; die Stelle kann neu
// übernommen werden (store() ordnet dann das neue Bild zu).
return $still instanceof ContentElement && $still->archived_at === null && ! filled($still->thumbnail_error) ? $still : null;
}
private function store(ContentElement $film, string $key, string $bytes, string $label, ?User $actor): ContentElement
@@ -176,12 +192,10 @@ private function store(ContentElement $film, string $key, string $bytes, string
);
try {
FilmStillSource::query()->create([
'film_element_id' => $film->id,
'still_element_id' => $still->id,
'source_key' => $key,
'actor_id' => $actor?->id,
]);
FilmStillSource::query()->updateOrCreate(
['film_element_id' => $film->id, 'source_key' => $key],
['still_element_id' => $still->id, 'actor_id' => $actor?->id],
);
} catch (QueryException) {
// Gleichzeitige Übernahme derselben Stelle: das zuerst angelegte Bild gilt.
return $this->existing($film, $key) ?? $still;
+10
View File
@@ -37,6 +37,16 @@ public static function effectiveFor(mixed $path): ?self
return $alias instanceof self && $alias->everReleased() ? $alias : null;
}
/**
* Früherer Pfad, dessen übernommenes Medium inzwischen gelöscht wurde. Die Datei unter cms/ bleibt liegen, wird aber
* weder ausgeliefert noch als Bild gezeigt: Das Löschen des Mediums gilt auch für die frühere Adresse.
*/
public static function isRetired(mixed $path): bool
{
return is_string($path) && $path !== ''
&& self::query()->where('legacy_path', $path)->whereNull('content_element_id')->exists();
}
public function everReleased(): bool
{
$element = $this->element;
+27 -6
View File
@@ -6,6 +6,7 @@
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Cms\Widgets\Support\WebsiteImage;
use App\Domain\Media\FilmStill;
use App\Domain\Media\WebsiteMedia;
use App\Filament\Resources\ContentElements\ContentElementResource;
use Filament\Notifications\Notification;
@@ -74,8 +75,10 @@ private function adoptFilmStill(string $pfad, int $elementId, callable $make): v
return;
}
$stills = app(FilmStill::class);
try {
$still = $make(app(FilmStill::class), $film);
$still = $make($stills, $film);
} catch (DomainRuleException $exception) {
Notification::make()->danger()->title($exception->getMessage())->send();
@@ -83,11 +86,29 @@ private function adoptFilmStill(string $pfad, int $elementId, callable $make): v
}
data_set($this, $pfad, $still->id);
Notification::make()
->success()
->title('Im Medienmanager angelegt: „'.($still->display_title ?: $still->working_title).'“')
->body('Das Bild ist als Kartenbild ausgewählt. Nach der Verarbeitung wird es für die Website freigegeben; dort lässt sich die Freigabe auch zurücknehmen.')
->send();
$title = ($still->display_title ?: $still->working_title);
if (! $stills->reused) {
Notification::make()
->success()
->title('Im Medienmanager angelegt: „'.$title.'“')
->body('Das Bild ist als Kartenbild ausgewählt. Nach der Verarbeitung wird es für die Website freigegeben; dort lässt sich die Freigabe auch zurücknehmen.')
->send();
return;
}
// Dieselbe Stelle war schon übernommen: Der tatsächliche Stand des Bildes entscheidet über die Meldung.
if (app(WebsiteMedia::class)->present($still) !== null) {
Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body('Diese Stelle war schon übernommen. Das Bild ist als Kartenbild ausgewählt.')->send();
} elseif (blank($still->thumbnail_path) && blank($still->thumbnail_error)) {
Notification::make()->success()->title('Bereits im Medienmanager: „'.$title.'“')->body('Das Bild wird noch verarbeitet und danach für die Website freigegeben.')->send();
} else {
Notification::make()->warning()->title('Bild ausgewählt, aber nicht für die Website freigegeben: „'.$title.'“')
->body('Diese Stelle war schon übernommen und die Website-Freigabe wurde zurückgenommen. Das Bild erscheint öffentlich erst wieder, wenn sie im Medienmanager (Reiter „Website“) erneut gegeben wird.')
->persistent()
->send();
}
}
/**
@@ -14,6 +14,8 @@ public function show(string $path, WebsiteMedia $media): StreamedResponse
abort_if(str_contains($path, '..') || ! str_starts_with($path, 'cms/'), 404);
// Ein in den Medienmanager übernommenes Bild folgt dessen Website-Freigabe, auch unter der früheren Adresse.
abort_if(WebsiteMediaAlias::isRetired($path), 404);
$alias = WebsiteMediaAlias::effectiveFor($path);
abort_if($alias !== null && $media->present($alias->content_element_id) === null, 404);