示例#1
0
 /**
  * @param int $uploadId
  * @param Package $package
  */
 public function addUploadToPackage($uploadId, Package $package)
 {
     $statementName = __METHOD__;
     $this->dbManager->prepare($statementName, "INSERT INTO upload_packages (package_fk, upload_fk) VALUES(\$1, \$2)");
     $res = $this->dbManager->execute($statementName, array($package->getId(), $uploadId));
     $this->dbManager->freeResult($res);
 }
示例#2
0
 /**
  * @param int $parentFolder  parent folder_pk
  * @return string HTML of the folder tree
  */
 public function showFolderTree($parentFolder)
 {
     $uri = Traceback_uri();
     $sql = $this->folderDao->getFolderTreeCte($parentFolder) . " SELECT folder_pk, folder_name, folder_desc, depth, name_path FROM folder_tree ORDER BY name_path";
     $stmt = __METHOD__;
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt, array($parentFolder));
     $out = '';
     $lastDepth = -1;
     while ($row = $this->dbManager->fetchArray($res)) {
         for (; $row['depth'] < $lastDepth; $lastDepth--) {
             $out .= '</li></ul>';
         }
         if ($row['depth'] == $lastDepth) {
             $out .= "</li>\n<li>";
         }
         if ($row['depth'] == 0) {
             $out .= '<ul id="tree"><li>';
             $lastDepth++;
         }
         for (; $row['depth'] > $lastDepth; $lastDepth++) {
             $out .= '<ul><li>';
         }
         $out .= $this->getFormattedItem($row, $uri);
     }
     for (; -1 < $lastDepth; $lastDepth--) {
         $out .= '</li></ul>';
     }
     return $out;
 }
示例#3
0
 /**
  * @param array $uploadTreeArray
  * @throws \Exception
  */
 protected function prepareUploadTree($uploadTreeArray = array())
 {
     $this->dbManager->prepare($stmt = 'insert.uploadtree', "INSERT INTO uploadtree (uploadtree_pk, parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name, realparent) VALUES (\$1, \$2, \$3, \$4, \$5, \$6, \$7, \$8, \$9)");
     foreach ($uploadTreeArray as $uploadTreeEntry) {
         $this->dbManager->freeResult($this->dbManager->execute($stmt, $uploadTreeEntry));
     }
 }
示例#4
0
 public function rerunBulkAndDeciderOnUpload($uploadId, $groupId, $userId, $jobId)
 {
     $bulkIds = $this->getBulkIds($uploadId, $groupId, $userId);
     if (count($bulkIds) == 0) {
         return 0;
     }
     /* @var $uploadDao UploadDao */
     $uploadDao = $GLOBALS['container']->get('dao.upload');
     $topItem = $uploadDao->getUploadParent($uploadId);
     /* @var $deciderPlugin DeciderJobAgentPlugin */
     $deciderPlugin = plugin_find("agent_deciderjob");
     $dependecies = array();
     $sql = "INSERT INTO license_ref_bulk (user_fk,group_fk,rf_text,upload_fk,uploadtree_fk) " . "SELECT \$1 AS user_fk, \$2 AS group_fk,rf_text,\$3 AS upload_fk, \$4 as uploadtree_fk\n              FROM license_ref_bulk WHERE lrb_pk=\$5 RETURNING lrb_pk, \$5 as lrb_origin";
     $sqlLic = "INSERT INTO license_set_bulk (lrb_fk,rf_fk,removing) " . "SELECT \$1 as lrb_fk,rf_fk,removing FROM license_set_bulk WHERE lrb_fk=\$2";
     $this->dbManager->prepare($stmt = __METHOD__ . 'cloneBulk', $sql);
     $this->dbManager->prepare($stmtLic = __METHOD__ . 'cloneBulkLic', $sqlLic);
     foreach ($bulkIds as $bulkId) {
         $res = $this->dbManager->execute($stmt, array($userId, $groupId, $uploadId, $topItem, $bulkId));
         $row = $this->dbManager->fetchArray($res);
         $this->dbManager->freeResult($res);
         $resLic = $this->dbManager->execute($stmtLic, array($row['lrb_pk'], $row['lrb_origin']));
         $this->dbManager->freeResult($resLic);
         $dependecies[] = array('name' => 'agent_monk_bulk', 'args' => $row['lrb_pk'], AgentPlugin::PRE_JOB_QUEUE => array('agent_decider'));
     }
     $errorMsg = '';
     $jqId = $deciderPlugin->AgentAdd($jobId, $uploadId, $errorMsg, $dependecies);
     if (!empty($errorMsg)) {
         throw new Exception($errorMsg);
     }
     return $jqId;
 }
示例#5
0
 public function hasActionPermissionsOnJob($jobId, $userId, $groupId)
 {
     $result = array();
     $stmt = __METHOD__;
     $this->dbManager->prepare($stmt, "SELECT *\n       FROM job\n         LEFT JOIN group_user_member gm\n           ON gm.user_fk = job_user_fk\n       WHERE job_pk = \$1\n         AND (job_user_fk = \$2\n              OR gm.group_fk = \$3)");
     $res = $this->dbManager->execute($stmt, array($jobId, $userId, $groupId));
     while ($row = $this->dbManager->fetchArray($res)) {
         $result[$row['jq_pk']] = $row['end_bits'];
     }
     $this->dbManager->freeResult($res);
     return $result;
 }
示例#6
0
 public function getAllJobStatus($uploadId, $userId, $groupId)
 {
     $result = array();
     $stmt = __METHOD__;
     $this->dbManager->prepare($stmt, "SELECT jobqueue.jq_pk as jq_pk, jobqueue.jq_end_bits as end_bits\n      FROM jobqueue INNER JOIN job ON jobqueue.jq_job_fk = job.job_pk\n      LEFT JOIN group_user_member gm ON gm.user_fk = job_user_fk\n      WHERE job.job_upload_fk = \$1 AND (job_user_fk = \$2 OR gm.group_fk = \$3)");
     $res = $this->dbManager->execute($stmt, array($uploadId, $userId, $groupId));
     while ($row = $this->dbManager->fetchArray($res)) {
         $result[$row['jq_pk']] = $row['end_bits'];
     }
     $this->dbManager->freeResult($res);
     return $result;
 }
 protected function setUp()
 {
     $this->testDb = new TestPgDb();
     $this->dbManager =& $this->testDb->getDbManager();
     $this->testDb->createPlainTables(array('upload', 'uploadtree'));
     $this->dbManager->prepare($stmt = 'insert.upload', "INSERT INTO upload (upload_pk, uploadtree_tablename) VALUES (\$1, \$2)");
     $uploadArray = array(array(1, 'uploadtree'), array(2, 'uploadtree_a'));
     foreach ($uploadArray as $uploadEntry) {
         $this->dbManager->freeResult($this->dbManager->execute($stmt, $uploadEntry));
     }
     $logger = M::mock('Monolog\\Logger');
     // new Logger("UploadDaoTest");
     $logger->shouldReceive('debug');
     $this->uploadPermissionDao = new UploadPermissionDao($this->dbManager, $logger);
     $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
 }
示例#8
0
 /**
  * \brief Display the user record edit form
  * 
  * \param $UserRec - Database users record for the user to be edited.
  * \param $SessionIsAdmin - Boolean: This session is by an admin
  * \return the text of the display form on success, or error on failure.
  */
 private function DisplayForm($UserRec, $SessionIsAdmin)
 {
     $vars = array('isSessionAdmin' => $SessionIsAdmin, 'userId' => $UserRec['user_pk']);
     /* For Admins, get the list of all users 
      * For non-admins, only show themself
      */
     if ($SessionIsAdmin) {
         $stmt = __METHOD__ . '.asSessionAdmin';
         $sql = "SELECT * FROM users ORDER BY user_name";
         $this->dbManager->prepare($stmt, $sql);
         $res = $this->dbManager->execute($stmt);
         $allUsers = array();
         while ($row = $this->dbManager->fetchArray($res)) {
             $allUsers[$row['user_pk']] = htmlentities($row['user_name']);
         }
         $this->dbManager->freeResult($res);
         $vars['allUsers'] = $allUsers;
     }
     $vars['userName'] = $UserRec['user_name'];
     $vars['userDescription'] = $UserRec['user_desc'];
     $vars['userEMail'] = $UserRec["user_email"];
     $vars['eMailNotification'] = $UserRec['email_notify'] == 'y';
     if ($SessionIsAdmin) {
         $vars['allAccessLevels'] = array(PLUGIN_DB_NONE => _("None (very basic, no database access)"), PLUGIN_DB_READ => _("Read-only (read, but no writes or downloads)"), PLUGIN_DB_WRITE => _("Read-Write (read, download, or edit information)"), PLUGIN_DB_ADMIN => _("Full Administrator (all access including adding and deleting users)"));
         $vars['accessLevel'] = $UserRec['user_perm'];
         $SelectedFolderPk = $UserRec['root_folder_fk'];
         $vars['folderListOption'] = FolderListOption($ParentFolder = -1, $Depth = 0, $IncludeTop = 1, $SelectedFolderPk);
     }
     $vars['isBlankPassword'] = $UserRec['_blank_pass'] == 'on';
     $vars['agentSelector'] = AgentCheckBoxMake(-1, array("agent_unpack", "agent_adj2nest", "wget_agent"), $UserRec['user_name']);
     $vars['bucketPool'] = SelectBucketPool($UserRec["default_bucketpool_fk"]);
     return $vars;
 }
示例#9
0
 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);
 }
示例#10
0
 private function updateLicense($row, $sameText)
 {
     $log = "Text of '{$row['shortname']}' already used for '{$sameText['rf_shortname']}'";
     $stmt = __METHOD__;
     $sql = 'UPDATE license_ref SET ';
     $param = array($sameText['rf_pk']);
     if (!empty($row['source']) && empty($sameText['rf_source'])) {
         $stmt .= '.updSource';
         $sql .= ' rf_source=$2';
         $param[] = $row['source'];
         $log .= ', updated the source';
     }
     if (false !== $row['risk'] && $row['risk'] !== $sameText['rf_risk']) {
         $stmt .= '.updRisk';
         $sql .= count($param) == 2 ? ', rf_risk=$3' : 'rf_risk=$';
         $param[] = $row['risk'];
         $log .= ', updated the risk level';
     }
     if (count($param) > 1) {
         $this->dbManager->prepare("{$sql} WHERE rf_pk=\$1", $stmt);
         $res = $this->dbManager->execute($stmt, $param);
         $this->dbManager->freeResult($res);
     }
     return $log;
 }
示例#11
0
 /**
  * \brief Database queries
  * \returns html table containing query strings, pid, and start time
  */
 function DatabaseQueries()
 {
     $V = "<table border=1>\n";
     $head1 = _("PID");
     $head2 = _("Query");
     $head3 = _("Started");
     $head4 = _("Elapsed");
     $V .= "<tr><th>{$head1}</th><th>{$head2}</th><th>{$head3}</th><th>{$head4}</th></tr>\n";
     $current_query = strcmp($this->pgVersion['server'], "9.2") >= 0 ? "state" : "current_query";
     $procpid = strcmp($this->pgVersion['server'], "9.2") >= 0 ? "pid" : "procpid";
     $sql = "SELECT {$procpid} processid, {$current_query}, query_start, now()-query_start AS elapsed FROM pg_stat_activity WHERE {$current_query} != '<IDLE>' AND datname = 'fossology' ORDER BY {$procpid}";
     $statementName = __METHOD__ . "queryFor_" . $current_query . "_orderBy_" . $procpid;
     $this->dbManager->prepare($statementName, $sql);
     $result = $this->dbManager->execute($statementName, array());
     if (pg_num_rows($result) > 1) {
         while ($row = pg_fetch_assoc($result)) {
             if ($row[$current_query] == $sql) {
                 continue;
             }
             // Don't display this query
             $V .= "<tr>";
             $V .= "<td>{$row['processid']}</td>";
             $V .= "<td>" . htmlspecialchars($row[$current_query]) . "</td>";
             $StartTime = substr($row['query_start'], 0, 19);
             $V .= "<td>{$StartTime}</td>";
             $V .= "<td>{$row['elapsed']}</td>";
             $V .= "</tr>\n";
         }
     } else {
         $V .= "<tr><td colspan=4>There are no active FOSSology queries</td></tr>";
     }
     pg_free_result($result);
     $V .= "</table>\n";
     return $V;
 }
示例#12
0
 /** 
  * @brief Return total Job data with time elapsed
  * @param $job_pk
  * @return $row
  */
 public function getDataForASingleJob($job_pk)
 {
     $statementName = __METHOD__ . "getDataForASingleJob";
     $this->dbManager->prepare($statementName, "SELECT *, jq_endtime-jq_starttime as elapsed FROM jobqueue LEFT JOIN job ON job.job_pk = jobqueue.jq_job_fk WHERE jobqueue.jq_pk =\$1");
     $result = $this->dbManager->execute($statementName, array($job_pk));
     $row = $this->dbManager->fetchArray($result);
     $this->dbManager->freeResult($result);
     return $row;
 }
示例#13
0
 /**
  * @param string $scannerName
  * @param int $uploadId
  * @return array[] with keys agent_id,agent_rev,agent_name
  */
 public function getSuccessfulAgentEntries($scannerName, $uploadId)
 {
     $stmt = __METHOD__ . ".getAgent.{$scannerName}";
     $this->dbManager->prepare($stmt, $sql = "SELECT agent_pk AS agent_id,agent_rev,agent_name " . "FROM agent LEFT JOIN {$scannerName}" . self::ARS_TABLE_SUFFIX . " ON agent_fk=agent_pk " . "WHERE agent_name=\$2 AND agent_enabled AND upload_fk=\$1 AND ars_success " . "ORDER BY agent_id DESC");
     $res = $this->dbManager->execute($stmt, array($uploadId, $scannerName));
     $agents = $this->dbManager->fetchAll($res);
     $this->dbManager->freeResult($res);
     return $agents;
 }
示例#14
0
 /**
  * @param int $uploadId
  * @param int $groupId
  * @return int
  */
 public function getReusedUpload($uploadId, $groupId)
 {
     $statementName = __METHOD__;
     $this->dbManager->prepare($statementName, "SELECT reused_upload_fk, reused_group_fk, reuse_mode FROM upload_reuse WHERE upload_fk = \$1 AND group_fk=\$2");
     $res = $this->dbManager->execute($statementName, array($uploadId, $groupId));
     $reusedPairs = $this->dbManager->fetchAll($res);
     $this->dbManager->freeResult($res);
     return $reusedPairs;
 }
示例#15
0
 /**
  * 
  * @param string $tablename
  * @param string $columnname
  * @param array $map using keys
  * @return int
  */
 private function checkDatabaseEnum($tablename, $columnname, $map)
 {
     $errors = 0;
     $stmt = __METHOD__ . ".{$tablename}.{$columnname}";
     $sql = "SELECT {$columnname},count(*) FROM {$tablename} GROUP BY {$columnname}";
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt);
     while ($row = $this->dbManager->fetchArray($res)) {
         if (!array_key_exists($row[$columnname], $map)) {
             echo "(-) found invalid {$columnname} '" . $row[$columnname] . "' in table '{$tablename}'\n";
             $errors++;
         } else {
             if ($this->verbose) {
                 echo "(+) found valid {$columnname} '" . $row[$columnname] . "' in table '{$tablename}'\n";
             }
         }
     }
     $this->dbManager->freeResult($res);
     return $errors;
 }
 public function getPermissionGroups($uploadId)
 {
     $this->dbManager->prepare($stmt = __METHOD__, "SELECT perm_upload_pk, perm, group_pk, group_name\n           FROM groups, perm_upload\n           WHERE group_fk=group_pk AND upload_fk=\$1\n           ORDER BY group_name");
     $res = $this->dbManager->execute($stmt, array($uploadId));
     $groupMap = array();
     while ($row = $this->dbManager->fetchArray($res)) {
         $groupMap[$row['group_pk']] = $row;
     }
     $this->dbManager->freeResult($res);
     return $groupMap;
 }
 private function getGroupMembers($groupsWhereUserIsAdmin)
 {
     $this->dbManager->prepare($stmt = __METHOD__, "SELECT user_name,gum.group_fk FROM group_user_member gum, users WHERE user_fk=user_pk");
     $res = $this->dbManager->execute($stmt);
     $gum = array();
     while ($row = $this->dbManager->fetchArray($res)) {
         if (array_key_exists($row['group_fk'], $groupsWhereUserIsAdmin)) {
             $gum[] = array($row['user_name'], $row['group_fk']);
         }
     }
     $this->dbManager->freeResult($res);
     return $gum;
 }
示例#18
0
 public function getMainLicenseIds($uploadId, $groupId)
 {
     $stmt = __METHOD__;
     $sql = "SELECT rf_fk FROM upload_clearing_license WHERE upload_fk=\$1 AND group_fk=\$2";
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt, array($uploadId, $groupId));
     $ids = array();
     while ($row = $this->dbManager->fetchArray($res)) {
         $ids[$row['rf_fk']] = $row['rf_fk'];
     }
     $this->dbManager->freeResult($res);
     return $ids;
 }
示例#19
0
 public function getFolderChildFolders($folderId)
 {
     $results = array();
     $stmtFolder = __METHOD__;
     $sqlFolder = "SELECT foldercontents_pk,foldercontents_mode, folder_name FROM foldercontents,folder " . "WHERE foldercontents.parent_fk=\$1 AND foldercontents.child_id=folder.folder_pk" . " AND foldercontents_mode=" . self::MODE_FOLDER;
     $this->dbManager->prepare($stmtFolder, $sqlFolder);
     $res = $this->dbManager->execute($stmtFolder, array($folderId));
     while ($row = $this->dbManager->fetchArray($res)) {
         $results[$row['foldercontents_pk']] = $row;
     }
     $this->dbManager->freeResult($res);
     return $results;
 }
示例#20
0
 public function getTopLevelLicenseRefs()
 {
     $licenseView = new LicenseViewProxy($this->groupId, array('columns' => array('rf_pk', 'rf_shortname', 'rf_fullname')), 'license_visible');
     $query = $licenseView->asCTE() . ' SELECT rf_pk, rf_shortname, rf_fullname FROM ' . $licenseView->getDbViewName() . ' LEFT JOIN license_map ON rf_pk=rf_fk AND rf_fk!=rf_parent AND usage=$1' . ' WHERE license_map_pk IS NULL';
     $stmt = __METHOD__ . ".{$this->usageId},{$this->groupId}";
     $this->dbManager->prepare($stmt, $query);
     $res = $this->dbManager->execute($stmt, array($this->usageId));
     $topLevel = array();
     while ($row = $this->dbManager->fetchArray($res)) {
         $topLevel[$row['rf_pk']] = new LicenseRef($row['rf_pk'], $row['rf_shortname'], $row['rf_fullname']);
     }
     return $topLevel;
 }
示例#21
0
 /**
  * @param int $userId
  * @param int $groupId
  * @param int $uploadTreeId
  * @param bool[] $licenseRemovals
  * @param string $refText
  * @return int lrp_pk on success or -1 on fail
  */
 public function insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseRemovals, $refText)
 {
     $licenseRefBulkIdResult = $this->dbManager->getSingleRow("INSERT INTO license_ref_bulk (user_fk, group_fk, uploadtree_fk, rf_text)\n      VALUES (\$1,\$2,\$3,\$4) RETURNING lrb_pk", array($userId, $groupId, $uploadTreeId, $refText), __METHOD__ . '.getLrb');
     if ($licenseRefBulkIdResult === false) {
         return -1;
     }
     $bulkId = $licenseRefBulkIdResult['lrb_pk'];
     $stmt = __METHOD__ . '.insertAction';
     $this->dbManager->prepare($stmt, "INSERT INTO license_set_bulk (lrb_fk, rf_fk, removing) VALUES (\$1,\$2,\$3)");
     foreach ($licenseRemovals as $licenseId => $removing) {
         $this->dbManager->execute($stmt, array($bulkId, $licenseId, $this->dbManager->booleanToDb($removing)));
     }
     return $bulkId;
 }
示例#22
0
 /**
  * @return string[] with keys being shortname
  */
 protected function getLicenseTexts()
 {
     $licenseTexts = array();
     $licenseViewProxy = new LicenseViewProxy($this->groupId, array(LicenseViewProxy::OPT_COLUMNS => array('rf_pk', 'rf_shortname', 'rf_text')));
     $this->dbManager->prepare($stmt = __METHOD__, $licenseViewProxy->getDbViewQuery());
     $res = $this->dbManager->execute($stmt);
     while ($row = $this->dbManager->fetchArray($res)) {
         if (array_key_exists($row['rf_pk'], $this->includedLicenseIds)) {
             $licenseTexts[$row['rf_shortname']] = $row['rf_text'];
         }
     }
     $this->dbManager->freeResult($res);
     return $licenseTexts;
 }
 protected function getCopyrights($upload_pk, $item, $uploadTreeTableName, $agentId, $type, $filter)
 {
     $offset = GetParm('iDisplayStart', PARM_INTEGER);
     $limit = GetParm('iDisplayLength', PARM_INTEGER);
     $tableName = $this->getTableName($type);
     $orderString = $this->getOrderString();
     list($left, $right) = $this->uploadDao->getLeftAndRight($item, $uploadTreeTableName);
     if ($filter == "") {
         $filter = "none";
     }
     $sql_upload = "";
     if ('uploadtree_a' == $uploadTreeTableName) {
         $sql_upload = " AND UT.upload_fk={$upload_pk} ";
     }
     $join = "";
     $filterQuery = "";
     if ($type == 'statement' && $filter == "nolic") {
         $noLicStr = "No_license_found";
         $voidLicStr = "Void";
         $join = " INNER JOIN license_file AS LF on cp.pfile_fk=LF.pfile_fk ";
         $filterQuery = " AND LF.rf_fk IN (SELECT rf_pk FROM license_ref WHERE rf_shortname IN ('{$noLicStr}','{$voidLicStr}')) ";
     } else {
         // No filter, nothing to do
     }
     $params = array($left, $right, $type, $agentId);
     $filterParms = $params;
     $searchFilter = $this->addSearchFilter($filterParms);
     $unorderedQuery = "FROM {$tableName} AS cp " . "INNER JOIN {$uploadTreeTableName} AS UT ON cp.pfile_fk = UT.pfile_fk " . $join . "WHERE cp.content!='' " . "AND ( UT.lft  BETWEEN  \$1 AND  \$2 ) " . "AND cp.type = \$3 " . "AND cp.agent_fk= \$4 " . $sql_upload;
     $totalFilter = $filterQuery . " " . $searchFilter;
     $grouping = " GROUP BY content ";
     $countQuery = "SELECT count(*) FROM (SELECT content, count(*) {$unorderedQuery} {$totalFilter} {$grouping}) as K";
     $iTotalDisplayRecordsRow = $this->dbManager->getSingleRow($countQuery, $filterParms, __METHOD__ . $tableName . ".count");
     $iTotalDisplayRecords = $iTotalDisplayRecordsRow['count'];
     $countAllQuery = "SELECT count(*) FROM (SELECT content, count(*) {$unorderedQuery}{$grouping}) as K";
     $iTotalRecordsRow = $this->dbManager->getSingleRow($countAllQuery, $params, __METHOD__, $tableName . "count.all");
     $iTotalRecords = $iTotalRecordsRow['count'];
     $range = "";
     $filterParms[] = $offset;
     $range .= ' OFFSET $' . count($filterParms);
     $filterParms[] = $limit;
     $range .= ' LIMIT $' . count($filterParms);
     $sql = "SELECT content, hash, count(*) as copyright_count  " . $unorderedQuery . $totalFilter . " GROUP BY content, hash " . $orderString . $range;
     $statement = __METHOD__ . $filter . $tableName . $uploadTreeTableName;
     $this->dbManager->prepare($statement, $sql);
     $result = $this->dbManager->execute($statement, $filterParms);
     $rows = $this->dbManager->fetchAll($result);
     $this->dbManager->freeResult($result);
     return array($rows, $iTotalDisplayRecords, $iTotalRecords);
 }
示例#24
0
 public function testGetEstimatedTimeShouldNotDivideByZero()
 {
     $this->dbManager->prepare($stmt = 'insert.jobqueue', "INSERT INTO jobqueue (jq_pk, jq_job_fk, jq_type, jq_args, jq_starttime, jq_endtime, jq_endtext, jq_end_bits, jq_schedinfo, jq_itemsprocessed)" . "VALUES (\$1, \$2, \$3, \$4,\$5, \$6,\$7,\$8,\$9,\$10)");
     $nowTime = time();
     $diffTime = 2345;
     $nomosTime = date('Y-m-d H:i:sO', $nowTime - $diffTime);
     $uploadArrayQue = array(array(8, $jobId = 1, $jqType = "nomos", 1, $nomosTime, null, "Started", 0, "localhost.5963", $itemNomos = 147), array(1, $jobId, "ununpack", 1, "2015-04-21 18:29:19.23825+05:30", "2015-04-21 18:29:26.396562+05:30", "Completed", 1, null, $itemCount = 646));
     foreach ($uploadArrayQue as $uploadEntry) {
         $this->dbManager->freeResult($this->dbManager->execute($stmt, $uploadEntry));
     }
     $showJobsDaoMock = M::mock('Fossology\\Lib\\Dao\\ShowJobsDao[getNumItemsPerSec]', array($this->dbManager, $this->uploadDao));
     $showJobsDaoMock->shouldReceive('getNumItemsPerSec')->andReturn(0);
     $estimated = $showJobsDaoMock->getEstimatedTime($jobId, $jqType);
     assertThat($estimated, equalTo('0:00:00'));
 }
示例#25
0
 /**
  * @param ItemTreeBounds $item
  * @param string $hash
  * @param int $userId
  * @param string $cpTable
  */
 public function rollbackTable($item, $hash, $userId, $cpTable = 'copyright')
 {
     $itemTable = $item->getUploadTreeTableName();
     $stmt = __METHOD__ . ".{$cpTable}.{$itemTable}";
     $params = array($hash, $item->getLeft(), $item->getRight(), $userId);
     $sql = "UPDATE {$cpTable} AS cpr SET content = cpa.oldtext, hash = \$1\n            FROM " . $cpTable . "_audit as cpa, {$itemTable} AS ut\n            WHERE cpr.pfile_fk = ut.pfile_fk\n              AND cpr.ct_pk = cpa.ct_fk\n              AND md5(cpa.oldtext) = \$1\n              AND ( ut.lft BETWEEN \$2 AND \$3 )\n              AND cpa.user_fk=\$4";
     if ('uploadtree_a' == $item->getUploadTreeTableName()) {
         $params[] = $item->getUploadId();
         $sql .= " AND ut.upload_fk=\$" . count($params);
         $stmt .= '.upload';
     }
     $this->dbManager->prepare($stmt, "{$sql}");
     $resource = $this->dbManager->execute($stmt, $params);
     $this->dbManager->freeResult($resource);
 }
示例#26
0
 /**
  * @brief Returns Estimated time using jobid
  * @param int $job_pk
  * @param string $jq_Type
  * @param float $filesPerSec
  * @param int $uploadId 
  * @return Returns empty if estimated time is 0 else returns time. 
  **/
 public function getEstimatedTime($job_pk, $jq_Type = '', $filesPerSec = 0, $uploadId = 0)
 {
     if (!empty($uploadId)) {
         $itemCount = $this->dbManager->getSingleRow("SELECT jq_itemsprocessed FROM jobqueue INNER JOIN job ON jq_job_fk=job_pk " . " WHERE jq_type LIKE 'ununpack' AND jq_end_bits ='1' AND job_upload_fk=\$1", array($uploadId), __METHOD__ . '.ununpack_might_be_in_other_job');
     } else {
         $itemCount = $this->dbManager->getSingleRow("SELECT jq_itemsprocessed FROM jobqueue WHERE jq_type LIKE 'ununpack' AND jq_end_bits ='1' AND jq_job_fk =\$1", array($job_pk), __METHOD__ . '.ununpack_must_be_in_this_job');
     }
     if (!empty($itemCount['jq_itemsprocessed'])) {
         $selectCol = "jq_type, jq_endtime, jq_starttime, jq_itemsprocessed";
         if (empty($jq_Type)) {
             $removeType = "jq_type NOT LIKE 'ununpack' AND jq_type NOT LIKE 'reportgen' AND jq_type NOT LIKE 'decider' AND";
             /* get starttime endtime and jobtype form jobqueue for a jobid except $removeType */
             $statementName = __METHOD__ . "{$selectCol}.{$removeType}";
             $this->dbManager->prepare($statementName, "SELECT {$selectCol} FROM jobqueue WHERE {$removeType} jq_job_fk =\$1 ORDER BY jq_type DESC");
             $result = $this->dbManager->execute($statementName, array($job_pk));
         } else {
             $statementName = __METHOD__ . "{$selectCol}.{$jq_Type}";
             $this->dbManager->prepare($statementName, "SELECT {$selectCol} FROM jobqueue WHERE jq_type LIKE '{$jq_Type}' AND jq_job_fk =\$1");
             $result = $this->dbManager->execute($statementName, array($job_pk));
         }
         $estimatedArray = array();
         // estimate time for each agent
         while ($row = $this->dbManager->fetchArray($result)) {
             $timeOfCompletion = 0;
             if (empty($row['jq_endtime']) && !empty($row['jq_starttime'])) {
                 // for agent started and not ended
                 if (empty($filesPerSec)) {
                     $burnTime = time() - strtotime($row['jq_starttime']);
                     $filesPerSec = $this->getNumItemsPerSec($row['jq_itemsprocessed'], $burnTime);
                 }
                 if (!empty($filesPerSec)) {
                     $timeOfCompletion = ($itemCount['jq_itemsprocessed'] - $row['jq_itemsprocessed']) / $filesPerSec;
                 }
                 array_push($estimatedArray, $timeOfCompletion);
             }
         }
         if (empty($estimatedArray)) {
             return "";
         } else {
             $estimatedTime = round(max($estimatedArray));
             // collecting max agent time in seconds
             return intval($estimatedTime / 3600) . gmdate(":i:s", $estimatedTime);
             // convert seconds to time and return
         }
     }
 }
示例#27
0
 function addFunctions($schema)
 {
     // prosrc
     // proretset == setof
     $sql = "SELECT proname AS name,\n        pronargs AS input_num,\n        proargnames AS input_names,\n        proargtypes AS input_type,\n        proargmodes AS input_modes,\n        proretset AS setof,\n        prorettype AS output_type\n      FROM pg_proc AS proc\n      INNER JOIN pg_language AS lang ON proc.prolang = lang.oid\n      WHERE lang.lanname = 'plpgsql'\n      ORDER BY proname;";
     $stmt = __METHOD__;
     $this->dbman->prepare($stmt, $sql);
     $result = $this->dbman->execute($stmt);
     while ($row = $this->dbman->fetchArray($result)) {
         $sql = "CREATE or REPLACE function " . $row['proname'] . "()";
         $sql .= ' RETURNS ' . "TBD" . ' AS $$';
         $sql .= " " . $row['prosrc'];
         $schema['FUNCTION'][$row['proname']] = $sql;
     }
     $this->dbman->freeResult($result);
     return $schema;
 }
示例#28
0
 /**
  * @param int $uploadTreeId
  * @param int|null $clearingId
  * @return Highlight[]
  */
 public function getHighlightBulk($uploadTreeId, $clearingId = null)
 {
     $stmt = __METHOD__;
     $sql = "SELECT h.clearing_event_fk, h.start, h.len, ce.rf_fk, rf_text\n            FROM clearing_event ce\n              INNER JOIN highlight_bulk h ON ce.clearing_event_pk = h.clearing_event_fk\n              INNER JOIN license_ref_bulk lrb ON lrb.lrb_pk = h.lrb_fk\n            WHERE ce.uploadtree_fk = \$1";
     $params = array($uploadTreeId);
     if (!empty($clearingId)) {
         $stmt .= ".clearingId";
         $params[] = $clearingId;
         $sql .= " AND h.clearing_event_fk = \$" . count($params);
     }
     $this->dbManager->prepare($stmt, $sql);
     $result = $this->dbManager->execute($stmt, $params);
     $highlightEntries = array();
     while ($row = $this->dbManager->fetchArray($result)) {
         $newHighlight = new Highlight(intval($row['start']), intval($row['start'] + $row['len']), Highlight::BULK, 0, 0);
         $newHighlight->setLicenseId($row['rf_fk']);
         $highlightEntries[] = $newHighlight;
     }
     $this->dbManager->freeResult($result);
     return $highlightEntries;
 }
示例#29
0
 public function getLicenseShortnamesContained(ItemTreeBounds $itemTreeBounds, $latestSuccessfulAgentIds = null, $filterLicenses = array('VOID'))
 {
     $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
     $noLicenseFoundStmt = empty($filterLicenses) ? "" : " AND rf_shortname NOT IN (" . implode(", ", array_map(function ($name) {
         return "'" . $name . "'";
     }, $filterLicenses)) . ")";
     $statementName = __METHOD__ . '.' . $uploadTreeTableName;
     $agentFilter = '';
     if (is_array($latestSuccessfulAgentIds)) {
         $agentIdSet = "{" . implode(',', $latestSuccessfulAgentIds) . "}";
         $statementName .= ".{$agentIdSet}";
         $agentFilter = " AND agent_fk=ANY('{$agentIdSet}')";
     }
     $this->dbManager->prepare($statementName, "SELECT license_ref.rf_shortname\n              FROM license_file JOIN license_ref ON license_file.rf_fk = license_ref.rf_pk\n              INNER JOIN {$uploadTreeTableName} uploadTree ON uploadTree.pfile_fk=license_file.pfile_fk\n              WHERE upload_fk=\$1\n                AND lft BETWEEN \$2 AND \$3\n                {$noLicenseFoundStmt} {$agentFilter}\n              GROUP BY rf_shortname\n              ORDER BY rf_shortname ASC");
     $result = $this->dbManager->execute($statementName, array($itemTreeBounds->getUploadId(), $itemTreeBounds->getLeft(), $itemTreeBounds->getRight()));
     $licenses = array();
     while ($row = $this->dbManager->fetchArray($result)) {
         $licenses[] = $row['rf_shortname'];
     }
     $this->dbManager->freeResult($result);
     return $licenses;
 }
示例#30
0
 /**
  * \brief Display the tag info data associated with the file.
  */
 function ShowTagInfo($Upload, $Item)
 {
     $VT = "";
     $text = _("Tag Info");
     $VT .= "<H2>{$text}</H2>\n";
     $groupId = Auth::getGroupId();
     $row = $this->uploadDao->getUploadEntry($Item);
     if (empty($row)) {
         $text = _("Invalid URL, nonexistant item");
         return "<h2>{$text} {$Item}</h2>";
     }
     $lft = $row["lft"];
     $rgt = $row["rgt"];
     $upload_pk = $row["upload_fk"];
     if (empty($lft)) {
         $text = _("Upload data is unavailable.  It needs to be unpacked.");
         return "<h2>{$text} uploadtree_pk: {$Item}</h2>";
     }
     $sql = "SELECT * FROM uploadtree INNER JOIN (SELECT * FROM tag_file,tag WHERE tag_pk = tag_fk) T\n        ON uploadtree.pfile_fk = T.pfile_fk WHERE uploadtree.upload_fk = \$1\n        AND uploadtree.lft >= \$2 AND uploadtree.rgt <= \$3 UNION SELECT * FROM uploadtree INNER JOIN\n        (SELECT * FROM tag_uploadtree,tag WHERE tag_pk = tag_fk) T ON uploadtree.uploadtree_pk = T.uploadtree_fk\n        WHERE uploadtree.upload_fk = \$1 AND uploadtree.lft >= \$2 AND uploadtree.rgt <= \$3 ORDER BY ufile_name";
     $this->dbManager->prepare(__METHOD__, $sql);
     $result = $this->dbManager->execute(__METHOD__, array($upload_pk, $lft, $rgt));
     if (pg_num_rows($result) > 0) {
         $VT .= "<table border=1>\n";
         $text = _("FileName");
         $text2 = _("Tag");
         $VT .= "<tr><th>{$text}</th><th>{$text2}</th><th></th></tr>\n";
         while ($row = pg_fetch_assoc($result)) {
             $VT .= "<tr><td align='center'>" . $row['ufile_name'] . "</td><td align='center'>" . $row['tag'] . "</td>";
             if ($this->uploadDao->isAccessible($upload_pk, $groupId)) {
                 $VT .= "<td align='center'><a href='" . Traceback_uri() . "?mod=tag&action=edit&upload={$Upload}&item=" . $row['uploadtree_pk'] . "&tag_file_pk=" . $row['tag_file_pk'] . "'>View</a></td></tr>\n";
             } else {
                 $VT .= "<td align='center'></td></tr>\n";
             }
         }
         $VT .= "</table><p>\n";
     }
     $this->dbManager->freeResult($result);
     return $VT;
 }