Example #1
0
 function testGetTopLevelLicenseRefs()
 {
     $licenseMap = new LicenseMap($this->dbManager, $this->groupId, LicenseMap::CONCLUSION);
     $topLevelLicenses = $licenseMap->getTopLevelLicenseRefs();
     assertThat($topLevelLicenses, hasItemInArray(new LicenseRef(1, 'One', 'One-1')));
     assertThat($topLevelLicenses, not(hasKeyInArray(2)));
 }
Example #2
0
 /**
  * \brief Add a new license_ref to the database
  *
  * \return An add status string
  */
 function Adddb()
 {
     $rf_shortname = trim($_POST['rf_shortname']);
     $rf_fullname = trim($_POST['rf_fullname']);
     $rf_url = $_POST['rf_url'];
     $rf_notes = $_POST['rf_notes'];
     $rf_text = trim($_POST['rf_text']);
     $parent = $_POST['rf_parent'];
     $report = $_POST['rf_report'];
     $riskLvl = intval($_POST['risk_level']);
     if (empty($rf_shortname)) {
         $text = _("ERROR: The license shortname is empty.");
         return "<b>{$text}</b><p>";
     }
     if ($this->isShortnameBlocked(0, $rf_shortname, $rf_text)) {
         $text = _("ERROR: The shortname or license text already exist in the license list.  License not added.");
         return "<b>{$text}</b><p>";
     }
     $md5term = empty($rf_text) || stristr($rf_text, "License by Nomos") ? 'null' : 'md5($7)';
     $stmt = __METHOD__ . '.rf';
     $sql = "INSERT into license_ref (\n        rf_active, marydone, rf_shortname, rf_fullname,\n        rf_url, rf_notes, rf_md5, rf_text, rf_text_updatable,\n        rf_detector_type, rf_risk) \n          VALUES (\n              \$1, \$2, \$3, \$4, \$5, \$6, {$md5term}, \$7, \$8, \$9, \$10) RETURNING rf_pk";
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt, array($_POST['rf_active'], $_POST['marydone'], $rf_shortname, $rf_fullname, $rf_url, $rf_notes, $rf_text, $_POST['rf_text_updatable'], $_POST['rf_detector_type'], $riskLvl));
     $row = $this->dbManager->fetchArray($res);
     $rfId = $row['rf_pk'];
     $parentMap = new LicenseMap($this->dbManager, 0, LicenseMap::CONCLUSION);
     $parentLicenses = $parentMap->getTopLevelLicenseRefs();
     if (array_key_exists($parent, $parentLicenses)) {
         $this->dbManager->insertTableRow('license_map', array('rf_fk' => $rfId, 'rf_parent' => $parent, 'usage' => LicenseMap::CONCLUSION));
     }
     $reportMap = new LicenseMap($this->dbManager, 0, LicenseMap::REPORT);
     $reportLicenses = $reportMap->getTopLevelLicenseRefs();
     if (array_key_exists($report, $reportLicenses)) {
         $this->dbManager->insertTableRow('license_map', array('rf_fk' => $rfId, 'rf_parent' => $report, 'usage' => LicenseMap::REPORT));
     }
     $ob = "License {$_POST['rf_shortname']} (id={$rfId}) added.<p>";
     return $ob;
 }