public function assignHostToHostGroup(Host &$host, HostGroup &$hostGroup) { if ($host == null || $host->getId() == -1 || $hostGroup == null) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Host or HostGroup object is not valid or Host.id|HostGroup.id is not set"); } Utils::log(LOG_DEBUG, "Assigning the host to the host group [host=" . $host->getHostname() . ",hostGroupName=" . $hostGroup->getName() . "]", __FILE__, __LINE__); # Check if the hostGroup name is valid if ($hostGroup->getName() == "") { $hostGroup->setName(Constants::$NA); } $hostGroupId = $this->getHostGroupIdByName($hostGroup->getName()); if ($hostGroupId == -1) { # HostGroup doesn't exist, so create it $this->getPakiti()->getDao("HostGroup")->create($hostGroup); } else { $hostGroup->setId($hostGroupId); } Utils::log(LOG_DEBUG, "Assinging the host to the hostGroup [hostId=" . $host->getId() . ",hostGroupId=" . $hostGroup->getId() . "]", __FILE__, __LINE__); # Check if the tag already exists $isAssigned = $this->getPakiti()->getManager("DbManager")->queryToSingleValue("select 1 from HostHostGroup where \n \t \t\thostId=" . $this->getPakiti()->getManager("DbManager")->escape($host->getId()) . " and \n \t \t\thostGroupId=" . $this->getPakiti()->getManager("DbManager")->escape($hostGroup->getId())); if ($isAssigned == null) { # Association between host and hostTag doesn't exist, so create it $this->getPakiti()->getManager("DbManager")->query("insert into HostHostGroup set \n hostId=" . $this->getPakiti()->getManager("DbManager")->escape($host->getId()) . ",\n \t \t\thostGroupId=" . $this->getPakiti()->getManager("DbManager")->escape($hostGroup->getId())); } }
public function delete(HostGroup &$hostGroup) { Utils::log(LOG_DEBUG, "Deleting [hostGroup=" . $hostGroup->getName() . "]", __FILE__, __LINE__); $this->db->query("delete from HostGroup where id=" . $hostGroup->getId()); }