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>
69 lines
2.7 KiB
PHP
69 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Legacy;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Company;
|
|
use App\Rules\PlausibleEmailDomain;
|
|
use App\Scopes\PortalScope;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
/**
|
|
* Alt-Vertrag POST /service/users/me/companies/{id}/contacts:
|
|
* Felder unter contact[...], salutation_id 1/2 → mr/mrs (wie ContactImporter),
|
|
* nur eigene Firmen. Paritäts-Doku §1/§4 S1.
|
|
*/
|
|
class LegacyContactController extends Controller
|
|
{
|
|
use RespondsLikeLegacyApi;
|
|
|
|
public function store(Request $request, int $company): JsonResponse
|
|
{
|
|
abort_unless($request->user()->tokenCan('press-releases:write'), 403);
|
|
|
|
$company = Company::withoutGlobalScope(PortalScope::class)
|
|
->whereKey($company)
|
|
->accessibleBy($request->user())
|
|
->first();
|
|
|
|
if (! $company) {
|
|
return $this->legacyError(403, ['You may only access companies which are related to your user-account']);
|
|
}
|
|
|
|
try {
|
|
$validated = $request->validate([
|
|
'contact' => ['required', 'array'],
|
|
'contact.salutation_id' => ['nullable', 'integer'],
|
|
'contact.title' => ['nullable', 'string', 'max:100'],
|
|
'contact.first_name' => ['required', 'string', 'max:255'],
|
|
'contact.last_name' => ['required', 'string', 'max:255'],
|
|
'contact.responsibility' => ['nullable', 'string', 'max:255'],
|
|
'contact.phone' => ['nullable', 'string', 'max:100'],
|
|
'contact.fax' => ['nullable', 'string', 'max:100'],
|
|
'contact.email' => ['nullable', 'email', 'max:255', new PlausibleEmailDomain],
|
|
])['contact'];
|
|
} catch (ValidationException $exception) {
|
|
return $this->legacyValidationError($exception);
|
|
}
|
|
|
|
$contact = $company->contacts()->create([
|
|
'portal' => $company->portal?->value,
|
|
'salutation_key' => match ((int) ($validated['salutation_id'] ?? 0)) {
|
|
1 => 'mr',
|
|
2 => 'mrs',
|
|
default => null,
|
|
},
|
|
'title' => $validated['title'] ?? null,
|
|
'first_name' => $validated['first_name'],
|
|
'last_name' => $validated['last_name'],
|
|
'responsibility' => $validated['responsibility'] ?? null,
|
|
'phone' => $validated['phone'] ?? null,
|
|
'fax' => $validated['fax'] ?? null,
|
|
'email' => $validated['email'] ?? null,
|
|
]);
|
|
|
|
return $this->legacyCreated(url("/service/users/me/companies/{$company->id}/contacts/{$contact->id}"));
|
|
}
|
|
}
|