From f035b720cd8a1b785748e80956aee217c4734c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Mon, 24 Nov 2025 10:47:35 +0000 Subject: [PATCH] Fix FLEXIAPI-406 Add an artisan console script to clear statistics after n days --- cron/flexiapi.debian | 1 + cron/flexiapi.redhat | 3 +- .../app/Console/Commands/ClearStatistics.php | 47 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 flexiapi/app/Console/Commands/ClearStatistics.php diff --git a/cron/flexiapi.debian b/cron/flexiapi.debian index 73a4447..cb26719 100644 --- a/cron/flexiapi.debian +++ b/cron/flexiapi.debian @@ -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 diff --git a/cron/flexiapi.redhat b/cron/flexiapi.redhat index af3c529..f8d5fc4 100644 --- a/cron/flexiapi.redhat +++ b/cron/flexiapi.redhat @@ -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 \ No newline at end of file +php artisan spaces:expiration-emails +php artisan app:clear-statistics 30 --apply \ No newline at end of file diff --git a/flexiapi/app/Console/Commands/ClearStatistics.php b/flexiapi/app/Console/Commands/ClearStatistics.php new file mode 100644 index 0000000..7ab942d --- /dev/null +++ b/flexiapi/app/Console/Commands/ClearStatistics.php @@ -0,0 +1,47 @@ +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; + } +}