/** * * @param int $depId * @param string $objectToDelete * @param string $relType | 'parent' or 'child' */ protected function delServicegroupRelations($depId, $objectToDelete, $relType) { $table = "dependency_servicegroup" . ucfirst($relType) . "_relation"; $sql = "DELETE FROM {$table} \n WHERE dependency_dep_id = ?\n AND servicegroup_sg_id = ?"; $obj = new Centreon_Object_Service_Group(); $ids = $obj->getIdByParameter($obj->getUniqueLabelField(), array($objectToDelete)); if (!count($ids)) { throw new CentreonClapiException(sprintf('Could not find service group %s', $objectToDelete)); } $this->db->query($sql, array($depId, $ids[0])); }
/** * Magic method * * @param string $name * @param array $args * @return void * @throws CentreonClapiException */ public function __call($name, $arg) { $name = strtolower($name); if (!isset($arg[0])) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $args = explode($this->delim, $arg[0]); $hgIds = $this->object->getIdByParameter($this->object->getUniqueLabelField(), array($args[0])); if (!count($hgIds)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $args[0]); } $groupId = $hgIds[0]; if (preg_match("/^(get|set|add|del)(member|host|servicegroup)\$/", $name, $matches)) { if ($matches[2] == "host" || $matches[2] == "member") { $relobj = new Centreon_Object_Relation_Host_Group_Host(); $obj = new Centreon_Object_Host(); } elseif ($matches[2] == "servicegroup") { $relobj = new Centreon_Object_Relation_Host_Group_Service_Group(); $obj = new Centreon_Object_Service_Group(); } if ($matches[1] == "get") { $tab = $relobj->getTargetIdFromSourceId($relobj->getSecondKey(), $relobj->getFirstKey(), $hgIds); echo "id" . $this->delim . "name" . "\n"; foreach ($tab as $value) { $tmp = $obj->getParameters($value, array($obj->getUniqueLabelField())); echo $value . $this->delim . $tmp[$obj->getUniqueLabelField()] . "\n"; } } else { if (!isset($args[1])) { throw new CentreonClapiException(self::MISSINGPARAMETER); } $relation = $args[1]; $relations = explode("|", $relation); $relationTable = array(); foreach ($relations as $rel) { $tab = $obj->getIdByParameter($obj->getUniqueLabelField(), array($rel)); if (!count($tab)) { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $rel); } $relationTable[] = $tab[0]; } if ($matches[1] == "set") { $relobj->delete($groupId); } $existingRelationIds = $relobj->getTargetIdFromSourceId($relobj->getSecondKey(), $relobj->getFirstKey(), array($groupId)); foreach ($relationTable as $relationId) { if ($matches[1] == "del") { $relobj->delete($groupId, $relationId); } elseif ($matches[1] == "set" || $matches[1] == "add") { if (!in_array($relationId, $existingRelationIds)) { $relobj->insert($groupId, $relationId); } } } $acl = new CentreonACL(); $acl->reload(true); } } else { throw new CentreonClapiException(self::UNKNOWN_METHOD); } }