public function insertPermission($uploadId, $groupId, $permLevel) { $this->dbManager->getSingleRow("DELETE FROM perm_upload WHERE upload_fk=\$1 AND group_fk=\$2", array($uploadId, $groupId), __METHOD__ . '.avoid_doublet'); if ($permLevel == Auth::PERM_NONE) { return; } $this->dbManager->insertTableRow('perm_upload', array('perm' => $permLevel, 'upload_fk' => $uploadId, 'group_fk' => $groupId)); }
public function testGetAgentFileLicenseMatchesWithLicenseMapping() { $this->testDb->createPlainTables(array('license_ref', 'uploadtree', 'license_file', 'agent', 'license_map')); $this->testDb->insertData_license_ref(); $lic0 = $this->dbManager->getSingleRow("Select * from license_ref limit 1", array(), __METHOD__ . '.anyLicense'); $licRefId = $lic0['rf_pk']; $licenseFileId = 1; $pfileId = 42; $agentId = 23; $matchPercent = 50; $uploadtreeId = 512; $uploadID = 123; $left = 2009; $right = 2014; $agentName = "fake"; $agentRev = 1; $lic1 = $this->dbManager->getSingleRow("SELECT * FROM license_ref WHERE rf_pk!=\$1 LIMIT 1", array($licRefId), __METHOD__ . '.anyOtherLicense'); $licVarId = $lic1['rf_pk']; $mydate = "'2014-06-04 14:01:30.551093+02'"; $this->dbManager->insertTableRow('license_map', array('license_map_pk' => 0, 'rf_fk' => $licVarId, 'rf_parent' => $licRefId, 'usage' => LicenseMap::CONCLUSION)); $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk, rf_fk, agent_fk, rf_match_pct, rf_timestamp, pfile_fk)\n VALUES ({$licenseFileId}, {$licVarId}, {$agentId}, {$matchPercent}, {$mydate}, {$pfileId})"); $this->dbManager->queryOnce("INSERT INTO uploadtree (uploadtree_pk, upload_fk, pfile_fk, lft, rgt)\n VALUES ({$uploadtreeId}, {$uploadID}, {$pfileId}, {$left}, {$right})"); $stmt = __METHOD__ . '.insert.agent'; $this->dbManager->prepare($stmt, "INSERT INTO agent (agent_pk, agent_name, agent_rev, agent_enabled) VALUES (\$1,\$2,\$3,\$4)"); $this->dbManager->execute($stmt, array($agentId, $agentName, $agentRev, 'true')); $licDao = new LicenseDao($this->dbManager); $itemTreeBounds = new ItemTreeBounds($uploadtreeId, "uploadtree", $uploadID, $left, $right); $matches = $licDao->getAgentFileLicenseMatches($itemTreeBounds, LicenseMap::CONCLUSION); $licenseRef = new LicenseRef($licRefId, $lic0['rf_shortname'], $lic0['rf_fullname']); $agentRef = new AgentRef($agentId, $agentName, $agentRev); $expected = array(new LicenseMatch($pfileId, $licenseRef, $agentRef, $licenseFileId, $matchPercent)); assertThat($matches, equalTo($expected)); $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore); }
public function ensureTopLevelFolder() { if (!$this->hasTopLevelFolder()) { $this->dbManager->insertTableRow("folder", array("folder_pk" => self::TOP_LEVEL, "folder_name" => "Software Repository", "folder_desc" => "Top Folder")); $this->insertFolderContents(1, 0, 0); $this->fixFolderSequence(); } }
private function insertMapIfNontrivial($fromName, $toName, $usage) { $isNontrivial = $fromName !== null && $fromName != $toName && $this->getKeyFromShortname($fromName) !== false; if ($isNontrivial) { $this->dbManager->insertTableRow('license_map', array('rf_fk' => $this->getKeyFromShortname($toName), 'rf_parent' => $this->getKeyFromShortname($fromName), 'usage' => $usage)); } return $isNontrivial; }
public function testGetUserName() { $username = '******'; $userId = 101; $this->testDb->createPlainTables(array('users')); $this->dbManager->insertTableRow('users', array('user_pk' => $userId, 'user_name' => $username)); $uName = $this->userDao->getUserName($userId); assertThat($uName, equalTo($username)); }
public function testmakeAccessibleToGroup() { $this->testDb->createPlainTables(array('perm_upload', 'group_user_member')); $userId = 501; $groupId = 601; $groupIdAlternative = 602; $this->dbManager->insertTableRow('group_user_member', array('group_fk' => $groupId, 'user_fk' => $userId, 'group_perm' => Auth::PERM_READ)); $this->dbManager->insertTableRow('group_user_member', array('group_fk' => $groupIdAlternative, 'user_fk' => $userId, 'group_perm' => Auth::PERM_READ)); $unaccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId = 1, $groupId); assertThat($unaccessibleIsAccessible, equalTo(false)); $this->uploadPermissionDao->makeAccessibleToGroup($uploadId, $groupId, Auth::PERM_WRITE); $accessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupId); assertThat($accessibleIsAccessible, equalTo(true)); $stillUnaccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupIdAlternative); assertThat($stillUnaccessibleIsAccessible, equalTo(false)); $this->uploadPermissionDao->makeAccessibleToAllGroupsOf($uploadId, $userId); $nowAccessibleIsAccessible = $this->uploadPermissionDao->isAccessible($uploadId, $groupIdAlternative); assertThat($nowAccessibleIsAccessible, equalTo(true)); }
/** * @param string $agentName * @return bool */ public function renewCurrentAgent($agentName) { $this->dbManager->begin(); $row = $this->dbManager->getSingleRow("SELECT agent_pk, agent_name, agent_rev, agent_desc FROM agent " . "WHERE agent_enabled AND agent_name=\$1 ORDER BY agent_pk DESC LIMIT 1", array($agentName), __METHOD__ . '.get'); $this->dbManager->getSingleRow("UPDATE agent SET agent_rev=agent_rev||'.'||substr(md5(agent_ts::text),0,6) " . "WHERE agent_pk=\$1", array($row['agent_pk']), __METHOD__ . '.upd'); unset($row['agent_pk']); $this->dbManager->insertTableRow('agent', $row); $this->dbManager->commit(); return true; }
private function buildDecisions($cDec, $j = 0) { foreach ($cDec as $cd) { list($item, $user, $group, $type, $t, $scope, $eventIds) = $cd; $this->dbManager->insertInto('clearing_decision', 'clearing_decision_pk, uploadtree_fk, pfile_fk, user_fk, group_fk, decision_type, date_added, scope', array($j, $item, $this->items[$item][2], $user, $group, $type, $this->getMyDate($this->now + $t), $scope)); foreach ($eventIds as $eId) { $this->dbManager->insertTableRow('clearing_decision_event', array('clearing_decision_fk' => $j, 'clearing_event_fk' => $eId)); } $j++; } }
public function testGetRemovableContents() { $this->folderDao->ensureTopLevelFolder(); $folderA = $this->folderDao->insertFolder($folderName = 'A', '/A', FolderDao::TOP_LEVEL); $this->folderDao->insertFolder('B', '/A/B', $folderA); $folderC = $this->folderDao->insertFolder('C', '/C', FolderDao::TOP_LEVEL); assertThat($this->folderDao->getRemovableContents($folderA), arrayWithSize(0)); $this->dbManager->insertTableRow('foldercontents', array('foldercontents_mode' => FolderDao::MODE_UPLOAD, 'parent_fk' => $folderA, 'child_id' => $folderC)); assertThat($this->folderDao->getRemovableContents($folderA), arrayWithSize(0)); $this->dbManager->insertTableRow('foldercontents', array('foldercontents_mode' => FolderDao::MODE_FOLDER, 'parent_fk' => $folderA, 'child_id' => $folderC)); assertThat($this->folderDao->getRemovableContents($folderA), arrayWithSize(1)); }
public function testUploads2JobsPaged() { $jobs = array_combine(range(3, 13), range(3, 13)); foreach ($jobs as $jobId => $jobUpload) { $this->dbManager->insertTableRow('job', array('job_pk' => $jobId, 'job_upload_fk' => $jobUpload)); } $uploadDao = M::mock('Fossology\\Lib\\Dao\\UploadDao'); $showJobDao = new ShowJobsDao($this->dbManager, $uploadDao); $jobsPage1 = $showJobDao->uploads2Jobs(range(1, 17), 0); assertThat($jobsPage1, arrayWithSize(10)); $jobsPage2 = $showJobDao->uploads2Jobs(array_combine(range(10, 16), range(11, 17)), 1); assertThat($jobsPage2, arrayWithSize(3)); $jobsPage3 = $showJobDao->uploads2Jobs(array(), 2); assertThat($jobsPage3, arrayWithSize(0)); }
/** * @param ItemTreeBounds $item * @param string $hash * @param string $content * @param int $userId * @param string $cpTable */ public function updateTable($item, $hash, $content, $userId, $cpTable = 'copyright') { $itemTable = $item->getUploadTreeTableName(); $stmt = __METHOD__ . ".{$cpTable}.{$itemTable}"; $params = array($hash, $item->getLeft(), $item->getRight(), $content); $sql = "UPDATE {$cpTable} AS cpr SET content = \$4, hash = md5(\$4)\n FROM {$cpTable} as cp\n INNER JOIN {$itemTable} AS ut ON cp.pfile_fk = ut.pfile_fk\n WHERE cpr.ct_pk = cp.ct_pk\n AND cp.hash =\$1\n AND ( ut.lft BETWEEN \$2 AND \$3 )"; if ('uploadtree_a' == $item->getUploadTreeTableName()) { $params[] = $item->getUploadId(); $sql .= " AND ut.upload_fk=\$" . count($params); $stmt .= '.upload'; } $this->dbManager->prepare($stmt, "{$sql} RETURNING cp.* "); $oldData = $this->dbManager->execute($stmt, $params); if ($cpTable == "copyright") { while ($row = $this->dbManager->fetchArray($oldData)) { $this->dbManager->insertTableRow('copyright_audit', array('ct_fk' => $row['ct_pk'], 'oldtext' => $row['content'], 'user_fk' => $userId, 'upload_fk' => $item->getUploadId(), 'uploadtree_pk' => $item->getItemId(), 'pfile_fk' => $row['pfile_fk']), __METHOD__ . "writeHist"); } } $this->dbManager->freeResult($oldData); }
/** * \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; }
/** * @param int $uploadId * @param int $jobId * @param string $fileName */ protected function updateReportTable($uploadId, $jobId, $fileName) { $this->dbManager->insertTableRow('reportgen', array('upload_fk' => $uploadId, 'job_fk' => $jobId, 'filepath' => $fileName), __METHOD__); }
/** * @param int $uploadId * @param int $reusedUploadId * @param int $groupId * @param int $reusedGroupId * @param int $reuseMode */ public function addReusedUpload($uploadId, $reusedUploadId, $groupId, $reusedGroupId, $reuseMode = 0) { $this->dbManager->insertTableRow('upload_reuse', array('upload_fk' => $uploadId, 'group_fk' => $groupId, 'reused_upload_fk' => $reusedUploadId, 'reused_group_fk' => $reusedGroupId, 'reuse_mode' => $reuseMode)); }
public function makeMainLicense($uploadId, $groupId, $licenseId) { $this->dbManager->insertTableRow('upload_clearing_license', array('upload_fk' => $uploadId, 'group_fk' => $groupId, 'rf_fk' => $licenseId)); }