schneespur/app/Console/Commands/PurgeExpiredJobs.php
Michael 2c63440ed8 Revert: move code back to project root from schneespur/ subdirectory
- Reverts the schneespur/ subdirectory restructure (b8e426b)
- Restores package.json and vite.config.js (needed for npm build, were
  removed in an earlier cleanup before the restructure)
- Updates public/build/ assets with current Vite output (new content hashes)
2026-05-17 18:24:26 +00:00

61 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use App\Models\Setting;
use App\Services\RetentionService;
use Illuminate\Console\Command;
class PurgeExpiredJobs extends Command
{
protected $signature = 'jobs:retention-delete
{--dry-run : Show what would be deleted without deleting}
{--limit=50 : Maximum jobs to delete per run}';
protected $description = 'Delete expired jobs after the configured retention period, preserving monthly aggregates.';
public function handle(RetentionService $retentionService): int
{
$isDryRun = $this->option('dry-run');
$limit = (int) $this->option('limit');
if (! $isDryRun && ! Setting::get('retention_auto_delete', false)) {
$this->info('Auto-Löschung ist deaktiviert.');
return 0;
}
$jobs = $retentionService->getExpiredJobs($limit);
if ($jobs->isEmpty()) {
$this->info('Keine abgelaufenen Einsätze.');
return 0;
}
if ($isDryRun) {
$this->info("Folgende Einsätze würden gelöscht ({$jobs->count()}):");
$this->table(
['ID', 'Kunde', 'Beendet am'],
$jobs->map(fn ($job) => [
$job->id,
$job->customer?->name ?? '',
$job->ended_at->format('d.m.Y H:i'),
]),
);
return 0;
}
$deleted = $retentionService->purge($limit);
$this->info("{$deleted} Einsätze gelöscht und in Monatsstatistik aggregiert.");
if ($deleted < $jobs->count()) {
$failed = $jobs->count() - $deleted;
$this->warn("{$failed} Einsätze konnten nicht gelöscht werden. Siehe Laravel-Log.");
}
return 0;
}
}