/**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int[] $constraints
  * @return string
  */
 private static function getUploadTreeView(ItemTreeBounds $itemTreeBounds, $constraints)
 {
     $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
     $isDefaultTable = $uploadTreeTableName == 'uploadtree_a' || $uploadTreeTableName == 'uploadtree';
     if ($isDefaultTable) {
         $constraints[] = self::CONDITION_UPLOAD;
     }
     $baseQuery = "SELECT * FROM {$uploadTreeTableName}";
     $condition = self::getConstraintsCondition($itemTreeBounds, $constraints);
     return $baseQuery . $condition;
 }
示例#2
0
 /**
  * @param string[][][] &$filesWithLicenses
  * @param ItemTreeBounds $itemTreeBounds
  */
 protected function addClearingStatus(&$filesWithLicenses, ItemTreeBounds $itemTreeBounds)
 {
     $alreadyClearedUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(), array(UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED, UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " . $itemTreeBounds->getRight() . ")", UploadTreeProxy::OPT_GROUP_ID => $this->groupId), $itemTreeBounds->getUploadTreeTableName(), 'already_cleared_uploadtree' . $itemTreeBounds->getUploadId());
     $alreadyClearedUploadTreeView->materialize();
     $filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->getNonArtifactDescendants($itemTreeBounds);
     $alreadyClearedUploadTreeView->unmaterialize();
     $uploadTreeIds = array_keys($filesWithLicenses);
     foreach ($uploadTreeIds as $uploadTreeId) {
         $filesWithLicenses[$uploadTreeId]['isCleared'] = false == array_key_exists($uploadTreeId, $filesThatShouldStillBeCleared);
     }
 }
示例#3
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param bool $isFlat plain files from sub*folders instead of folders
  * @return array
  */
 public function countNonArtifactDescendants(ItemTreeBounds $itemTreeBounds, $isFlat = true)
 {
     $stmt = __METHOD__;
     $sql = "SELECT count(*) FROM " . $itemTreeBounds->getUploadTreeTableName() . " ut " . "WHERE ut.upload_fk=\$1";
     $params = array($itemTreeBounds->getUploadId());
     if (!$isFlat) {
         $stmt = __METHOD__ . '.parent';
         $params[] = $itemTreeBounds->getItemId();
         $sql .= " AND ut.ufile_mode & (1<<28) = 0 AND ut.realparent = \$2";
     } else {
         $params[] = $itemTreeBounds->getLeft();
         $params[] = $itemTreeBounds->getRight();
         $sql .= " AND ut.ufile_mode & (3<<28) = 0 AND (ut.lft BETWEEN \$2 AND \$3)";
     }
     $descendants = $this->dbManager->getSingleRow($sql, $params);
     return $descendants['count'];
 }
示例#4
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;
 }
 public function testGetUploadTreeTableName()
 {
     assertThat($this->itemTreeBounds->getUploadTreeTableName(), is($this->uploadTreeTableName));
 }
示例#6
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);
 }
示例#7
0
 /**
  * @param $tagId
  * @param ItemTreeBounds $itemTreeBounds
  * @param $UniqueTagArray
  * @param $selectedAgentId
  * @param int $groupId
  * @param ScanJobProxy $scanJobProxy
  * @return array
  */
 private function createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy)
 {
     if (!empty($selectedAgentId)) {
         $agentName = $this->agentDao->getAgentName($selectedAgentId);
         $selectedScanners = array($agentName => $selectedAgentId);
     } else {
         $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
     }
     /** change the license result when selecting one version of nomos */
     $uploadId = $itemTreeBounds->getUploadId();
     $isFlat = isset($_GET['flatten']);
     if ($isFlat) {
         $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
     } else {
         $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->getItemId());
     }
     $descendantView = new UploadTreeProxy($uploadId, $options, $itemTreeBounds->getUploadTreeTableName(), 'uberItems');
     $vars['iTotalDisplayRecords'] = $descendantView->count();
     $columnNamesInDatabase = array($isFlat ? 'ufile_name' : 'lft');
     $defaultOrder = array(array(0, "asc"));
     $orderString = $this->getObject('utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
     $offset = GetParm('iDisplayStart', PARM_INTEGER);
     $limit = GetParm('iDisplayLength', PARM_INTEGER);
     if ($offset) {
         $orderString .= " OFFSET {$offset}";
     }
     if ($limit) {
         $orderString .= " LIMIT {$limit}";
     }
     /* Get ALL the items under this Uploadtree_pk */
     $sql = $descendantView->getDbViewQuery() . " {$orderString}";
     $dbManager = $this->getObject('db.manager');
     $dbManager->prepare($stmt = __METHOD__ . $orderString, $sql);
     $res = $dbManager->execute($stmt, $descendantView->getParams());
     $descendants = $dbManager->fetchAll($res);
     $dbManager->freeResult($res);
     /* Filter out Children that don't have tag */
     if (!empty($tagId)) {
         TagFilter($descendants, $tagId, $itemTreeBounds->getUploadTreeTableName());
     }
     if (empty($descendants)) {
         $vars['fileData'] = array();
         return $vars;
     }
     if ($isFlat) {
         $firstChild = reset($descendants);
         $lastChild = end($descendants);
         $nameRange = array($firstChild['ufile_name'], $lastChild['ufile_name']);
     } else {
         $nameRange = array();
     }
     /*******    File Listing     ************/
     $pfileLicenses = array();
     foreach ($selectedScanners as $agentName => $agentId) {
         $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange);
         foreach ($licensePerPfile as $pfile => $licenseRow) {
             foreach ($licenseRow as $licId => $row) {
                 $lic = $this->licenseProjector->getProjectedShortname($licId);
                 $pfileLicenses[$pfile][$lic][$agentName] = $row;
             }
         }
     }
     $baseUri = Traceback_uri() . '?mod=fileBrowse' . Traceback_parm_keep(array('upload', 'folder', 'show'));
     $tableData = array();
     global $Plugins;
     $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
     foreach ($descendants as $child) {
         if (empty($child)) {
             continue;
         }
         $tableData[] = $this->createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $baseUri, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds);
     }
     $vars['fileData'] = $tableData;
     return $vars;
 }
示例#8
0
 /**
  * @param string[][][] $filesWithLicenses
  * @param ItemTreeBounds $itemTreeBounds
  */
 protected function addScannerResults(&$filesWithLicenses, $itemTreeBounds)
 {
     $uploadId = $itemTreeBounds->getUploadId();
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->container->get('dao.agent'), $uploadId);
     $scanJobProxy->createAgentStatus($scannerAgents);
     $scannerIds = $scanJobProxy->getLatestSuccessfulAgentIds();
     if (empty($scannerIds)) {
         return;
     }
     $selectedScanners = '{' . implode(',', $scannerIds) . '}';
     $tableName = $itemTreeBounds->getUploadTreeTableName();
     $stmt = __METHOD__ . '.scanner_findings';
     $sql = "SELECT uploadtree_pk,rf_fk FROM {$tableName} ut, license_file\n      WHERE ut.pfile_fk=license_file.pfile_fk AND rf_fk IS NOT NULL AND agent_fk=any(\$1)";
     $param = array($selectedScanners);
     if ($tableName == 'uploadtree_a') {
         $param[] = $uploadId;
         $sql .= " AND upload_fk=\$" . count($param);
         $stmt .= $tableName;
     }
     $sql .= " GROUP BY uploadtree_pk,rf_fk";
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt, $param);
     while ($row = $this->dbManager->fetchArray($res)) {
         $reportedLicenseId = $this->licenseMap->getProjectedId($row['rf_fk']);
         $shortName = $this->licenseMap->getProjectedShortname($reportedLicenseId);
         if ($shortName != 'No_license_found' && $shortName != 'Void') {
             $filesWithLicenses[$row['uploadtree_pk']]['scanner'][] = $shortName;
             $this->includedLicenseIds[$reportedLicenseId] = $reportedLicenseId;
         }
     }
     $this->dbManager->freeResult($res);
     return "licenseInfoInFile determined by Scanners {$selectedScanners}";
 }
示例#9
0
 /**
  * @param $tagId
  * @param ItemTreeBounds $itemTreeBounds
  * @param $UniqueTagArray
  * @param $selectedAgentId
  * @param int $groupId
  * @param ScanJobProxy $scanJobProxy
  * @return array
  */
 private function createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy)
 {
     if (!empty($selectedAgentId)) {
         $agentName = $this->agentDao->getAgentName($selectedAgentId);
         $selectedScanners = array($agentName => $selectedAgentId);
     } else {
         $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
     }
     /** change the license result when selecting one version of nomos */
     $uploadId = $itemTreeBounds->getUploadId();
     $isFlat = isset($_GET['flatten']);
     if ($isFlat) {
         $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
     } else {
         $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->getItemId());
     }
     $searchMap = array();
     foreach (explode(' ', GetParm('sSearch', PARM_RAW)) as $pair) {
         $a = explode(':', $pair);
         if (count($a) == 1) {
             $searchMap['head'] = $pair;
         } else {
             $searchMap[$a[0]] = $a[1];
         }
     }
     if (array_key_exists('ext', $searchMap) && strlen($searchMap['ext']) >= 1) {
         $options[UploadTreeProxy::OPT_EXT] = $searchMap['ext'];
     }
     if (array_key_exists('head', $searchMap) && strlen($searchMap['head']) >= 1) {
         $options[UploadTreeProxy::OPT_HEAD] = $searchMap['head'];
     }
     if (($rfId = GetParm('scanFilter', PARM_INTEGER)) > 0) {
         $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners;
         $options[UploadTreeProxy::OPT_SCAN_REF] = $rfId;
     }
     if (($rfId = GetParm('conFilter', PARM_INTEGER)) > 0) {
         $options[UploadTreeProxy::OPT_GROUP_ID] = Auth::getGroupId();
         $options[UploadTreeProxy::OPT_CONCLUDE_REF] = $rfId;
     }
     $openFilter = GetParm('openCBoxFilter', PARM_RAW);
     if ($openFilter == 'true' || $openFilter == 'checked') {
         $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners;
         $options[UploadTreeProxy::OPT_GROUP_ID] = Auth::getGroupId();
         $options[UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED] = true;
     }
     $descendantView = new UploadTreeProxy($uploadId, $options, $itemTreeBounds->getUploadTreeTableName(), 'uberItems');
     $vars['iTotalDisplayRecords'] = $descendantView->count();
     $columnNamesInDatabase = array($isFlat ? 'ufile_name' : 'lft');
     $defaultOrder = array(array(0, "asc"));
     $orderString = $this->getObject('utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
     $offset = GetParm('iDisplayStart', PARM_INTEGER);
     $limit = GetParm('iDisplayLength', PARM_INTEGER);
     if ($offset) {
         $orderString .= " OFFSET {$offset}";
     }
     if ($limit) {
         $orderString .= " LIMIT {$limit}";
     }
     /* Get ALL the items under this Uploadtree_pk */
     $sql = $descendantView->getDbViewQuery() . " {$orderString}";
     $dbManager = $this->getObject('db.manager');
     $dbManager->prepare($stmt = __METHOD__ . $orderString, $sql);
     $res = $dbManager->execute($stmt, $descendantView->getParams());
     $descendants = $dbManager->fetchAll($res);
     $dbManager->freeResult($res);
     /* Filter out Children that don't have tag */
     if (!empty($tagId)) {
         TagFilter($descendants, $tagId, $itemTreeBounds->getUploadTreeTableName());
     }
     if (empty($descendants)) {
         $vars['fileData'] = array();
         return $vars;
     }
     if ($isFlat) {
         $firstChild = reset($descendants);
         $lastChild = end($descendants);
         $nameRange = array($firstChild['ufile_name'], $lastChild['ufile_name']);
     } else {
         $nameRange = array();
     }
     /*******    File Listing     ************/
     $pfileLicenses = array();
     foreach ($selectedScanners as $agentName => $agentId) {
         $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange);
         foreach ($licensePerPfile as $pfile => $licenseRow) {
             foreach ($licenseRow as $licId => $row) {
                 $lic = $this->licenseProjector->getProjectedShortname($licId);
                 $pfileLicenses[$pfile][$lic][$agentName] = $row;
             }
         }
     }
     $alreadyClearedUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(), $options = array(UploadTreeProxy::OPT_SKIP_THESE => UploadTreeProxy::OPT_SKIP_ALREADY_CLEARED, UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " . $itemTreeBounds->getRight() . ")", UploadTreeProxy::OPT_GROUP_ID => $groupId), $itemTreeBounds->getUploadTreeTableName(), $viewName = 'already_cleared_uploadtree' . $itemTreeBounds->getUploadId());
     $alreadyClearedUploadTreeView->materialize();
     if (!$isFlat) {
         $this->filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->countMaskedNonArtifactChildren($itemTreeBounds->getItemId());
     } else {
         $this->filesThatShouldStillBeCleared = $alreadyClearedUploadTreeView->getNonArtifactDescendants($itemTreeBounds);
     }
     $alreadyClearedUploadTreeView->unmaterialize();
     $noLicenseUploadTreeView = new UploadTreeProxy($itemTreeBounds->getUploadId(), $options = array(UploadTreeProxy::OPT_SKIP_THESE => "noLicense", UploadTreeProxy::OPT_ITEM_FILTER => "AND (lft BETWEEN " . $itemTreeBounds->getLeft() . " AND " . $itemTreeBounds->getRight() . ")", UploadTreeProxy::OPT_GROUP_ID => $groupId), $itemTreeBounds->getUploadTreeTableName(), $viewName = 'no_license_uploadtree' . $itemTreeBounds->getUploadId());
     $noLicenseUploadTreeView->materialize();
     if (!$isFlat) {
         $this->filesToBeCleared = $noLicenseUploadTreeView->countMaskedNonArtifactChildren($itemTreeBounds->getItemId());
     } else {
         $this->filesToBeCleared = $noLicenseUploadTreeView->getNonArtifactDescendants($itemTreeBounds);
     }
     $noLicenseUploadTreeView->unmaterialize();
     $allDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId, $isFlat);
     $editedMappedLicenses = $this->clearingFilter->filterCurrentClearingDecisions($allDecisions);
     $baseUri = Traceback_uri() . '?mod=license' . Traceback_parm_keep(array('upload', 'folder', 'show'));
     $tableData = array();
     global $Plugins;
     $ModLicView =& $Plugins[plugin_find_id("view-license")];
     $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
     foreach ($descendants as $child) {
         if (empty($child)) {
             continue;
         }
         $tableData[] = $this->createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $baseUri, $ModLicView, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds);
     }
     $vars['fileData'] = $tableData;
     return $vars;
 }
示例#10
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @return Highlight[]
  */
 public function getHighlightKeywords(ItemTreeBounds $itemTreeBounds)
 {
     $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
     $stmt = __METHOD__ . $uploadTreeTableName;
     $sql = "SELECT start,len\n             FROM highlight_keyword\n             WHERE pfile_fk = (SELECT pfile_fk FROM {$uploadTreeTableName} WHERE uploadtree_pk = \$1)";
     $this->dbManager->prepare($stmt, $sql);
     $result = $this->dbManager->execute($stmt, array($itemTreeBounds->getItemId()));
     $highlightEntries = array();
     while ($row = $this->dbManager->fetchArray($result)) {
         $highlightEntries[] = new Highlight(intval($row['start']), intval($row['start'] + $row['len']), Highlight::KEYWORD, 0, 0);
     }
     $this->dbManager->freeResult($result);
     return $highlightEntries;
 }
示例#11
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $groupId
  * @param int $userId
  */
 protected function markDirectoryAsIrrelevantIfScannerDetected(ItemTreeBounds $itemTreeBounds, $groupId, $userId)
 {
     $params = array($itemTreeBounds->getLeft(), $itemTreeBounds->getRight(), $userId, $groupId, DecisionTypes::IRRELEVANT, DecisionScopes::ITEM);
     $options = array(UploadTreeProxy::OPT_SKIP_THESE => 'noLicense', UploadTreeProxy::OPT_ITEM_FILTER => ' AND (lft BETWEEN $1 AND $2)', UploadTreeProxy::OPT_GROUP_ID => '$4');
     $uploadTreeProxy = new UploadTreeProxy($itemTreeBounds->getUploadId(), $options, $itemTreeBounds->getUploadTreeTableName());
     $statementName = __METHOD__;
     $sql = $uploadTreeProxy->asCte() . ' INSERT INTO clearing_decision (uploadtree_fk,pfile_fk,user_fk,group_fk,decision_type,scope) 
       SELECT uploadtree_pk itemid,pfile_fk pfile_id, $3, $4, $5, $6 FROM UploadTreeView';
     $this->dbManager->prepare($statementName, $sql);
     $res = $this->dbManager->execute($statementName, $params);
     $this->dbManager->freeResult($res);
 }