From a0266741d7b039ba20d2b79e57c9d1c10ae9dfc3 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Wed, 9 Oct 2019 10:32:49 +0200 Subject: [PATCH] fix(remote-server): fix simple remote server creation (#7936) Refs: BAM-748 --- .../PollerConfigurationRequestBridge.php | 5 +- .../configGenerate/xml/moveFiles.php | 73 +++++++++++-------- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/CentreonRemote/Domain/Service/ConfigurationWizard/PollerConfigurationRequestBridge.php b/src/CentreonRemote/Domain/Service/ConfigurationWizard/PollerConfigurationRequestBridge.php index 7a19edd21c9..345afedb0bf 100644 --- a/src/CentreonRemote/Domain/Service/ConfigurationWizard/PollerConfigurationRequestBridge.php +++ b/src/CentreonRemote/Domain/Service/ConfigurationWizard/PollerConfigurationRequestBridge.php @@ -71,8 +71,9 @@ public function collectDataFromAdditionalRemoteServers(): void { $isRemoteServerWizard = (new ServerWizardIdentity)->requestConfigurationIsRemote(); - if (!$isRemoteServerWizard) { - $linkedRemotes= isset($_POST['linked_remote_slaves']) ? $_POST['linked_remote_slaves'] : []; + $linkedRemotes = []; + if (!$isRemoteServerWizard && isset($_POST['linked_remote_slaves'])) { + $linkedRemotes = $_POST['linked_remote_slaves']; } $this->additionalRemotes = $this->getPollersToLink($linkedRemotes); // set and instantiate linked pollers diff --git a/www/include/configuration/configGenerate/xml/moveFiles.php b/www/include/configuration/configGenerate/xml/moveFiles.php index a11be3977d9..9ff94e4512a 100644 --- a/www/include/configuration/configGenerate/xml/moveFiles.php +++ b/www/include/configuration/configGenerate/xml/moveFiles.php @@ -73,43 +73,54 @@ global $generatePhpErrors; global $dependencyInjector; -$generatePhpErrors = array(); +$generatePhpErrors = []; $pollers = explode(',', $_POST['poller']); // Add task to export files if there is a remote -$idBindString = str_repeat('?,', count($pollers)); -$idBindString = rtrim($idBindString, ','); -$queryRemotes =<<query($queryRemotes, array_merge($pollers, $pollers)); -$remotesResults = $remotesStatement->fetchAll(PDO::FETCH_ASSOC); +$pollerParams = []; +foreach ($pollers as $pollerId) { + $pollerParams[':poller_' . $pollerId] = $pollerId; +} +$statementRemotes = $pearDB->prepare(' + SELECT ns.id, ns.ns_ip_address AS ip, + rs.centreon_path, rs.http_method, rs.http_port, rs.no_check_certificate, rs.no_proxy + FROM nagios_server AS ns + JOIN remote_servers AS rs ON rs.ip = ns.ns_ip_address + WHERE ns.id IN (' . implode(',', array_keys($pollerParams)) . ') + UNION + SELECT ns1.id, ns1.ns_ip_address AS ip, + rs.centreon_path, rs.http_method, rs.http_port, rs.no_check_certificate, rs.no_proxy + FROM nagios_server AS ns1 + JOIN remote_servers AS rs ON rs.ip = ns1.ns_ip_address + JOIN nagios_server AS ns2 ON ns1.id = ns2.remote_id + WHERE ns2.id IN (' . implode(',', array_keys($pollerParams)) . ') + UNION + SELECT ns1.id, ns1.ns_ip_address AS ip, + rs.centreon_path, rs.http_method, rs.http_port, rs.no_check_certificate, rs.no_proxy + FROM nagios_server AS ns1 + JOIN remote_servers AS rs ON rs.ip = ns1.ns_ip_address + JOIN rs_poller_relation AS rspr ON rspr.remote_server_id = ns1.id + WHERE rspr.poller_server_id IN (' . implode(',', array_keys($pollerParams)) . ') +'); +foreach ($pollerParams as $key => $value) { + $statementRemotes->bindValue($key, $value, \PDO::PARAM_INT); +} +$statementRemotes->execute(); +$remotesResults = $statementRemotes->fetchAll(PDO::FETCH_ASSOC); if (!empty($remotesResults)) { foreach ($remotesResults as $remote) { - $queryLinked =<<query($queryLinked); + $linkedStatement = $pearDB->prepare(' + SELECT id + FROM nagios_server + WHERE remote_id = :remote_id + UNION + SELECT poller_server_id AS id + FROM rs_poller_relation + WHERE remote_server_id = :remote_id + '); + $linkedStatement->bindValue(':remote_id', $remote['id'], \PDO::PARAM_INT); + $linkedStatement->execute(); $linkedResults = $linkedStatement->fetchAll(PDO::FETCH_ASSOC); $exportParams = [