27 lines
724 B
PHP
27 lines
724 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\AcademyEvent;
|
|
use Illuminate\Console\Command;
|
|
|
|
final class AcademyAnalyticsPruneEventsCommand extends Command
|
|
{
|
|
protected $signature = 'academy:analytics-prune-events {--days=180}';
|
|
|
|
protected $description = 'Delete old raw Academy analytics events while keeping daily rollups';
|
|
|
|
public function handle(): int
|
|
{
|
|
$days = max(1, (int) $this->option('days'));
|
|
$deleted = AcademyEvent::query()
|
|
->where('occurred_at', '<', now()->subDays($days)->startOfDay())
|
|
->delete();
|
|
|
|
$this->info(sprintf('Pruned %d Academy analytics event(s).', $deleted));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
} |