Fixes host editing

main
Yasen Pramatarov 2024-10-31 11:25:37 +02:00
parent 5d715e4aac
commit e084a04305
2 changed files with 24 additions and 15 deletions

View File

@ -65,26 +65,20 @@ class Host {
}
// edit an existing host
public function editAgent($platform_id, $updatedAgent) {
public function editHost($platform_id, $updatedHost) {
try {
$sql = 'UPDATE jilo_agents SET
agent_type_id = :agent_type_id,
url = :url,
secret_key = :secret_key,
check_period = :check_period
$sql = 'UPDATE hosts SET
address = :address,
port = :port,
name = :name,
WHERE
id = :agent_id
AND
platform_id = :platform_id';
id = :id';
$query = $this->db->prepare($sql);
$query->execute([
':agent_type_id' => $updatedAgent['agent_type_id'],
':url' => $updatedAgent['url'],
':secret_key' => $updatedAgent['secret_key'],
':check_period' => $updatedAgent['check_period'],
':agent_id' => $updatedAgent['id'],
':platform_id' => $platform_id,
':address' => $updatedHost['address'],
':port' => $updatedHost['port'],
':name' => $updatedHost['name'],
]);
return true;

View File

@ -82,6 +82,21 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$platform = $_POST['platform'];
$platformObject->deletePlatform($platform);
// an update to an existing host
} elseif (isset($_POST['host'])) {
$updatedHost = [
'id' => $host,
'address' => $address,
'port' => $port,
'name' => $name,
];
$result = $hostObject->editHost($platform_id, $updatedHost);
if ($result === true) {
$_SESSION['notice'] = "Host id \"{$_REQUEST['host']}\" edited.";
} else {
$_SESSION['error'] = "Editing the host failed. Error: $result";
}
// an update to an existing agent
} elseif (isset($_POST['agent'])) {
$updatedAgent = [