Commit 0270aa05 authored by Sylvestre Ho's avatar Sylvestre Ho
Browse files

fixes #5201; fixes macro massive change

parent c7a7c7a6
......@@ -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
?>
......@@ -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;
}
}
......
......@@ -1502,7 +1502,8 @@ function updateHost_MC($host_id = null) {
$host_id,
$_REQUEST['macroInput'],
$_REQUEST['macroValue'],
$_REQUEST['macroPassword']
$_REQUEST['macroPassword'],
true
);
}
......
......@@ -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);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment