- B-01/B-02: Startseiten-Feed, Card-Helfer und Nachweis-PDF nur mit isPubliclyDeliverable() - B-03: Livewire-Temp-Upload 16 MiB - N09: Snapshot je Bytes- und Metadaten-Hash inkl. OG-Variante, put() geprüft, alle Fassungen ins Archiv - O03: published_ever_at in der Freigabetransaktion (markPublishedIfNowPublic) — Kundenbestätigung, Vorab-Sichtung, Korrektur - B-04/B-14: Bestätigung an Bild-ID und SHA gebunden, unter Sperre - B-05/B-06: Entfernen unter Sperre mit frischem Stand und Archivauftrag; Korrektur archiviert über den Auftrag, Nacharbeiten abgesichert - B-07: precheck_withheld_at getrennt von withheld_at (Migration + Übernahme) - B-08, B-09, B-11, B-12: published_ever_at nur bei Status published, Admin-Eigentümer mit Kundenregel, Sweep verwaister Originale, Verarbeitungsfehler als Formularmeldung - K-02-Teil: nach Kundenbestätigung erneut routen - OPT-3 bis OPT-5: pingImage für JPEG, Hash durchgereicht, erstes Frame Admin-PM-Detailseite enthält zusätzlich K-06 (Autorisierung) und A-08 (Nachweis per POST), weil die Datei ungeteilt committet ist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
159 lines
6.8 KiB
PHP
159 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\PressRelease\Images;
|
|
|
|
use App\Enums\AiDeclarationSource;
|
|
use App\Enums\AiImageDeclaration;
|
|
use App\Enums\ArchiveEvent;
|
|
use App\Enums\ArchiveReasonCategory;
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Models\ArchivePendingJob;
|
|
use App\Models\ImageDeclarationCorrection;
|
|
use App\Models\PressReleaseImage;
|
|
use App\Models\User;
|
|
use App\Services\Archive\ArchivePendingQueue;
|
|
use App\Services\Archive\PressReleaseArchiver;
|
|
use App\Services\Image\ImageService;
|
|
use App\Support\ImageCredit;
|
|
use App\Support\WebCaches;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Korrekturweg (Bildkennzeichnung E.6, Decision-Update S17): Der Admin
|
|
* ändert Bildnachweis oder Portalkennzeichnung mit Pflichtgrund oder hält
|
|
* das Bild vorläufig zurück. Kundenangabe, ursprüngliche Bestätigung und
|
|
* Befund bleiben unverändert; jede Änderung ist insert-only protokolliert.
|
|
*/
|
|
class ImageCorrectionService
|
|
{
|
|
public function __construct(
|
|
private readonly PublishedImageSnapshot $snapshots,
|
|
private readonly PressReleaseArchiver $archiver,
|
|
private readonly ImageService $imageService,
|
|
private readonly ArchivePendingQueue $pendingArchive,
|
|
) {}
|
|
|
|
public function correctCredit(PressReleaseImage $image, User $admin, string $newCredit, string $reason): ImageDeclarationCorrection
|
|
{
|
|
return $this->apply($image, $admin, ImageDeclarationCorrection::FIELD_CREDIT, $image->copyright, $newCredit, null, $reason, function () use ($image, $newCredit): void {
|
|
$image->forceFill(['copyright' => $newCredit])->save();
|
|
});
|
|
}
|
|
|
|
public function correctAiDeclaration(PressReleaseImage $image, User $admin, AiImageDeclaration $new, string $reason): ImageDeclarationCorrection
|
|
{
|
|
return $this->apply($image, $admin, ImageDeclarationCorrection::FIELD_AI_DECLARATION, $image->ai_declaration?->value, $new->value, $image->ai_declaration_source?->value, $reason, function () use ($image, $new): void {
|
|
$image->forceFill([
|
|
'ai_declaration' => $new,
|
|
'ai_declaration_source' => AiDeclarationSource::AdminCorrection,
|
|
'ai_declaration_locked' => false,
|
|
])->save();
|
|
});
|
|
}
|
|
|
|
public function withhold(PressReleaseImage $image, User $admin, string $reason): ImageDeclarationCorrection
|
|
{
|
|
return $this->apply($image, $admin, ImageDeclarationCorrection::FIELD_WITHHELD, '0', '1', null, $reason, function () use ($image): void {
|
|
$image->forceFill(['withheld_at' => now()])->save();
|
|
});
|
|
}
|
|
|
|
public function release(PressReleaseImage $image, User $admin, string $reason): ImageDeclarationCorrection
|
|
{
|
|
return $this->apply($image, $admin, ImageDeclarationCorrection::FIELD_WITHHELD, '1', '0', null, $reason, function () use ($image): void {
|
|
$image->forceFill(['withheld_at' => null])->save();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Der eingebrannte Nachweis der OG-Variante muss der Korrektur folgen (H.1).
|
|
*/
|
|
public function refreshOgVariant(PressReleaseImage $image): void
|
|
{
|
|
$caption = ImageCredit::for($image, $image->pressRelease?->company)->line();
|
|
$path = $this->imageService->regenerateOgVariant(
|
|
$image->disk,
|
|
$image->variants,
|
|
$image->path,
|
|
$image->focus_x !== null && $image->focus_y !== null ? ['x' => $image->focus_x, 'y' => $image->focus_y] : null,
|
|
(bool) $image->no_crop,
|
|
$caption,
|
|
);
|
|
|
|
if ($path !== null) {
|
|
$image->forceFill(['variants' => array_merge((array) $image->variants, ['og' => $path])])->save();
|
|
}
|
|
}
|
|
|
|
private function apply(PressReleaseImage $image, User $admin, string $field, ?string $old, ?string $new, ?string $oldSource, string $reason, \Closure $mutation): ImageDeclarationCorrection
|
|
{
|
|
// Nie veröffentlicht: kein Archiveintrag (DU 4.1, Umsetzungsaudit
|
|
// 5.1 b) — die Korrekturzeile dokumentiert den Vorgang; wird das Bild
|
|
// später veröffentlicht und entfernt, wandern alle Korrekturen mit
|
|
// dem image_removed-Eintrag ins Archiv.
|
|
$archive = $image->wasEverPublished();
|
|
|
|
/** @var array{0: ImageDeclarationCorrection, 1: ArchivePendingJob|null} $result */
|
|
$result = DB::transaction(function () use ($image, $admin, $field, $old, $new, $oldSource, $reason, $mutation, $archive): array {
|
|
$mutation();
|
|
$image->markPublishedIfNowPublic();
|
|
|
|
$correction = ImageDeclarationCorrection::query()->create([
|
|
'press_release_image_id' => $image->getKey(),
|
|
'press_release_id' => $image->press_release_id,
|
|
'admin_id' => $admin->getKey(),
|
|
'field' => $field,
|
|
'old_value' => $old,
|
|
'new_value' => $new,
|
|
'old_source' => $oldSource,
|
|
'reason' => $reason,
|
|
'created_at' => now(),
|
|
]);
|
|
|
|
// Auftrag „Archivierung steht aus" in derselben Transaktion
|
|
// (Umsetzungsaudit 29.09., B-06/A-09): archive:retry-pending holt
|
|
// label_corrected nach, wenn die Ablage unten scheitert.
|
|
$job = $archive
|
|
? $this->pendingArchive->push((int) $image->press_release_id, ArchiveEvent::LabelCorrected, $correction, ArchiveReasonCategory::Correction, actorId: (int) $admin->getKey())
|
|
: null;
|
|
|
|
return [$correction, $job];
|
|
});
|
|
|
|
[$correction, $job] = $result;
|
|
$fresh = $image->fresh() ?? $image;
|
|
|
|
// Zuerst der Archiveintrag (Block F.4); completeWith() wirft nie und
|
|
// lässt den Auftrag bei einem Fehler offen.
|
|
if ($job !== null) {
|
|
$this->pendingArchive->completeWith($job, fn () => $this->archiver->labelCorrected($fresh, $correction, $admin));
|
|
}
|
|
|
|
// Nacharbeiten nach dem N08-Muster: ein Fehler wird gemeldet und
|
|
// kostet weder die Korrektur noch den Archiveintrag.
|
|
if (in_array($field, [ImageDeclarationCorrection::FIELD_CREDIT, ImageDeclarationCorrection::FIELD_AI_DECLARATION], true)) {
|
|
$this->quietly(fn () => $this->refreshOgVariant($fresh));
|
|
}
|
|
|
|
// Öffentliche Fassung hat sich geändert: Snapshot nachziehen (neue
|
|
// Fassung, N09) und Seiten-Caches verwerfen (D.5). Auch für ein an
|
|
// einer veröffentlichten Meldung freigegebenes Bild, das damit erst
|
|
// öffentlich wird.
|
|
if ($archive || $fresh->pressRelease?->status === PressReleaseStatus::Published) {
|
|
$this->quietly(fn () => $this->snapshots->capture($fresh->fresh() ?? $fresh));
|
|
$this->quietly(fn () => WebCaches::forgetPublicPages());
|
|
}
|
|
|
|
return $correction;
|
|
}
|
|
|
|
private function quietly(\Closure $step): void
|
|
{
|
|
try {
|
|
$step();
|
|
} catch (Throwable $exception) {
|
|
report($exception);
|
|
}
|
|
}
|
|
}
|