Fix FLEXIAPI-406 Add an artisan console script to clear statistics after n days

Add it in the daily crons, with 30 days delay
This commit is contained in:
Timothée Jaussoin 2025-11-18 15:48:22 +01:00
parent da63835902
commit 396f420aac
3 changed files with 50 additions and 1 deletions

View file

@ -6,3 +6,4 @@ sudo -su www-data && php artisan accounts:clear-api-keys 60
sudo -su www-data && php artisan accounts:clear-accounts-tombstones 7 --apply
sudo -su www-data && php artisan accounts:clear-unconfirmed 30 --apply
sudo -su www-data && php artisan spaces:expiration-emails
sudo -su www-data && php artisan app:clear-statistics 30 --apply

View file

@ -5,4 +5,5 @@ php artisan digest:clear-nonces 60
php artisan accounts:clear-api-keys 60
php artisan accounts:clear-accounts-tombstones 7 --apply
php artisan accounts:clear-unconfirmed 30 --apply
php artisan spaces:expiration-emails
php artisan spaces:expiration-emails
php artisan app:clear-statistics 30 --apply

View file

@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands;
use App\StatisticsCall;
use App\StatisticsMessage;
use Carbon\Carbon;
use Illuminate\Console\Command;
class ClearStatistics extends Command
{
protected $signature = 'app:clear-statistics {days} {--apply}';
protected $description = 'Command description';
public function handle()
{
$calls = StatisticsCall::where(
'created_at',
'<',
Carbon::now()->subDays($this->argument('days'))->toDateTimeString()
);
$messages = StatisticsMessage::where(
'created_at',
'<',
Carbon::now()->subDays($this->argument('days'))->toDateTimeString()
);
$callsCount = $calls->count();
$messagesCount = $messages->count();
if ($this->option('apply')) {
$this->info($callsCount . ' calls statistics in deletion…');
$calls->delete();
$this->info($callsCount . ' calls statistics deleted');
$this->info($messagesCount . ' messages statistics in deletion…');
$messages->delete();
$this->info($messagesCount . ' messages statistics deleted');
return Command::SUCCESS;
}
$this->info($callsCount . ' calls statistics to delete');
$this->info($messagesCount . ' messages statistics to delete');
return Command::SUCCESS;
}
}