Пример #1
0
 private static function getConstraintCondition(ItemTreeBounds $itemTreeBounds, $constraint)
 {
     switch ($constraint) {
         case self::CONDITION_UPLOAD:
             $uploadId = $itemTreeBounds->getUploadId();
             return "upload_fk = {$uploadId}";
         case self::CONDITION_RANGE:
             $left = $itemTreeBounds->getLeft();
             $right = $itemTreeBounds->getRight();
             return "lft BETWEEN {$left} AND {$right}";
         case self::CONDITION_PLAIN_FILES:
             return '((ufile_mode & (3<<28))=0) AND pfile_fk != 0';
         default:
             throw new \InvalidArgumentException("constraint {$constraint} is not defined");
     }
 }
Пример #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
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @return array
  */
 public function getNonArtifactDescendants(ItemTreeBounds $itemTreeBounds)
 {
     $uploadExpr = '$' . (count($this->params) + 1);
     $lftExpr = '$' . (count($this->params) + 2);
     $rgtExpr = '$' . (count($this->params) + 3);
     $dbManager = $GLOBALS['container']->get('db.manager');
     $sql = "SELECT u.uploadtree_pk FROM " . $this->getDbViewName() . " u " . "WHERE u.upload_fk={$uploadExpr} AND (u.lft BETWEEN {$lftExpr} AND {$rgtExpr}) AND u.ufile_mode & (3<<28) = 0";
     $stmt = __METHOD__ . '.' . $this->getDbViewName();
     if (!$this->materialized) {
         $sql = $this->asCTE() . ' ' . $sql;
         $stmt .= '.cte';
     }
     $dbManager->prepare($stmt, $sql);
     $params = array_merge($this->params, array($itemTreeBounds->getUploadId(), $itemTreeBounds->getLeft(), $itemTreeBounds->getRight()));
     $res = $dbManager->execute($stmt, $params);
     $descendants = array();
     while ($row = $dbManager->fetchArray($res)) {
         $descendants[$row['uploadtree_pk']] = 1;
     }
     $dbManager->freeResult($res);
     return $descendants;
 }
Пример #5
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;
 }
Пример #6
0
 public function testGetRight()
 {
     assertThat($this->itemTreeBounds->getRight(), is($this->right));
 }
Пример #7
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);
 }
Пример #8
0
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $groupId
  * @param int $userId
  */
 protected function markDirectoryAsIrrelevantIfUserEdited(ItemTreeBounds $itemTreeBounds, $groupId, $userId)
 {
     $statementName = __METHOD__;
     $params = array($itemTreeBounds->getLeft(), $itemTreeBounds->getRight());
     $condition = "ut.lft BETWEEN \$1 AND \$2";
     $decisionsCte = $this->getRelevantDecisionsCte($itemTreeBounds, $groupId, $onlyCurrent = true, $statementName, $params, $condition);
     $params[] = $userId;
     $a = count($params);
     $params[] = $groupId;
     $params[] = DecisionTypes::IRRELEVANT;
     $params[] = DecisionScopes::ITEM;
     $this->dbManager->prepare($statementName, $decisionsCte . ' INSERT INTO clearing_decision (uploadtree_fk,pfile_fk,user_fk,group_fk,decision_type,scope) 
       SELECT itemid,pfile_id, $' . $a . ', $' . ($a + 1) . ', $' . ($a + 2) . ', $' . ($a + 3) . ' FROM allDecs ad WHERE type_id!=$' . ($a + 2));
     $res = $this->dbManager->execute($statementName, $params);
     $this->dbManager->freeResult($res);
 }