47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Console\Commands;
|
||
|
|
|
||
|
|
use App\Jobs\CleanOldActivities as CleanOldActivitiesJob;
|
||
|
|
use Illuminate\Console\Command;
|
||
|
|
|
||
|
|
class CleanOldActivities extends Command
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* The name and signature of the console command.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected $signature = 'uwil:activity-logs:clean {--force : Delete all activity logs regardless of date.}';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The console command description.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected $description = 'Clean all logs older than one year. Use --force to delete all logs.';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the console command.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle(): void
|
||
|
|
{
|
||
|
|
$messageTitle = "<comment>activity logs</comment>";
|
||
|
|
$this->components->info("Cleaning {$messageTitle}...");
|
||
|
|
|
||
|
|
$force = $this->option('force');
|
||
|
|
|
||
|
|
if ($force && !$this->confirm('Are you sure you want to delete all activity logs ? This cannot be undone.')) {
|
||
|
|
$this->components->error("Clean of {$messageTitle} aborted.");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
(new CleanOldActivitiesJob(force: $force))->handle();
|
||
|
|
|
||
|
|
$messageContent = $force ? "All {$messageTitle} deleted" : "Old {$messageTitle} cleaned";
|
||
|
|
$this->components->success($messageContent);
|
||
|
|
}
|
||
|
|
}
|