public function assignTagToCve(Cve &$cve, Tag &$tag) { if ($cve == null || $cve->getId() == -1 || $tag == null) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Cve object is not valid or Cve.id is not set"); } # Check if the tag name is valid if ($tag->getName() == "") { $tag->setName(Constants::$NA); } $tagId = $this->getTagIdByName($tag->getName()); if ($tagId == -1) { $this->getPakiti()->getDao("Tag")->create($tag); } else { $tag->setId($tagId); } Utils::log(LOG_DEBUG, "Assinging the tag to the cve [cveId=" . $cve->getId() . ",tag=" . $tag->getName() . "]", __FILE__, __LINE__); # Check if the already assigned $isAssigned = $this->getPakiti()->getManager("DbManager")->queryToSingleValue("select 1 from CveTag where\n \t \t\tcveId=" . $this->getPakiti()->getManager("DbManager")->escape($cve->getId()) . " and\n \t \t\ttagId=" . $this->getPakiti()->getManager("DbManager")->escape($tag->getId())); if ($isAssigned != null) { throw new Exception($cve->getName() . " is already associated with " . $tag->getName() . " tag!"); } else { # Association between cve and cveTag doesn't exist, so create it $this->getPakiti()->getManager("DbManager")->query("\n \t\tinsert into CveTag set\n \t\t\tcveId=" . $this->getPakiti()->getManager("DbManager")->escape($cve->getId()) . ",\n \t \t\ttagId=" . $this->getPakiti()->getManager("DbManager")->escape($tag->getId()) . ",\n \t \t\t`reason`='" . $this->getPakiti()->getManager("DbManager")->escape($tag->getReason()) . "'"); } }
public function create(Cve &$cve) { $this->db->query("insert into Cve set\n \tname='" . $this->db->escape($cve->getName()) . "',\n \tcveDefId='" . $this->db->escape($cve->getCveDefId()) . "'"); # Set the newly assigned id $cve->setId($this->db->getLastInsertedId()); }