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
62202a4b13
commit
f235156de9
73 changed files with 1746 additions and 170 deletions
|
|
@ -29,7 +29,7 @@ class Contact extends Model
|
|||
*/
|
||||
public function scopeForCompany(Builder $query, int $companyId): Builder
|
||||
{
|
||||
return $query->withoutGlobalScopes()
|
||||
return $query->withoutGlobalScope(PortalScope::class)
|
||||
->where('company_id', $companyId)
|
||||
->orderBy('last_name')
|
||||
->orderBy('first_name');
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
* Schreibt für jede Bewertung einen unveränderlichen Eintrag inkl.
|
||||
* Anbieter, Modell, Ergebnis, Begründung und Roh-Antwort – für
|
||||
* Nachvollziehbarkeit und Nachweispflicht (DSGVO).
|
||||
*
|
||||
* `content_hash` bindet das Ergebnis an die geprüfte Inhaltsversion
|
||||
* (Audit F07); `discarded_at` markiert Ergebnisse, die beim Eintreffen nicht
|
||||
* mehr zum aktuellen Inhalt passten und deshalb nicht übernommen wurden.
|
||||
*/
|
||||
class KiAudit extends Model
|
||||
{
|
||||
|
|
@ -33,6 +37,8 @@ class KiAudit extends Model
|
|||
'result',
|
||||
'reason',
|
||||
'raw_response',
|
||||
'content_hash',
|
||||
'discarded_at',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
|
|
@ -41,6 +47,7 @@ class KiAudit extends Model
|
|||
return [
|
||||
'raw_response' => 'array',
|
||||
'created_at' => 'datetime',
|
||||
'discarded_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ class PressRelease extends Model
|
|||
public function pressContactEmail(): ?string
|
||||
{
|
||||
$contactEmail = $this->contacts()
|
||||
->withoutGlobalScopes()
|
||||
->withoutGlobalScope(PortalScope::class)
|
||||
->whereNotNull('email')
|
||||
->where('email', '!=', '')
|
||||
->value('email');
|
||||
|
|
@ -204,7 +204,7 @@ class PressRelease extends Model
|
|||
// ohne PM-Kontakt zählt der Firmen-Pressekontakt als Kanal.
|
||||
if ($this->company_id) {
|
||||
$companyContactEmail = Contact::query()
|
||||
->withoutGlobalScopes()
|
||||
->withoutGlobalScope(PortalScope::class)
|
||||
->where('company_id', $this->company_id)
|
||||
->whereNotNull('email')
|
||||
->where('email', '!=', '')
|
||||
|
|
@ -216,7 +216,7 @@ class PressRelease extends Model
|
|||
}
|
||||
}
|
||||
|
||||
$companyEmail = $this->company()->withoutGlobalScopes()->value('email');
|
||||
$companyEmail = $this->company()->withoutGlobalScope(PortalScope::class)->value('email');
|
||||
|
||||
return is_string($companyEmail) && $companyEmail !== '' ? $companyEmail : null;
|
||||
}
|
||||
|
|
@ -427,7 +427,7 @@ class PressRelease extends Model
|
|||
*/
|
||||
public function canonical(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PressRelease::class, 'canonical_press_release_id')->withoutGlobalScopes();
|
||||
return $this->belongsTo(PressRelease::class, 'canonical_press_release_id')->withoutGlobalScope(PortalScope::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -437,7 +437,7 @@ class PressRelease extends Model
|
|||
*/
|
||||
public function duplicates(): HasMany
|
||||
{
|
||||
return $this->hasMany(PressRelease::class, 'canonical_press_release_id')->withoutGlobalScopes();
|
||||
return $this->hasMany(PressRelease::class, 'canonical_press_release_id')->withoutGlobalScope(PortalScope::class);
|
||||
}
|
||||
|
||||
public function isCanonicalDuplicate(): bool
|
||||
|
|
@ -727,7 +727,7 @@ class PressRelease extends Model
|
|||
// EXISTS). Company::accessibleBy() (Owner ODER Pivot-Mitglied) ist die
|
||||
// Single Source of Truth; als Eloquent-Subquery werden die Company-
|
||||
// Global-Scopes (PortalScope, SoftDeletes) mitkompiliert.
|
||||
return $query->withoutGlobalScopes()
|
||||
return $query->withoutGlobalScope(PortalScope::class)
|
||||
->where(function (Builder $q) use ($user): void {
|
||||
$q->where('user_id', $user->id)
|
||||
->orWhereIn('company_id', Company::accessibleBy($user)->select('companies.id'));
|
||||
|
|
@ -752,7 +752,7 @@ class PressRelease extends Model
|
|||
public static function accessibleStatusCountsFor(User $user, ?Closure $constrain = null): array
|
||||
{
|
||||
$branch = function (Closure $where) use ($constrain): Builder {
|
||||
$query = static::query()->withoutGlobalScopes()->select('id', 'status');
|
||||
$query = static::query()->withoutGlobalScope(PortalScope::class)->select('id', 'status');
|
||||
$where($query);
|
||||
|
||||
if ($constrain !== null) {
|
||||
|
|
@ -806,7 +806,7 @@ class PressRelease extends Model
|
|||
$sortDir = $sortDir === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
$branch = function (Closure $where) use ($constrain): Builder {
|
||||
$query = static::query()->withoutGlobalScopes()
|
||||
$query = static::query()->withoutGlobalScope(PortalScope::class)
|
||||
->select('id', 'created_at', 'title', 'status');
|
||||
$where($query);
|
||||
|
||||
|
|
@ -834,7 +834,7 @@ class PressRelease extends Model
|
|||
->forPage($page, $perPage)
|
||||
->pluck('id');
|
||||
|
||||
$models = static::query()->withoutGlobalScopes()
|
||||
$models = static::query()->withoutGlobalScope(PortalScope::class)
|
||||
->whereKey($pageIds)
|
||||
// Kategorie fürs Listen-Rendering (localizedCategoryName, 13.07.);
|
||||
// Bilder fürs Listen-Thumbnail — Titelbild zuerst (is_preview,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Enums\EmailNotificationType;
|
|||
use App\Enums\Portal;
|
||||
use App\Enums\RegistrationType;
|
||||
use App\Enums\Tier;
|
||||
use App\Support\EmailQuery;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
|
@ -52,6 +53,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
'oauth_provider',
|
||||
'oauth_provider_id',
|
||||
'press_release_quota_used_this_month',
|
||||
'press_release_quota_period',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -171,10 +173,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
* Truth für die E-Mail-basierte Auflösung (Magic-Link, Social-Login,
|
||||
* Kontakt-Zugang).
|
||||
*
|
||||
* Bewusst weiterhin über `LOWER(email)`: E-Mails werden nicht normalisiert
|
||||
* gespeichert, daher ist der case-insensitive Vergleich Pflicht. Ein
|
||||
* indexfreundlicher Direktvergleich setzt eine Normalisierung beim
|
||||
* Schreiben voraus (separater, datenseitiger Schritt).
|
||||
* Case-insensitiv über den Unique-Index (siehe EmailQuery): die Kollation
|
||||
* der Spalte vergleicht ohne Groß-/Kleinschreibung, `LOWER()` würde den
|
||||
* Index nur ausschalten (Audit F22).
|
||||
*/
|
||||
public static function findByEmail(string $email): ?self
|
||||
{
|
||||
|
|
@ -184,7 +185,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
return null;
|
||||
}
|
||||
|
||||
return static::query()->whereRaw('LOWER(email) = ?', [$email])->first();
|
||||
return EmailQuery::whereEmail(static::query(), $email)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -270,12 +271,34 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
|
||||
$planRemaining = max(
|
||||
0,
|
||||
($this->currentPlan()?->press_release_quota ?? 0) - (int) $this->press_release_quota_used_this_month,
|
||||
($this->currentPlan()?->press_release_quota ?? 0) - $this->pressReleaseQuotaUsedThisMonth(),
|
||||
);
|
||||
|
||||
return $planRemaining + $this->openSinglePurchaseCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Kalendermonat, für den der Verbrauchszähler gilt (YYYY-MM).
|
||||
*/
|
||||
public static function currentQuotaPeriod(): string
|
||||
{
|
||||
return now()->format('Y-m');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verbrauch des LAUFENDEN Monats. Steht der Zähler auf einem früheren
|
||||
* Monat (oder ohne Monat aus der Zeit vor der Periodenbindung), zählt er
|
||||
* null – unabhängig davon, ob der Reset-Cron gelaufen ist (Audit F18).
|
||||
*/
|
||||
public function pressReleaseQuotaUsedThisMonth(): int
|
||||
{
|
||||
if ($this->press_release_quota_period !== null && $this->press_release_quota_period !== self::currentQuotaPeriod()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) $this->press_release_quota_used_this_month;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bezahlte, noch nicht eingelöste Einmalkäufe (Einzel-/Extra-PM), die zur
|
||||
* Einreichung berechtigen. Per-Request memoisiert, weil das Status-Widget
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue