/** * Set the activate field * * @param string $objectName * @param int $value * @throws CentreonClapiException */ protected function activate($objectName, $value) { if (!isset($objectName) || !$objectName) { throw new CentreonClapiException(self::MISSINGPARAMETER); } if (isset($this->activateField)) { $ids = $this->object->getIdByParameter($this->object->getUniqueLabelField(), array($objectName)); if (count($ids)) { $this->object->update($ids[0], array($this->activateField => $value)); } else { throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $objectName); } } else { throw new CentreonClapiException(self::UNKNOWN_METHOD); } }
/** * Insert new dependency * * @param string $name * @param string $description * @param Centreon_Object $parentObj * @param string $parentString * @param Centreon_Object_Relation * @throws CentreonClapiException */ protected function insertDependency($name, $description, $parentObj, $parentString, $relationObj) { $parents = explode('|', $parentString); $parentIds = array(); foreach ($parents as $parent) { $idTab = $parentObj->getIdByParameter($parentObj->getUniqueLabelField(), array($parent)); // make sure that all parents exist if (!count($idTab)) { throw new CentreonClapiException(sprintf('Could not find %s', $parent)); } $parentIds[] = $idTab[0]; } // insert dependency $depId = $this->object->insert(array('dep_name' => $name, 'dep_description' => $description)); if (is_null($depId)) { throw new CentreonClapiException(sprintf("Could not insert dependency %s", $name)); } // insert relations foreach ($parentIds as $parentId) { $relationObj->insert($depId, $parentId); } }
/** * Delete resource from downtime * * @param string $parameters | downtime name; resource name separated by "|" character * @param Centreon_Object $object * @param string $relTable * @param string $relField */ protected function delGenericRelation($parameters, $object, $relTable, $relField) { $tmp = explode($this->delim, $parameters); if (count($tmp) != 2) { throw new CentreonClapiException('Missing parameters'); } /* init var */ $downtimeId = $this->getObjectId($tmp[0]); $resources = explode('|', $tmp[1]); /* retrieve object ids */ $objectIds = array(); foreach ($resources as $resource) { $ids = $object->getIdByParameter($object->getUniqueLabelField(), array($resource)); /* object does not exist */ if (!count($ids)) { throw new CentreonClapiException(sprintf('Unknown object named %s', $resource)); } /* checks whether or not relationship already exists */ $sql = "SELECT * FROM {$relTable} WHERE dt_id = ? AND {$relField} = ?"; $stmt = $this->db->query($sql, array($downtimeId, $ids[0])); if (!$stmt->rowCount()) { throw new CentreonClapiException(sprintf('Cannot remove relationship with %s as the relationship does not exist', $resource)); } $objectIds[] = $ids[0]; } /* delete relationship */ $sql = "DELETE FROM {$relTable} WHERE dt_id = ? AND {$relField} = ?"; foreach ($objectIds as $id) { $this->db->query($sql, array($downtimeId, $id)); } }