Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
#5297 [CLAPI] Several bugs on HG / CG when export is filtered (#5320)
Browse files Browse the repository at this point in the history
* #5297 [CLAPI] Several bugs on HG / CG when export is filtered 

Fix contact group filtered member export

* fix filters on CG export

* Update centreonHostGroup.class.php
  • Loading branch information
Simon Bomm authored and kduret committed Jul 12, 2017
1 parent cfdcdd2 commit a948ed9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
31 changes: 24 additions & 7 deletions www/class/centreon-clapi/centreonContactGroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,32 @@ public function __call($name, $arg) {
* @return void
*/
public function export($filter_id=null, $filter_name=null) {
$filters = null;
if (!is_null($filter_id)) {
$filters = array('cg_id' => $filter_id);
$filters = array();
if (!is_null($filter_id) && $filter_id !== 0) {
$filters['cg_id'] = $filter_id;
}
if (!is_null($filter_name)) {
$filters['cg_name'] = $filter_name;
}
$obj = new Centreon_Object_Relation_Contact_Group_Contact();
$elements = $obj->getMergedParameters(array("cg_name"), array("contact_name", "contact_id"), -1, 0, "cg_name");
parent::export($filters);
$relObj = new Centreon_Object_Relation_Contact_Group_Contact();
$contactObj = new Centreon_Object_Contact();
$cgFieldName = $this->object->getUniqueLabelField();
$cFieldName = $contactObj->getUniqueLabelField();
$elements = $relObj->getMergedParameters(
array($cgFieldName),
array($cFieldName, "contact_id"),
-1,
0,
$cgFieldName,
'ASC',
$filters,
'AND'
);

foreach ($elements as $element) {
$this->api->export_filter('CONTACT', $element['contact_id'], $element['contact_name']);
echo $this->action . $this->delim . "addcontact" . $this->delim . $element['cg_name'] . $this->delim . $element['contact_alias'] . "\n";
$this->api->export_filter('CONTACT', $element['contact_id'], $element[$cgFieldName]);
echo $this->action . $this->delim . "addcontact" . $this->delim . $element[$cgFieldName] . $this->delim . $element[$cFieldName] . $this->delim . $element['contact_alias'] . "\n";
}
}

Expand Down
13 changes: 9 additions & 4 deletions www/class/centreon-clapi/centreonHostGroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,12 @@ public function __call($name, $arg)
*/
public function export($filter_id=null, $filter_name=null)
{
$filters = null;
if (!is_null($filter_id)) {
$filters = array('hg_id' => $filter_id);
$filters = array();
if (!is_null($filter_id) && $filter_id !== 0) {
$filters['hg_id'] = $filter_id;
}
if (!is_null($filter_name)) {
$filters['hg_name'] = $filter_name;
}
parent::export($filters);
$relObj = new Centreon_Object_Relation_Host_Group_Host();
Expand All @@ -252,7 +255,9 @@ public function export($filter_id=null, $filter_name=null)
-1,
0,
$hgFieldName,
null
'ASC',
$filters,
'AND'
);
foreach ($elements as $element) {
$this->api->export_filter('HOST', $element['host_id'], $element[$hFieldName]);
Expand Down

0 comments on commit a948ed9

Please sign in to comment.