Files
core/src/Command/ExportCleanupCommand.php
T
2026-07-01 18:35:39 +03:00

42 lines
1.0 KiB
PHP

<?php
namespace Modules\Core\Command;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class ExportCleanupCommand extends Command
{
protected $signature = "boboko:export:cleanup {--keep=0 : Number of most recent exports to keep}";
protected $description = "Delete export archives";
public function handle(): void
{
$exportDir = Storage::disk("local")->path("exports");
$files = glob($exportDir . "/export_*.zip");
if (empty($files)) {
$this->info("No export files found.");
return;
}
rsort($files);
$keep = max(0, (int) $this->option("keep"));
$toDelete = array_slice($files, $keep);
if (empty($toDelete)) {
$this->info("Nothing to delete.");
return;
}
foreach ($toDelete as $file) {
unlink($file);
$this->line("Deleted: " . basename($file));
}
$this->info("Deleted " . count($toDelete) . " export(s).");
}
}