36 lines
1.0 KiB
PHP
36 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\CustomerIsoUpload;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class PurgeExpiredIsoUploadsCommand extends Command
|
|
{
|
|
protected $signature = 'hosting:purge-iso-uploads';
|
|
|
|
protected $description = 'Remove expired customer ISO uploads from Proxmox storage';
|
|
|
|
public function handle(): int
|
|
{
|
|
$expired = CustomerIsoUpload::query()
|
|
->where('expires_at', '<=', now())
|
|
->get();
|
|
|
|
foreach ($expired as $upload) {
|
|
try {
|
|
// Proxmox delete via storage API when upload service is wired
|
|
Log::info('ISO upload expired', ['volid' => $upload->volid, 'user_id' => $upload->user_id]);
|
|
} catch (\Throwable $e) {
|
|
Log::warning('ISO purge failed', ['id' => $upload->id, 'error' => $e->getMessage()]);
|
|
}
|
|
$upload->delete();
|
|
}
|
|
|
|
$this->info("Purged {$expired->count()} expired ISO upload(s).");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|