87 lines
2.4 KiB
PHP
87 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Hosting\Provisioning;
|
|
|
|
use App\Models\Customer;
|
|
use App\Models\User;
|
|
use App\Models\VmActivityLog;
|
|
use App\Services\Hosting\Proxmox\ProxmoxClient;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class DeprovisionService
|
|
{
|
|
public function __construct(
|
|
private readonly ProvisioningService $provisioning,
|
|
private readonly ProxmoxClient $proxmox,
|
|
private readonly VmidReservationService $vmidReservation,
|
|
) {}
|
|
|
|
/**
|
|
* Endgültige Löschung (WHMCS Terminate / Kunde nicht verlängert).
|
|
*/
|
|
public function terminatePermanently(Customer $customer, ?User $actor = null): void
|
|
{
|
|
Log::info('Permanent deprovision started', ['customer_id' => $customer->id]);
|
|
|
|
$this->deleteBackups($customer);
|
|
|
|
$customerId = $customer->id;
|
|
$vmid = $customer->vmid;
|
|
|
|
if ($actor) {
|
|
VmActivityLog::query()->create([
|
|
'customer_id' => $customerId,
|
|
'user_id' => $actor->id,
|
|
'action' => 'terminate.permanent',
|
|
'status' => 'success',
|
|
]);
|
|
}
|
|
|
|
$this->provisioning->deprovision($customer);
|
|
|
|
if ($vmid) {
|
|
$this->vmidReservation->scheduleRelease((int) $vmid, $customer);
|
|
}
|
|
|
|
$customer->devices()->delete();
|
|
$customer->delete();
|
|
}
|
|
|
|
/**
|
|
* VM entfernen, Kundeneintrag bleibt (Support-Fall).
|
|
*/
|
|
public function removeVmOnly(Customer $customer, ?User $actor = null): void
|
|
{
|
|
$this->provisioning->deprovision($customer);
|
|
|
|
if ($customer->vmid) {
|
|
$this->vmidReservation->scheduleRelease((int) $customer->vmid, $customer);
|
|
}
|
|
|
|
$customer->update([
|
|
'status' => 'failed',
|
|
'provisioning_step' => 'deprovisioned',
|
|
'vmid' => null,
|
|
]);
|
|
}
|
|
|
|
private function deleteBackups(Customer $customer): void
|
|
{
|
|
if (! $customer->vmid) {
|
|
return;
|
|
}
|
|
|
|
if (! config('hosting.backups.enabled', false)) {
|
|
Log::info('Backup deletion skipped (PBS not enabled)', ['vmid' => $customer->vmid]);
|
|
|
|
return;
|
|
}
|
|
|
|
// PBS-Integration folgt in Phase 2, wenn API-Rechte auf inett-PBS vorhanden
|
|
Log::warning('PBS backup purge pending implementation', [
|
|
'vmid' => $customer->vmid,
|
|
'storage' => config('hosting.backups.pbs_storage'),
|
|
]);
|
|
}
|
|
}
|