diff --git a/app/classes/host.php b/app/classes/host.php index 706db94..7b51c6e 100644 --- a/app/classes/host.php +++ b/app/classes/host.php @@ -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; diff --git a/app/pages/config.php b/app/pages/config.php index c4415fd..16cc0b8 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -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 = [