Init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?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).");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user