diff --git a/www/class/centreonHost.class.php b/www/class/centreonHost.class.php index 7618039f5c8524d96444ba09e8441b55fdc79b4c..32ccf74f60ac5898f73ab1f2ab036462c1b36e77 100644 --- a/www/class/centreonHost.class.php +++ b/www/class/centreonHost.class.php @@ -484,11 +484,27 @@ class CentreonHost * @param int $hostId * @param array $macroInput * @param array $macroValue + * @param array $macroPassword + * @param bool $isMassiveChange * @return void */ - public function insertMacro($hostId, $macroInput = array(), $macroValue = array(), $macroPassword = array()) { - $this->db->query("DELETE FROM on_demand_macro_host + public function insertMacro($hostId, $macroInput = array(), $macroValue = array(), $macroPassword = array(), $isMassiveChange = false) { + if (false === $isMassiveChange) { + $this->db->query("DELETE FROM on_demand_macro_host WHERE host_host_id = ".$this->db->escape($hostId)); + } else { + $macroList = ""; + foreach ($macroInput as $v) { + $macroList .= "'\$_HOST".strtoupper($this->db->escape($v))."\$',"; + } + if ($macroList) { + $macroList = rtrim($macroList, ","); + $this->db->query("DELETE FROM on_demand_macro_host + WHERE host_host_id = ".$this->db->escape($hostId)." + AND host_macro_name IN ({$macroList})" + ); + } + } $macros = $macroInput; $macrovalues = $macroValue; @@ -497,7 +513,7 @@ class CentreonHost if ($value != "" && !isset($stored[strtolower($value)])) { $this->db->query("INSERT INTO on_demand_macro_host (`host_macro_name`, `host_macro_value`, `is_password`, `host_host_id`) - VALUES ('\$_HOST". strtoupper($value) ."\$', '". $this->db->escape($macrovalues[$key]) ."', ".(isset($macroPassword[$key]) ? 1 : 'NULL') .", ". $hostId .")"); + VALUES ('\$_HOST". strtoupper($this->db->escape($value)) ."\$', '". $this->db->escape($macrovalues[$key]) ."', ".(isset($macroPassword[$key]) ? 1 : 'NULL') .", ". $this->db->escape($hostId) .")"); $stored[strtolower($value)] = true; } } @@ -639,4 +655,4 @@ class CentreonHost } -?> \ No newline at end of file +?> diff --git a/www/class/centreonService.class.php b/www/class/centreonService.class.php index bfb240ffb0fdd4194fae6776a9d01141f7cf1fa5..dd09c361da4ea17347681cd1e0f06111ed652b14 100644 --- a/www/class/centreonService.class.php +++ b/www/class/centreonService.class.php @@ -303,11 +303,28 @@ * @param int $serviceId * @param array $macroInput * @param array $macroValue + * @param array $macroPassword + * @param bool $isMassiveChange * @return void */ - public function insertMacro($serviceId, $macroInput = array(), $macroValue = array(), $macroPassword = array()) { - $this->db->query("DELETE FROM on_demand_macro_service - WHERE svc_svc_id = ".$this->db->escape($serviceId)); + public function insertMacro($serviceId, $macroInput = array(), $macroValue = array(), $macroPassword = array(), $isMassiveChange = false) { + if (false === $isMassiveChange) { + $this->db->query("DELETE FROM on_demand_macro_service + WHERE svc_svc_id = ".$this->db->escape($serviceId) + ); + } else { + $macroList = ""; + foreach ($macroInput as $v) { + $macroList .= "'\$_SERVICE".strtoupper($this->db->escape($v))."\$',"; + } + if ($macroList) { + $macroList = rtrim($macroList, ","); + $this->db->query("DELETE FROM on_demand_macro_service + WHERE svc_svc_id = ".$this->db->escape($serviceId)." + AND svc_macro_name IN ({$macroList})" + ); + } + } $macros = $macroInput; $macrovalues = $macroValue; @@ -316,7 +333,7 @@ if ($value != "" && !isset($stored[strtolower($value)])) { $this->db->query("INSERT INTO on_demand_macro_service (`svc_macro_name`, `svc_macro_value`, `is_password`, `svc_svc_id`) - VALUES ('\$_SERVICE".strtoupper($value)."\$', '".$this->db->escape($macrovalues[$key])."', ".(isset($macroPassword[$key]) ? 1 : 'NULL').", ".$serviceId .")"); + VALUES ('\$_SERVICE".strtoupper($this->db->escape($value))."\$', '".$this->db->escape($macrovalues[$key])."', ".(isset($macroPassword[$key]) ? 1 : 'NULL').", ".$this->db->escape($serviceId) .")"); $stored[strtolower($value)] = true; } } diff --git a/www/include/configuration/configObject/host/DB-Func.php b/www/include/configuration/configObject/host/DB-Func.php index 5e2921f78dc21a0ec40a2a5cb0ded454b89ba0af..3474435242d3fb5f3916af0c9fe41d65236270fb 100644 --- a/www/include/configuration/configObject/host/DB-Func.php +++ b/www/include/configuration/configObject/host/DB-Func.php @@ -1502,7 +1502,8 @@ function updateHost_MC($host_id = null) { $host_id, $_REQUEST['macroInput'], $_REQUEST['macroValue'], - $_REQUEST['macroPassword'] + $_REQUEST['macroPassword'], + true ); } diff --git a/www/include/configuration/configObject/service/DB-Func.php b/www/include/configuration/configObject/service/DB-Func.php index bea7585602c98434fe0da004c301d9bd370ec40a..07ab57c7065f56ff809cbac92a64ea21e34042ed 100644 --- a/www/include/configuration/configObject/service/DB-Func.php +++ b/www/include/configuration/configObject/service/DB-Func.php @@ -1479,19 +1479,18 @@ function divideHostsToHost($service_id) { /* * Update on demand macros */ - if (isset($_REQUEST['macroInput']) && - isset($_REQUEST['macroValue'])) { - $service->insertMacro( - $service_id, - $_REQUEST['macroInput'], - $_REQUEST['macroValue'], - $_REQUEST['macroPassword'] - ); - } - - if (isset($ret['criticality_id']) && $ret['criticality_id']) { - setServiceCriticality($service_id, $ret['criticality_id']); - } + if (isset($_REQUEST['macroInput']) && isset($_REQUEST['macroValue'])) { + $service->insertMacro( + $service_id, + $_REQUEST['macroInput'], + $_REQUEST['macroValue'], + $_REQUEST['macroPassword'], + true + ); + } + if (isset($ret['criticality_id']) && $ret['criticality_id']) { + setServiceCriticality($service_id, $ret['criticality_id']); + } $centreon->CentreonLogAction->insertLog("service", $service_id, getMyServiceName($service_id), "mc", $fields); }