Beide Tabellen hatten keine Frist; activity_events trägt Namen und Adressen im Klartext, api_usage_logs IP und User-Agent. MassPrunable, täglich 04:05 über model:prune, Fristen in config/monitoring.php (Roadmap 4.2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\ActivityType;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\MassPrunable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
/**
|
|
* Ein Eintrag im Aktivitäts-Verlauf (Admin ▸ Reports ▸ Verlauf).
|
|
* Wird ausschließlich über den ActivityLog-Service geschrieben.
|
|
*/
|
|
class ActivityEvent extends Model
|
|
{
|
|
use MassPrunable;
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = [
|
|
'type',
|
|
'occurred_at',
|
|
'user_id',
|
|
'actor_label',
|
|
'subject_type',
|
|
'subject_id',
|
|
'description',
|
|
'meta',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'type' => ActivityType::class,
|
|
'occurred_at' => 'datetime',
|
|
'meta' => 'array',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* @return MorphTo<Model, $this>
|
|
*/
|
|
public function subject(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
/**
|
|
* Einträge nach der Löschfrist (config monitoring.retention, 395 Tage).
|
|
*
|
|
* @return Builder<static>
|
|
*/
|
|
public function prunable(): Builder
|
|
{
|
|
return static::query()->where('occurred_at', '<', now()->subDays((int) config('monitoring.retention.activity_events_days')));
|
|
}
|
|
}
|