コード例 #1
0
 public function testMakeDecisionFromLastEventsWithNoLicenseKnownTypeAndAnExistingAddingUserEvent()
 {
     /** @var LicenseRef $licenseRef */
     list($scannerResults, $licenseRef) = $this->createScannerDetectedLicenses();
     $addedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName(), ClearingEventTypes::USER, $isRemoved = false);
     $isGlobal = true;
     $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")->with($this->itemTreeBounds)->andReturn(array());
     $this->clearingDao->shouldReceive("getRelevantClearingEvents")->with($this->itemTreeBounds, $this->groupId)->andReturn(array($licenseRef->getId() => $addedEvent));
     $clearingDecision = M::mock(ClearingDecision::classname());
     $clearingDecision->shouldReceive("getTimeStamp")->withNoArgs()->andReturn($this->timestamp - 3600);
     $clearingDecision->shouldReceive("getType")->withNoArgs()->andReturn(DecisionTypes::IRRELEVANT);
     $clearingDecision->shouldReceive("getClearingEvents")->withNoArgs()->andReturn(array());
     $this->clearingDao->shouldReceive("getRelevantClearingDecision")->with($this->itemTreeBounds, $this->groupId)->andReturn($clearingDecision);
     $eventId = 65;
     $this->clearingDao->shouldReceive("insertClearingEvent")->with($this->itemTreeBounds->getItemId(), $this->userId, $this->groupId, $addedEvent->getLicenseId(), true)->andReturn($eventId);
     $this->clearingDao->shouldReceive("createDecisionFromEvents")->once()->with($this->uploadTreeId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, DecisionScopes::REPO, array($eventId));
     $this->clearingDao->shouldReceive("removeWipClearingDecision")->never();
     $this->clearingDecisionProcessor->makeDecisionFromLastEvents($this->itemTreeBounds, $this->userId, $this->groupId, ClearingDecisionProcessor::NO_LICENSE_KNOWN_DECISION_TYPE, $isGlobal);
 }
コード例 #2
0
ファイル: UploadDao.php プロジェクト: rlintu/fossology
 /**
  * @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'];
 }
コード例 #3
0
 /**
  * @param ItemTreeBounds $itemBounds
  * @param int $userId
  * @param int $groupId
  * @param int $type
  * @param boolean $global
  * @param int[] $additionalEventIds additional event ids to include, indexed by licenseId
  */
 public function makeDecisionFromLastEvents(ItemTreeBounds $itemBounds, $userId, $groupId, $type, $global, $additionalEventIds = array())
 {
     if ($type < self::NO_LICENSE_KNOWN_DECISION_TYPE) {
         return;
     }
     $this->dbManager->begin();
     $itemId = $itemBounds->getItemId();
     $previousEvents = $this->clearingDao->getRelevantClearingEvents($itemBounds, $groupId);
     if ($type === self::NO_LICENSE_KNOWN_DECISION_TYPE) {
         $type = DecisionTypes::IDENTIFIED;
         $clearingEventIds = $this->insertClearingEventsForAgentFindings($itemBounds, $userId, $groupId, true, ClearingEventTypes::USER);
         foreach ($previousEvents as $eventId => $clearingEvent) {
             if (!in_array($eventId, $clearingEventIds) && !$clearingEvent->isRemoved()) {
                 $licenseId = $clearingEvent->getLicenseId();
                 $newEventId = $this->clearingDao->insertClearingEvent($itemBounds->getItemId(), $userId, $groupId, $licenseId, true);
                 $clearingEventIds[$licenseId] = $newEventId;
             }
         }
     } else {
         $clearingEventIds = $this->insertClearingEventsForAgentFindings($itemBounds, $userId, $groupId, false, ClearingEventTypes::AGENT, $previousEvents);
         foreach ($previousEvents as $clearingEvent) {
             $clearingEventIds[$clearingEvent->getLicenseId()] = $clearingEvent->getEventId();
         }
     }
     $currentDecision = $this->clearingDao->getRelevantClearingDecision($itemBounds, $groupId);
     $clearingEventIds = array_unique(array_merge($clearingEventIds, $additionalEventIds));
     $scope = $global ? DecisionScopes::REPO : DecisionScopes::ITEM;
     if (null === $currentDecision || $this->clearingDecisionIsDifferentFrom($currentDecision, $type, $scope, $clearingEventIds)) {
         $this->clearingDao->createDecisionFromEvents($itemBounds->getItemId(), $userId, $groupId, $type, $scope, $clearingEventIds);
     } else {
         $this->clearingDao->removeWipClearingDecision($itemId, $groupId);
     }
     $this->dbManager->commit();
 }
コード例 #4
0
ファイル: LicenseDao.php プロジェクト: DanielDobre/fossology
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $selectedAgentId
  * @param array $mask
  * @return array
  */
 public function getLicenseIdPerPfileForAgentId(ItemTreeBounds $itemTreeBounds, $selectedAgentId, $includeSubfolders = true, $nameRange = array())
 {
     $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
     $statementName = __METHOD__ . '.' . $uploadTreeTableName;
     $param = array($selectedAgentId);
     if ($includeSubfolders) {
         $param[] = $itemTreeBounds->getLeft();
         $param[] = $itemTreeBounds->getRight();
         $condition = "lft BETWEEN \$2 AND \$3";
         $statementName .= ".subfolders";
         if (!empty($nameRange)) {
             $condition .= " AND ufile_name BETWEEN \$4 and \$5";
             $param[] = $nameRange[0];
             $param[] = $nameRange[1];
         }
     } else {
         $param[] = $itemTreeBounds->getItemId();
         $condition = "realparent = \$2";
     }
     if ('uploadtree_a' == $uploadTreeTableName) {
         $param[] = $itemTreeBounds->getUploadId();
         $condition .= " AND utree.upload_fk=\$" . count($param);
     }
     $sql = "SELECT utree.pfile_fk as pfile_id,\n           license_ref.rf_pk as license_id,\n           rf_match_pct as match_percentage,\n           CAST(\$1 AS INT) AS agent_id,\n           uploadtree_pk\n         FROM license_file, license_ref, {$uploadTreeTableName} utree\n         WHERE agent_fk = \$1\n           AND license_file.rf_fk = license_ref.rf_pk\n           AND license_file.pfile_fk = utree.pfile_fk\n           AND {$condition}\n         ORDER BY match_percentage ASC";
     $this->dbManager->prepare($statementName, $sql);
     $result = $this->dbManager->execute($statementName, $param);
     $licensesPerFileId = array();
     while ($row = $this->dbManager->fetchArray($result)) {
         $licensesPerFileId[$row['pfile_id']][$row['license_id']] = $row;
     }
     $this->dbManager->freeResult($result);
     return $licensesPerFileId;
 }
コード例 #5
0
 public function testGetUploadTreeID()
 {
     assertThat($this->itemTreeBounds->getItemId(), is($this->uploadTreeId));
 }
コード例 #6
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);
 }
コード例 #7
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $userId
  */
 protected function processClearingEventsForItem(ItemTreeBounds $itemTreeBounds, $userId, $groupId, $additionalEventsFromThisJob)
 {
     $this->dbManager->begin();
     $itemId = $itemTreeBounds->getItemId();
     switch ($this->conflictStrategyId) {
         case self::FORCE_DECISION:
             $createDecision = true;
             break;
         default:
             $createDecision = !$this->clearingDecisionProcessor->hasUnhandledScannerDetectedLicenses($itemTreeBounds, $groupId, $additionalEventsFromThisJob, $this->licenseMap);
     }
     if ($createDecision) {
         $this->clearingDecisionProcessor->makeDecisionFromLastEvents($itemTreeBounds, $userId, $groupId, DecisionTypes::IDENTIFIED, $this->decisionIsGlobal, $additionalEventsFromThisJob);
     } else {
         foreach ($additionalEventsFromThisJob as $eventId) {
             $this->clearingDao->copyEventIdTo($eventId, $itemId, $userId, $groupId);
         }
         $this->clearingDao->markDecisionAsWip($itemId, $userId, $groupId);
     }
     $this->heartbeat(1);
     $this->dbManager->commit();
 }
コード例 #8
0
ファイル: LicenseDao.php プロジェクト: rlintu/fossology
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param Array(int) $selectedAgentIds
  * @param bool $includeSubFolders
  * @param String $excluding
  * @param bool $ignore ignore files without license
  * @return array
  */
 public function getLicensesPerFileNameForAgentId(ItemTreeBounds $itemTreeBounds, $selectedAgentIds = null, $includeSubfolders = true, $excluding = '', $ignore = false)
 {
     $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName();
     $statementName = __METHOD__ . '.' . $uploadTreeTableName;
     $param = array();
     $condition = " (ufile_mode & (1<<28)) = 0";
     if ($includeSubfolders) {
         $param[] = $itemTreeBounds->getLeft();
         $param[] = $itemTreeBounds->getRight();
         $condition .= " AND lft BETWEEN \$1 AND \$2";
         $statementName .= ".subfolders";
     } else {
         $param[] = $itemTreeBounds->getItemId();
         $condition .= " AND realparent = \$1";
     }
     if ('uploadtree_a' == $uploadTreeTableName) {
         $param[] = $itemTreeBounds->getUploadId();
         $condition .= " AND upload_fk=\$" . count($param);
     }
     $agentSelect = "";
     if ($selectedAgentIds !== null) {
         $statementName .= "." . count($selectedAgentIds) . "agents";
         $agentSelect = "WHERE agent_fk IS NULL";
         foreach ($selectedAgentIds as $selectedAgentId) {
             $param[] = $selectedAgentId;
             $agentSelect .= " OR agent_fk = \$" . count($param);
         }
     }
     $sql = "\nSELECT ufile_name, lft, rgt, ufile_mode,\n       rf_shortname, agent_fk\nFROM (SELECT\n        ufile_name,\n        lft, rgt, ufile_mode, pfile_fk\n      FROM {$uploadTreeTableName}\n      WHERE {$condition}) AS subselect1\nLEFT JOIN (SELECT rf_shortname,pfile_fk,agent_fk\n           FROM license_file, license_ref\n           WHERE rf_fk = rf_pk) AS subselect2\n  ON subselect1.pfile_fk = subselect2.pfile_fk\n{$agentSelect}\nORDER BY lft asc\n";
     $this->dbManager->prepare($statementName, $sql);
     $result = $this->dbManager->execute($statementName, $param);
     $licensesPerFileName = array();
     $row = $this->dbManager->fetchArray($result);
     $pathStack = array($row['ufile_name']);
     $rgtStack = array($row['rgt']);
     $lastLft = $row['lft'];
     $path = implode($pathStack, '/');
     $this->addToLicensesPerFileName($licensesPerFileName, $path, $row, $ignore);
     while ($row = $this->dbManager->fetchArray($result)) {
         if (!empty($excluding) && false !== strpos("/{$row['ufile_name']}/", $excluding)) {
             $lastLft = $row['rgt'] + 1;
             continue;
         }
         if ($row['lft'] < $lastLft) {
             continue;
         }
         $this->updateStackState($pathStack, $rgtStack, $lastLft, $row);
         $path = implode($pathStack, '/');
         $this->addToLicensesPerFileName($licensesPerFileName, $path, $row, $ignore);
     }
     $this->dbManager->freeResult($result);
     return array_reverse($licensesPerFileName);
 }
コード例 #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());
     }
     $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;
 }
コード例 #10
0
ファイル: Item.php プロジェクト: DanielDobre/fossology
 /**
  * @return int
  */
 public function getId()
 {
     return $this->itemTreeBounds->getItemId();
 }
コード例 #11
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;
 }
コード例 #12
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;
 }
コード例 #13
0
ファイル: ClearingDao.php プロジェクト: rlintu/fossology
 /**
  * @param ItemTreeBounds $itemTreeBound
  * @param int $groupId
  * @param boolean $onlyTried
  * @return array[] where array has keys ("bulkId","id","text","matched","tried","removedLicenses","addedLicenses")
  */
 public function getBulkHistory(ItemTreeBounds $itemTreeBound, $groupId, $onlyTried = true)
 {
     $uploadTreeTableName = $itemTreeBound->getUploadTreeTableName();
     $itemId = $itemTreeBound->getItemId();
     $uploadId = $itemTreeBound->getUploadId();
     $left = $itemTreeBound->getLeft();
     $params = array($uploadId, $itemId, $left, $groupId);
     $stmt = __METHOD__ . "." . $uploadTreeTableName;
     $triedExpr = "\$3 between ut2.lft and ut2.rgt";
     $triedFilter = "";
     if ($onlyTried) {
         $triedFilter = "and " . $triedExpr;
         $stmt .= ".tried";
     }
     $sql = "WITH alltried AS (\n            SELECT lr.lrb_pk, ce.clearing_event_pk ce_pk, lr.rf_text, ce.uploadtree_fk,\n              {$triedExpr} AS tried\n            FROM license_ref_bulk lr\n              LEFT JOIN highlight_bulk h ON lrb_fk = lrb_pk\n              LEFT JOIN clearing_event ce ON ce.clearing_event_pk = h.clearing_event_fk\n              LEFT JOIN {$uploadTreeTableName} ut ON ut.uploadtree_pk = ce.uploadtree_fk\n              INNER JOIN {$uploadTreeTableName} ut2 ON ut2.uploadtree_pk = lr.uploadtree_fk\n            WHERE ut2.upload_fk = \$1 AND lr.group_fk = \$4\n              {$triedFilter}\n              ORDER BY lr.lrb_pk\n            ), aggregated_tried AS (\n            SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text AS text, tried, matched\n            FROM (\n              SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text, tried, true AS matched FROM alltried WHERE uploadtree_fk = \$2\n              UNION ALL\n              SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text, tried, false AS matched FROM alltried WHERE uploadtree_fk != \$2 OR uploadtree_fk IS NULL\n            ) AS result ORDER BY lrb_pk, matched DESC)\n            SELECT lrb_pk, text, rf_shortname, removing, tried, ce_pk, matched\n            FROM aggregated_tried\n              INNER JOIN license_set_bulk lsb ON lsb.lrb_fk = lrb_pk\n              INNER JOIN license_ref lrf ON lsb.rf_fk = lrf.rf_pk\n            ORDER BY lrb_pk";
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt, $params);
     $bulks = array();
     while ($row = $this->dbManager->fetchArray($res)) {
         $bulkRun = $row['lrb_pk'];
         if (!array_key_exists($bulkRun, $bulks)) {
             $bulks[$bulkRun] = array("bulkId" => $row['lrb_pk'], "id" => $row['ce_pk'], "text" => $row['text'], "matched" => $this->dbManager->booleanFromDb($row['matched']), "tried" => $this->dbManager->booleanFromDb($row['tried']), "removedLicenses" => array(), "addedLicenses" => array());
         }
         $key = $this->dbManager->booleanFromDb($row['removing']) ? 'removedLicenses' : 'addedLicenses';
         $bulks[$bulkRun][$key][] = $row['rf_shortname'];
     }
     $this->dbManager->freeResult($res);
     return $bulks;
 }
コード例 #14
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $groupId
  * @param boolean $orderAscending
  * @return array
  */
 protected function getCurrentSelectedLicensesTableData(ItemTreeBounds $itemTreeBounds, $groupId, $orderAscending)
 {
     $uploadTreeId = $itemTreeBounds->getItemId();
     $uploadId = $itemTreeBounds->getUploadId();
     $uberUri = Traceback_uri() . "?mod=view-license" . Traceback_parm_keep(array('upload', 'folder'));
     list($addedClearingResults, $removedLicenses) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId, LicenseMap::CONCLUSION);
     $licenseEventTypes = new ClearingEventTypes();
     $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId);
     $table = array();
     /* @var $clearingResult ClearingResult */
     foreach ($addedClearingResults as $licenseShortName => $clearingResult) {
         $licenseId = $clearingResult->getLicenseId();
         $types = $this->getAgentInfo($clearingResult, $uberUri, $uploadTreeId);
         $reportInfo = "";
         $comment = "";
         if ($clearingResult->hasClearingEvent()) {
             $licenseDecisionEvent = $clearingResult->getClearingEvent();
             $types[] = $this->getEventInfo($licenseDecisionEvent, $uberUri, $uploadTreeId, $licenseEventTypes);
             $reportInfo = $licenseDecisionEvent->getReportinfo();
             $comment = $licenseDecisionEvent->getComment();
         }
         $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef());
         $actionLink = "<a href=\"javascript:;\" onclick=\"removeLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img class=\"delete\" src=\"images/space_16.png\" alt=\"\"/></a>";
         if (in_array($clearingResult->getLicenseId(), $mainLicIds)) {
             $tooltip = _('This is a main license for the upload. Click to discard selection.');
             $actionLink .= " <a href=\"javascript:;\" onclick=\"removeMainLicense({$uploadId}, {$licenseId});\"><img src=\"images/icons/star_filled_16.png\" alt=\"mainLicense\" title=\"{$tooltip}\" border=\"0\"/></a>";
         } else {
             $tooltip = _('Click to select this as a main license for the upload.');
             $actionLink .= " <a href=\"javascript:;\" onclick=\"makeMainLicense({$uploadId}, {$licenseId});\"><img src=\"images/icons/star_16.png\" alt=\"noMainLicense\" title=\"{$tooltip}\" border=\"0\"/></a>";
         }
         $reportInfoField = nl2br(htmlspecialchars($reportInfo));
         $commentField = nl2br(htmlspecialchars($comment));
         $id = "{$uploadTreeId},{$licenseId}";
         $table[$licenseShortName] = array('DT_RowId' => $id, '0' => $licenseShortNameWithLink, '1' => implode("<br/>", $types), '2' => $reportInfoField, '3' => $commentField, '4' => $actionLink);
     }
     foreach ($removedLicenses as $licenseShortName => $clearingResult) {
         if ($clearingResult->getAgentDecisionEvents()) {
             $agents = $this->getAgentInfo($clearingResult, $uberUri, $uploadTreeId);
             $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef());
             $licenseId = $clearingResult->getLicenseId();
             $actionLink = "<a href=\"javascript:;\" onclick=\"addLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img class=\"add\" src=\"images/space_16.png\" alt=\"\"/></a>";
             $filled = in_array($clearingResult->getLicenseId(), $mainLicIds) ? 'filled_' : '';
             $actionLink .= ' <img src="images/icons/star_' . $filled . '16.png" alt="mainLicense"/>';
             $idArray = array($uploadTreeId, $licenseId);
             $id = implode(',', $idArray);
             $table[$licenseShortName] = array('DT_RowId' => $id, 'DT_RowClass' => 'removed', '0' => $licenseShortNameWithLink, '1' => implode("<br/>", $agents), '2' => "-", '3' => "-", '4' => $actionLink);
         }
     }
     $valueTable = array_values($this->sortByKeys($table, $orderAscending));
     return $valueTable;
 }