If a server has the "new" state and it is deleted, it will be permanent.

This commit is contained in:
2026-01-04 21:45:54 +01:00
parent f84eb6d149
commit fac4255c32

View File

@@ -48,6 +48,18 @@ class API_servers extends API
public function updateServer() public function updateServer()
{ {
# if the server_state that is posted is 'deleted' check if the current server state is 'new' if so, delete it perm.
if ($this->data['server_state'] == 'deleted') {
$stmt = $GLOBALS['pdo']->prepare("SELECT server_state FROM servers WHERE server_vm_id = ? AND server_state = 'new'");
$stmt->execute([$this->data['server_vm_id']]);
if ($stmt->fetch()) {
$deleteStmt = $GLOBALS['pdo']->prepare("DELETE FROM servers WHERE server_vm_id = ? AND server_state = 'new'");
$deleteStmt->execute([$this->data['server_vm_id']]);
return;
}
}
if (isset($this->data['company_uuid'])) { if (isset($this->data['company_uuid'])) {
if (strlen($this->data['company_uuid']) == 0) { if (strlen($this->data['company_uuid']) == 0) {
$this->data['company_uuid'] = NULL; $this->data['company_uuid'] = NULL;
@@ -84,7 +96,7 @@ class API_servers extends API
if (array_key_exists($field, $this->data)) { if (array_key_exists($field, $this->data)) {
$insertFields[] = $field; $insertFields[] = $field;
$insertValues[] = ":$field"; $insertValues[] = ":$field";
$bindParams[":$field"] = $this->data[$field]; // can be NULL $bindParams[":$field"] = $this->data[$field];
} }
} }
@@ -115,8 +127,6 @@ class API_servers extends API
if (!$stmt->execute($bindParams)) { if (!$stmt->execute($bindParams)) {
$this->apiOutput(400, ['error' => "Failed to insert server into database"]); $this->apiOutput(400, ['error' => "Failed to insert server into database"]);
} }
} }
private function validateLicenseData($server_vm_id, $server_licenses) private function validateLicenseData($server_vm_id, $server_licenses)
@@ -255,15 +265,4 @@ class API_servers extends API
$this->updateServer(); $this->updateServer();
} }
public function deleteServer()
{
$query = "DELETE FROM servers WHERE server_uuid = ?";
$stmt = $this->prepareStatement($query);
$stmt->bind_param('s', $this->data['server_uuid']);
$this->executeStatement($stmt);
$stmt->close();
$this->apiOutput(200, ['success' => 'Server removed']);
}
} }