2026-06-02 20:54:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
|
|
use App\Models\Entry;
|
2026-06-16 16:21:43 +02:00
|
|
|
use App\Models\News;
|
2026-06-02 20:54:40 +02:00
|
|
|
use Illuminate\Console\Attributes\Description;
|
|
|
|
|
use Illuminate\Console\Attributes\Signature;
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
|
|
#[Signature('entries:purge-rejected {--days=7}')]
|
|
|
|
|
#[Description('Soft Delete rejected entries older than X days')]
|
|
|
|
|
class DeleteRejectedEntries extends Command
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Execute the console command.
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
$days = (int) $this->option('days');
|
|
|
|
|
$count = Entry::where('state', 'rejected')
|
|
|
|
|
->where('rejected_at', '<', now()->subDays($days))
|
|
|
|
|
->delete();
|
2026-06-16 16:21:43 +02:00
|
|
|
$count += News::where('state', 'rejected')
|
|
|
|
|
->where('rejected_at', '<', now()->subDays($days))
|
|
|
|
|
->delete();
|
2026-06-02 20:54:40 +02:00
|
|
|
|
2026-06-16 16:21:43 +02:00
|
|
|
$this->info("Deleted {$count} entries/news");
|
|
|
|
|
return self::SUCCESS;
|
2026-06-02 20:54:40 +02:00
|
|
|
}
|
|
|
|
|
}
|