flexisip-account-manager/flexiapi/app/Console/Commands/ClearOldAccountsTombstones.php
Timothée Jaussoin 63a690d6b2 Save the removed accounts in a "tombstones" table to prevent them to be recreated
Add a Console commande to clear the old tombstones
Update the documentation
2021-09-07 15:52:21 +02:00

33 lines
870 B
PHP

<?php
namespace App\Console\Commands;
use App\Account;
use App\AccountTombstone;
use Carbon\Carbon;
use Illuminate\Console\Command;
class ClearOldAccountsTombstones extends Command
{
protected $signature = 'accounts:clear-accounts-tombstones {days} {--apply}';
protected $description = 'Clear deleted accounts tombstones after n days';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$tombstones = AccountTombstone::where('created_at', '<',
Carbon::now()->subDays($this->argument('days'))->toDateTimeString()
);
if ($this->option('apply')) {
$this->info($tombstones->count() . ' tombstones deleted');
$tombstones->delete();
} else {
$this->info($tombstones->count() . ' tombstones to delete');
}
}
}