mirror of
https://gitlab.linphone.org/BC/public/flexisip-account-manager.git
synced 2026-01-17 10:08:05 +00:00
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:
parent
fe265a972d
commit
056dc8d159
3 changed files with 50 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
47
flexiapi/app/Console/Commands/ClearStatistics.php
Normal file
47
flexiapi/app/Console/Commands/ClearStatistics.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue