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:
1 parent
886715af96
commit
cd66561ca9
9 files changed
+197
-15
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user