45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Enums\PressReleaseStatus;
|
||
use App\Models\PressRelease;
|
||
use Illuminate\Console\Command;
|
||
|
||
/**
|
||
* Archiviert Entwürfe, die seit mehr als X Tagen nicht bearbeitet wurden.
|
||
* Schützt vor "Zombie-Drafts" in der DB – optional, konfigurierbar.
|
||
*/
|
||
class PurgeExpiredPressReleaseDrafts extends Command
|
||
{
|
||
protected $signature = 'press-releases:purge-drafts
|
||
{--days=180 : Entwürfe älter als X Tage archivieren}
|
||
{--dry-run : Nur zählen, nichts ändern}';
|
||
|
||
protected $description = 'Archiviert inaktive PM-Entwürfe (älter als X Tage).';
|
||
|
||
public function handle(): int
|
||
{
|
||
$days = (int) $this->option('days');
|
||
$isDryRun = $this->option('dry-run');
|
||
$cutoff = now()->subDays($days);
|
||
|
||
$query = PressRelease::withoutGlobalScopes()
|
||
->where('status', PressReleaseStatus::Draft->value)
|
||
->where('updated_at', '<', $cutoff);
|
||
|
||
$count = $query->count();
|
||
|
||
if ($isDryRun) {
|
||
$this->warn("[DRY-RUN] {$count} Entwürfe würden archiviert. Kein tatsächlicher Vorgang.");
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
|
||
$query->update(['status' => PressReleaseStatus::Archived->value]);
|
||
|
||
$this->info("PM-Entwürfe archiviert: {$count} Einträge.");
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|