web/api/ki: Soft Deletes wieder wirksam, Caches bei Firmenwechsel, KI-Ergebnis an Inhalt gebunden (Audit Block 3+4, Deploy D)
Block 3 — Sichtbarkeit, Löschung, Cache, Eingaben F04: withoutGlobalScopes() ohne Argument entfernte neben dem PortalScope auch den Soft-Delete-Filter. Öffentliche, Kunden-, API-, Vorschau- und Medienpfade sowie die PressRelease-Helfer schreiben jetzt withoutGlobalScope(PortalScope::class). Zwei Stellen, die der Audit nicht kannte: die öffentliche Meldungsseite zeigte gelöschte Firmenkontakte mit Name, Mail und Telefon; das Pressefach listete gelöschte Kontakte weiter und ließ sie bearbeiten. Ein Architekturtest friert die 39 bewusst verbliebenen Stellen (Admin, Importer, Befehle, Slug-Eindeutigkeit) ein. Der Vorschau-Test prüfte bisher forceDelete statt delete. F22: LOWER(email) machte auf companies (110k Zeilen) bei jedem Login einen Vollscan; die Kollation ist ohnehin case-insensitiv. EmailQuery vergleicht auf MySQL direkt über den Index, auf SQLite (Tests) weiter per LOWER. Neuer Index contacts_email_idx. F13: Firmen-Observer verwirft die öffentlichen Seiten-Caches bei Löschung, Wiederherstellung und is_active-Wechsel auf jedem Weg; die Newsroom-Seite prüft Sichtbarkeit vor dem Cache-Treffer; Kontakt- Änderungen im Pressefach flushen. Der Tombstone-Test wärmte den Cache vorher nicht und traf den Fehler nie. F12: Gemeldete URLs werden über Host, Ausgabe und Slug aufgelöst (ReportedUrlResolver); fremde Hosts zählen nicht, bei Doppelveröffentlichung gewinnt die Erstquelle. F11: per_page 1–100, status als Enum, language nur de/en, Kategorie muss aktiv sein und zum Ziel-Portal passen. Legacy-Aliasse behalten ihren Vertrag. F23: Rückgabewert von put() wird geprüft; Logo erst speichern, dann Datenbank, dann altes Logo löschen. Fehler enden als Feldfehler, nicht als verlorenes Logo. Block 4 — KI-Prüfung und Scheduler F07: Klassifikation und Score tragen die Prüfsumme des Inhalts bei Einplanung. Weicht sie beim Speichern ab, wird das Ergebnis verworfen (ki_audits.discarded_at) und ein neuer Lauf eingeplant. Der Scheduler veröffentlicht keine Meldung, deren jüngste Klassifikation nicht zum aktuellen Text passt, sondern plant eine Prüfung mit Routing ein. F18: Kontingent an den Kalendermonat gebunden (users.press_release_quota_period). Verbrauch aus einem früheren Monat zählt null, auch ohne Reset-Cron; der Reset ist idempotent und lässt den laufenden Monat in Ruhe. F20: Der Publikations-Scheduler liefert bei technischen Fehlern einen Fehler-Exit-Code, damit der Failure-Hook greift. F17: KI-Jobs mit $timeout = 120, retry_after 150; Runbook ergänzt. F19: Aggregation der Aufrufe unter einem Cache-Lock für alle Einstiege. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
301bca3a90
commit
72432fdb82
73 changed files with 1746 additions and 170 deletions
|
|
@ -145,41 +145,68 @@ new #[Layout('components.layouts.app'), Title('Firma bearbeiten')] class extends
|
|||
}
|
||||
|
||||
$slug = $company->generateUniqueSlug($this->company_name, ['portal' => $this->portal]);
|
||||
$logoPath = $company->logo_path;
|
||||
$logoVariants = $company->logo_variants;
|
||||
$previousLogoPath = $company->logo_path;
|
||||
$previousLogoVariants = $company->logo_variants;
|
||||
$logoPath = $previousLogoPath;
|
||||
$logoVariants = $previousLogoVariants;
|
||||
$discardPreviousLogo = false;
|
||||
$stored = null;
|
||||
|
||||
if ($this->remove_logo) {
|
||||
$imageService->deleteCompanyLogo($company->logo_path, $company->logo_variants);
|
||||
$logoPath = null;
|
||||
$logoVariants = null;
|
||||
$discardPreviousLogo = true;
|
||||
}
|
||||
|
||||
if ($this->logo) {
|
||||
$imageService->deleteCompanyLogo($logoPath, $logoVariants);
|
||||
// Erst die neue Datei speichern, dann die DB-Referenz wechseln, das
|
||||
// alte Logo erst danach löschen: Scheitert der Storage, bleiben
|
||||
// bisheriges Logo und Datensatz unangetastet (F23).
|
||||
try {
|
||||
$stored = $imageService->storeCompanyLogo(
|
||||
$this->logo,
|
||||
$this->portal === Portal::Both->value ? Portal::Presseecho->value : $this->portal,
|
||||
$company->id,
|
||||
);
|
||||
} catch (\RuntimeException $exception) {
|
||||
report($exception);
|
||||
|
||||
$stored = $imageService->storeCompanyLogo(
|
||||
$this->logo,
|
||||
$this->portal === Portal::Both->value ? Portal::Presseecho->value : $this->portal,
|
||||
$company->id,
|
||||
);
|
||||
throw ValidationException::withMessages([
|
||||
'logo' => __('Das Logo konnte nicht gespeichert werden. Bitte versuchen Sie es erneut.'),
|
||||
]);
|
||||
}
|
||||
|
||||
$logoPath = $stored['path'];
|
||||
$logoVariants = $stored['variants'];
|
||||
$discardPreviousLogo = true;
|
||||
}
|
||||
|
||||
$company->update([
|
||||
'portal' => $this->portal,
|
||||
'name' => $this->company_name,
|
||||
'slug' => $slug,
|
||||
'address' => $this->composeAddress(),
|
||||
'country_code' => strtoupper($this->country),
|
||||
'phone' => $this->phone ?: null,
|
||||
'email' => $this->email ?: null,
|
||||
'website' => $this->website ?: null,
|
||||
'logo_path' => $logoPath,
|
||||
'logo_variants' => $logoVariants,
|
||||
'is_active' => $this->is_active,
|
||||
]);
|
||||
try {
|
||||
$company->update([
|
||||
'portal' => $this->portal,
|
||||
'name' => $this->company_name,
|
||||
'slug' => $slug,
|
||||
'address' => $this->composeAddress(),
|
||||
'country_code' => strtoupper($this->country),
|
||||
'phone' => $this->phone ?: null,
|
||||
'email' => $this->email ?: null,
|
||||
'website' => $this->website ?: null,
|
||||
'logo_path' => $logoPath,
|
||||
'logo_variants' => $logoVariants,
|
||||
'is_active' => $this->is_active,
|
||||
]);
|
||||
} catch (\Throwable $exception) {
|
||||
// Ohne DB-Referenz wäre die neue Datei verwaist.
|
||||
if ($stored !== null) {
|
||||
$imageService->deleteCompanyLogo($stored['path'], $stored['variants']);
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
if ($discardPreviousLogo && $previousLogoPath !== null && $previousLogoPath !== $logoPath) {
|
||||
$imageService->deleteCompanyLogo($previousLogoPath, $previousLogoVariants);
|
||||
}
|
||||
|
||||
session()->flash('success', 'Firma erfolgreich aktualisiert.');
|
||||
$this->redirect(route('admin.companies.index'), navigate: true);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use App\Enums\PressReleaseStatus;
|
|||
use App\Models\PressRelease;
|
||||
use App\Models\PressReleaseAttachment;
|
||||
use App\Services\PressRelease\PressReleaseAttachmentStorage;
|
||||
use App\Scopes\PortalScope;
|
||||
use Flux\Flux;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Volt\Component;
|
||||
|
|
@ -213,7 +214,7 @@ new class extends Component
|
|||
|
||||
private function getPressRelease(): PressRelease
|
||||
{
|
||||
return PressRelease::withoutGlobalScopes()
|
||||
return PressRelease::withoutGlobalScope(PortalScope::class)
|
||||
->findOrFail($this->pressReleaseId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Enums\PressReleaseStatus;
|
|||
use App\Models\PressRelease;
|
||||
use App\Models\PressReleaseImage;
|
||||
use App\Services\Image\ImageService;
|
||||
use App\Scopes\PortalScope;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Locked;
|
||||
|
|
@ -330,7 +331,7 @@ new class extends Component {
|
|||
|
||||
private function getPressRelease(): PressRelease
|
||||
{
|
||||
return PressRelease::withoutGlobalScopes()->findOrFail($this->pressReleaseId);
|
||||
return PressRelease::withoutGlobalScope(PortalScope::class)->findOrFail($this->pressReleaseId);
|
||||
}
|
||||
|
||||
private function canChangeImages(PressRelease $pressRelease): bool
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Models\PressRelease;
|
|||
use App\Models\Profile;
|
||||
use App\Models\User;
|
||||
use App\Services\Customer\CustomerCompanyContext;
|
||||
use App\Scopes\PortalScope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Livewire\Attributes\Layout;
|
||||
|
|
@ -22,7 +23,7 @@ new #[Layout('components.layouts.app'), Title('Mein Dashboard')] class extends C
|
|||
$selectedCompanyId = $context->selectedCompanyId($user);
|
||||
$selectedCompany = $selectedCompanyId === null ? null : $context->findFor($user, $selectedCompanyId);
|
||||
|
||||
$pressReleaseQuery = PressRelease::withoutGlobalScopes()
|
||||
$pressReleaseQuery = PressRelease::withoutGlobalScope(PortalScope::class)
|
||||
->where('user_id', $user->id)
|
||||
->when($selectedCompanyId !== null, fn($query) => $query->where('company_id', $selectedCompanyId));
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use App\Services\Customer\CustomerCompanyContext;
|
||||
use App\Scopes\PortalScope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -189,12 +190,12 @@ new #[Layout('components.layouts.app'), Title('Meine Firmen')] class extends Com
|
|||
$companyIdsQuery = $this->baseQuery($user)->select('companies.id');
|
||||
|
||||
$pressReleaseCount = (int) \App\Models\PressRelease::query()
|
||||
->withoutGlobalScopes()
|
||||
->withoutGlobalScope(PortalScope::class)
|
||||
->whereIn('company_id', $companyIdsQuery)
|
||||
->count();
|
||||
|
||||
$contactsCount = (int) \App\Models\Contact::query()
|
||||
->withoutGlobalScopes()
|
||||
->withoutGlobalScope(PortalScope::class)
|
||||
->whereIn('company_id', $companyIdsQuery)
|
||||
->count();
|
||||
|
||||
|
|
@ -338,10 +339,10 @@ new #[Layout('components.layouts.app'), Title('Meine Firmen')] class extends Com
|
|||
->limit(1),
|
||||
])
|
||||
->withCount([
|
||||
'contacts' => fn ($q) => $q->withoutGlobalScopes(),
|
||||
'pressReleases' => fn ($q) => $q->withoutGlobalScopes(),
|
||||
'contacts' => fn ($q) => $q->withoutGlobalScope(PortalScope::class),
|
||||
'pressReleases' => fn ($q) => $q->withoutGlobalScope(PortalScope::class),
|
||||
])
|
||||
->withMax(['pressReleases' => fn ($q) => $q->withoutGlobalScopes()], 'published_at');
|
||||
->withMax(['pressReleases' => fn ($q) => $q->withoutGlobalScope(PortalScope::class)], 'published_at');
|
||||
|
||||
$this->applySavedView($query, $user, $this->savedView);
|
||||
$this->applySharedFilters($query);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
use App\Models\Company;
|
||||
use App\Models\Contact;
|
||||
use App\Models\PressRelease;
|
||||
use App\Scopes\PortalScope;
|
||||
use App\Rules\NoPromotionalText;
|
||||
use App\Services\Company\CompanyProfileCheck;
|
||||
use App\Services\Conversion\ConversionRecorder;
|
||||
|
|
@ -144,22 +145,51 @@ new #[Layout('components.layouts.app'), Title('Firma')] class extends Component
|
|||
'disable_footer_code' => $this->companyDisableFooterCode,
|
||||
]);
|
||||
|
||||
$previousLogoPath = $company->logo_path;
|
||||
$previousLogoVariants = $company->logo_variants;
|
||||
$discardPreviousLogo = false;
|
||||
$stored = null;
|
||||
|
||||
if ($this->removeCompanyLogo) {
|
||||
$imageService->deleteCompanyLogo($company->logo_path, $company->logo_variants);
|
||||
$company->logo_path = null;
|
||||
$company->logo_variants = null;
|
||||
$discardPreviousLogo = true;
|
||||
}
|
||||
|
||||
if ($this->companyLogo) {
|
||||
$imageService->deleteCompanyLogo($company->logo_path, $company->logo_variants);
|
||||
// Erst die neue Datei speichern, dann die DB-Referenz wechseln, das
|
||||
// alte Logo erst danach löschen: Scheitert der Storage, bleiben
|
||||
// bisheriges Logo und Datensatz unangetastet (F23).
|
||||
try {
|
||||
$stored = $imageService->storeCompanyLogo($this->companyLogo, $company->portal?->value ?? 'presseecho', $company->id);
|
||||
} catch (\RuntimeException $exception) {
|
||||
report($exception);
|
||||
|
||||
$stored = $imageService->storeCompanyLogo($this->companyLogo, $company->portal?->value ?? 'presseecho', $company->id);
|
||||
throw ValidationException::withMessages([
|
||||
'companyLogo' => __('Das Logo konnte nicht gespeichert werden. Bitte versuchen Sie es erneut.'),
|
||||
]);
|
||||
}
|
||||
|
||||
$company->logo_path = $stored['path'];
|
||||
$company->logo_variants = $stored['variants'];
|
||||
$discardPreviousLogo = true;
|
||||
}
|
||||
|
||||
try {
|
||||
$company->save();
|
||||
} catch (\Throwable $exception) {
|
||||
// Ohne DB-Referenz wäre die neue Datei verwaist.
|
||||
if ($stored !== null) {
|
||||
$imageService->deleteCompanyLogo($stored['path'], $stored['variants']);
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
if ($discardPreviousLogo && $previousLogoPath !== null && $previousLogoPath !== $company->logo_path) {
|
||||
$imageService->deleteCompanyLogo($previousLogoPath, $previousLogoVariants);
|
||||
}
|
||||
|
||||
$company->save();
|
||||
$this->resetCompanyForm();
|
||||
|
||||
// Stufe 3 der Konversionsleiter: Newsroom gepflegt (einmal je Firma).
|
||||
|
|
@ -237,6 +267,10 @@ new #[Layout('components.layouts.app'), Title('Firma')] class extends Component
|
|||
session()->flash('contact-status', __('Pressekontakt wurde angelegt.'));
|
||||
}
|
||||
|
||||
// Die Kontakte liegen mit im gecachten Newsroom-Seitenpaket — die
|
||||
// Änderung soll nicht erst nach Ablauf des Seiten-Caches greifen.
|
||||
WebCaches::forgetPublicPages();
|
||||
|
||||
$this->resetContactForm();
|
||||
}
|
||||
|
||||
|
|
@ -247,6 +281,8 @@ new #[Layout('components.layouts.app'), Title('Firma')] class extends Component
|
|||
$contact = $this->contact($contactId);
|
||||
$contact->delete();
|
||||
|
||||
WebCaches::forgetPublicPages();
|
||||
|
||||
if ($this->editingContactId === $contactId) {
|
||||
$this->resetContactForm();
|
||||
}
|
||||
|
|
@ -270,7 +306,7 @@ new #[Layout('components.layouts.app'), Title('Firma')] class extends Component
|
|||
'canManageCompany' => $user->can('update', $company),
|
||||
'canManageContacts' => $user->can('update', $company),
|
||||
'countries' => (array) config('countries.items', []),
|
||||
'contacts' => Contact::withoutGlobalScopes()
|
||||
'contacts' => Contact::withoutGlobalScope(PortalScope::class)
|
||||
->where('company_id', $company->id)
|
||||
->withCount('pressReleases')
|
||||
->orderBy('last_name')
|
||||
|
|
@ -282,7 +318,7 @@ new #[Layout('components.layouts.app'), Title('Firma')] class extends Component
|
|||
// für ihn eingeliefert hat — die Policy erlaubt das Firmen-
|
||||
// mitgliedern ohnehin. Sortiert nach Veröffentlichung, Entwürfe
|
||||
// nach Anlage.
|
||||
'pressReleases' => $pressReleases = PressRelease::withoutGlobalScopes()
|
||||
'pressReleases' => $pressReleases = PressRelease::withoutGlobalScope(PortalScope::class)
|
||||
->where('company_id', $company->id)
|
||||
->orderByRaw('coalesce(published_at, created_at) desc')
|
||||
->limit(15)
|
||||
|
|
@ -303,7 +339,7 @@ new #[Layout('components.layouts.app'), Title('Firma')] class extends Component
|
|||
|
||||
private function contact(int $contactId): Contact
|
||||
{
|
||||
return Contact::withoutGlobalScopes()->where('company_id', $this->id)->findOrFail($contactId);
|
||||
return Contact::withoutGlobalScope(PortalScope::class)->where('company_id', $this->id)->findOrFail($contactId);
|
||||
}
|
||||
|
||||
private function resetCompanyForm(): void
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use App\Services\PressRelease\PressReleaseCoverImage;
|
|||
use App\Services\PressRelease\PressReleaseHtmlSanitizer;
|
||||
use App\Services\PressRelease\PressReleaseService;
|
||||
use App\Services\PressRelease\QuotaExceededException;
|
||||
use App\Scopes\PortalScope;
|
||||
use Flux\Flux;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Layout;
|
||||
|
|
@ -112,7 +113,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung bearbeiten')] cl
|
|||
$this->backlinkUrl = $pr->backlink_url ?? '';
|
||||
$this->boilerplateOverride = $pr->boilerplate_override ?? '';
|
||||
$this->useBoilerplateOverride = filled($pr->boilerplate_override);
|
||||
$this->contactId = $pr->contacts()->withoutGlobalScopes()->first()?->id
|
||||
$this->contactId = $pr->contacts()->withoutGlobalScope(PortalScope::class)->first()?->id
|
||||
?? $this->defaultContactIdFor((int) $pr->company_id);
|
||||
|
||||
if ($pr->scheduled_at) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use App\Services\PressRelease\BlacklistViolationException;
|
|||
use App\Services\PressRelease\BookingRequiredException;
|
||||
use App\Services\PressRelease\PressReleaseService;
|
||||
use App\Services\PressRelease\QuotaExceededException;
|
||||
use App\Scopes\PortalScope;
|
||||
use Flux\Flux;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Attributes\Layout;
|
||||
|
|
@ -174,7 +175,7 @@ new #[Layout('components.layouts.app'), Title('Meine Pressemitteilungen')] class
|
|||
|
||||
private function findMyPR(int $id): ?PressRelease
|
||||
{
|
||||
return PressRelease::withoutGlobalScopes()
|
||||
return PressRelease::withoutGlobalScope(PortalScope::class)
|
||||
->where('id', $id)
|
||||
->where('user_id', auth()->id())
|
||||
->first();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use App\Services\PressRelease\PressReleaseService;
|
|||
use App\Services\PressRelease\QuotaExceededException;
|
||||
use App\Services\PressRelease\VisibilityStats;
|
||||
use App\Services\SearchConsole\IndexStatusChecker;
|
||||
use App\Scopes\PortalScope;
|
||||
use Flux\Flux;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Locked;
|
||||
|
|
@ -907,7 +908,7 @@ new #[Layout('components.layouts.app'), Title('Pressemitteilung')] class extends
|
|||
->withCount(['pressReleases', 'contacts']),
|
||||
'category.translations',
|
||||
'contacts' => fn ($query) => $query
|
||||
->withoutGlobalScopes()
|
||||
->withoutGlobalScope(PortalScope::class)
|
||||
->orderBy('last_name')
|
||||
->orderBy('first_name')
|
||||
->select(['contacts.id', 'contacts.company_id', 'contacts.first_name', 'contacts.last_name', 'contacts.responsibility', 'contacts.email', 'contacts.phone']),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue