Chronologisches Protokoll der Systemereignisse als neue Admin-Seite (/admin/reports/activity) mit Filter nach Ereignistyp, Zeitraum und Suche. Erfasst ab jetzt fortlaufend: - Registrierungen inkl. Weg (Formular, Google, Magic-Link) - Anmeldungen inkl. Weg (Passwort, Google, Magic-Link, Impersonation) - PM-Statuswechsel mit Ergebnis/Begründung (zentral im Status-Log-Hook; KI-/Scheduler-Wechsel erscheinen als „System") - Zahlungseingänge (Rechnungsspiegelung) und Credit-Aufladungen - Formular-Eingänge: Kontakt, Rechtsanfrage, Widerruf, Kündigung, Newsletter-Anmeldung (Observer auf den Modellen) Schreiben ist Best-Effort über den ActivityLog-Service — ein fehlgeschlagener Verlaufseintrag bricht nie den fachlichen Ablauf. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Enums\ActivityType;
|
|
use App\Models\ActivityEvent;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* Schreibt Einträge in den Aktivitäts-Verlauf (Admin ▸ Reports ▸ Verlauf).
|
|
*
|
|
* Bewusst Best-Effort: Ein fehlgeschlagener Verlaufs-Eintrag darf nie den
|
|
* fachlichen Ablauf brechen (Login, Checkout, Webhook) — Fehler landen nur
|
|
* im Log.
|
|
*/
|
|
class ActivityLog
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $meta
|
|
*/
|
|
public function record(
|
|
ActivityType $type,
|
|
string $description,
|
|
?User $user = null,
|
|
?Model $subject = null,
|
|
array $meta = [],
|
|
?string $actorLabel = null,
|
|
): void {
|
|
try {
|
|
ActivityEvent::query()->create([
|
|
'type' => $type->value,
|
|
'occurred_at' => now(),
|
|
'user_id' => $user?->id,
|
|
'actor_label' => Str::limit($actorLabel ?? (string) $user?->name, 240),
|
|
'subject_type' => $subject?->getMorphClass(),
|
|
'subject_id' => $subject?->getKey(),
|
|
'description' => Str::limit($description, 480),
|
|
'meta' => $meta ?: null,
|
|
]);
|
|
} catch (\Throwable $exception) {
|
|
Log::warning('Aktivitäts-Verlauf konnte nicht geschrieben werden.', [
|
|
'type' => $type->value,
|
|
'error' => $exception->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
}
|