コード例 #1
0
 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn)
 {
     $where = parent::buildWhereClauseParts($conn);
     if ($this->repositoryPHIDs !== null) {
         $map_repositories = id(new PhabricatorRepositoryQuery())->setViewer($this->getViewer())->withPHIDs($this->repositoryPHIDs)->execute();
         if (!$map_repositories) {
             throw new PhabricatorEmptyQueryException();
         }
         $repository_ids = mpull($map_repositories, 'getID');
         if ($this->repositoryIDs !== null) {
             $repository_ids = array_merge($repository_ids, $this->repositoryIDs);
         }
         $this->withRepositoryIDs($repository_ids);
     }
     if ($this->ids !== null) {
         $where[] = qsprintf($conn, 'commit.id IN (%Ld)', $this->ids);
     }
     if ($this->phids !== null) {
         $where[] = qsprintf($conn, 'commit.phid IN (%Ls)', $this->phids);
     }
     if ($this->repositoryIDs !== null) {
         $where[] = qsprintf($conn, 'commit.repositoryID IN (%Ld)', $this->repositoryIDs);
     }
     if ($this->authorPHIDs !== null) {
         $where[] = qsprintf($conn, 'commit.authorPHID IN (%Ls)', $this->authorPHIDs);
     }
     if ($this->epochMin !== null) {
         $where[] = qsprintf($conn, 'commit.epoch >= %d', $this->epochMin);
     }
     if ($this->epochMax !== null) {
         $where[] = qsprintf($conn, 'commit.epoch <= %d', $this->epochMax);
     }
     if ($this->importing !== null) {
         if ($this->importing) {
             $where[] = qsprintf($conn, '(commit.importStatus & %d) != %d', PhabricatorRepositoryCommit::IMPORTED_ALL, PhabricatorRepositoryCommit::IMPORTED_ALL);
         } else {
             $where[] = qsprintf($conn, '(commit.importStatus & %d) = %d', PhabricatorRepositoryCommit::IMPORTED_ALL, PhabricatorRepositoryCommit::IMPORTED_ALL);
         }
     }
     if ($this->identifiers !== null) {
         $min_unqualified = PhabricatorRepository::MINIMUM_UNQUALIFIED_HASH;
         $min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH;
         $refs = array();
         $bare = array();
         foreach ($this->identifiers as $identifier) {
             $matches = null;
             preg_match('/^(?:[rR]([A-Z]+:?|[0-9]+:))?(.*)$/', $identifier, $matches);
             $repo = nonempty(rtrim($matches[1], ':'), null);
             $commit_identifier = nonempty($matches[2], null);
             if ($repo === null) {
                 if ($this->defaultRepository) {
                     $repo = $this->defaultRepository->getPHID();
                 }
             }
             if ($repo === null) {
                 if (strlen($commit_identifier) < $min_unqualified) {
                     continue;
                 }
                 $bare[] = $commit_identifier;
             } else {
                 $refs[] = array('repository' => $repo, 'identifier' => $commit_identifier);
             }
         }
         $sql = array();
         foreach ($bare as $identifier) {
             $sql[] = qsprintf($conn, '(commit.commitIdentifier LIKE %> AND ' . 'LENGTH(commit.commitIdentifier) = 40)', $identifier);
         }
         if ($refs) {
             $repositories = ipull($refs, 'repository');
             $repos = id(new PhabricatorRepositoryQuery())->setViewer($this->getViewer())->withIdentifiers($repositories);
             $repos->execute();
             $repos = $repos->getIdentifierMap();
             foreach ($refs as $key => $ref) {
                 $repo = idx($repos, $ref['repository']);
                 if (!$repo) {
                     continue;
                 }
                 if ($repo->isSVN()) {
                     if (!ctype_digit((string) $ref['identifier'])) {
                         continue;
                     }
                     $sql[] = qsprintf($conn, '(commit.repositoryID = %d AND commit.commitIdentifier = %s)', $repo->getID(), (int) $ref['identifier']);
                 } else {
                     if (strlen($ref['identifier']) < $min_qualified) {
                         continue;
                     }
                     $identifier = $ref['identifier'];
                     if (strlen($identifier) == 40) {
                         // MySQL seems to do slightly better with this version if the
                         // clause, so issue it if we have a full commit hash.
                         $sql[] = qsprintf($conn, '(commit.repositoryID = %d
               AND commit.commitIdentifier = %s)', $repo->getID(), $identifier);
                     } else {
                         $sql[] = qsprintf($conn, '(commit.repositoryID = %d
               AND commit.commitIdentifier LIKE %>)', $repo->getID(), $identifier);
                     }
                 }
             }
         }
         if (!$sql) {
             // If we discarded all possible identifiers (e.g., they all referenced
             // bogus repositories or were all too short), make sure the query finds
             // nothing.
             throw new PhabricatorEmptyQueryException(pht('No commit identifiers.'));
         }
         $where[] = '(' . implode(' OR ', $sql) . ')';
     }
     if ($this->auditIDs !== null) {
         $where[] = qsprintf($conn, 'audit.id IN (%Ld)', $this->auditIDs);
     }
     if ($this->auditorPHIDs !== null) {
         $where[] = qsprintf($conn, 'audit.auditorPHID IN (%Ls)', $this->auditorPHIDs);
     }
     if ($this->needsAuditByPHIDs !== null) {
         $where[] = qsprintf($conn, 'needs.auditorPHID IN (%Ls)', $this->needsAuditByPHIDs);
     }
     $status = $this->auditStatus;
     if ($status !== null) {
         switch ($status) {
             case self::AUDIT_STATUS_PARTIAL:
                 $where[] = qsprintf($conn, 'commit.auditStatus = %d', PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED);
                 break;
             case self::AUDIT_STATUS_ACCEPTED:
                 $where[] = qsprintf($conn, 'commit.auditStatus = %d', PhabricatorAuditCommitStatusConstants::FULLY_AUDITED);
                 break;
             case self::AUDIT_STATUS_CONCERN:
                 $where[] = qsprintf($conn, 'status.auditStatus = %s', PhabricatorAuditStatusConstants::CONCERNED);
                 break;
             case self::AUDIT_STATUS_OPEN:
                 $where[] = qsprintf($conn, 'status.auditStatus in (%Ls)', PhabricatorAuditStatusConstants::getOpenStatusConstants());
                 break;
             case self::AUDIT_STATUS_ANY:
                 break;
             default:
                 $valid = array(self::AUDIT_STATUS_ANY, self::AUDIT_STATUS_OPEN, self::AUDIT_STATUS_CONCERN, self::AUDIT_STATUS_ACCEPTED, self::AUDIT_STATUS_PARTIAL);
                 throw new Exception(pht("Unknown audit status '%s'! Valid statuses are: %s.", $status, implode(', ', $valid)));
         }
     }
     return $where;
 }
コード例 #2
0
 protected function buildWhereClause(AphrontDatabaseConnection $conn_r)
 {
     $where = array();
     if ($this->repositoryPHIDs !== null) {
         $map_repositories = id(new PhabricatorRepositoryQuery())->setViewer($this->getViewer())->withPHIDs($this->repositoryPHIDs)->execute();
         if (!$map_repositories) {
             throw new PhabricatorEmptyQueryException();
         }
         $repository_ids = mpull($map_repositories, 'getID');
         if ($this->repositoryIDs !== null) {
             $repository_ids = array_merge($repository_ids, $this->repositoryIDs);
         }
         $this->withRepositoryIDs($repository_ids);
     }
     if ($this->ids !== null) {
         $where[] = qsprintf($conn_r, 'commit.id IN (%Ld)', $this->ids);
     }
     if ($this->phids !== null) {
         $where[] = qsprintf($conn_r, 'commit.phid IN (%Ls)', $this->phids);
     }
     if ($this->repositoryIDs !== null) {
         $where[] = qsprintf($conn_r, 'commit.repositoryID IN (%Ld)', $this->repositoryIDs);
     }
     if ($this->authorPHIDs !== null) {
         $where[] = qsprintf($conn_r, 'commit.authorPHID IN (%Ls)', $this->authorPHIDs);
     }
     if ($this->epochMin !== null) {
         $where[] = qsprintf($conn_r, 'commit.epoch >= %d', $this->epochMin);
     }
     if ($this->epochMax !== null) {
         $where[] = qsprintf($conn_r, 'commit.epoch <= %d', $this->epochMax);
     }
     if ($this->importing !== null) {
         if ($this->importing) {
             $where[] = qsprintf($conn_r, '(commit.importStatus & %d) != %d', PhabricatorRepositoryCommit::IMPORTED_ALL, PhabricatorRepositoryCommit::IMPORTED_ALL);
         } else {
             $where[] = qsprintf($conn_r, '(commit.importStatus & %d) = %d', PhabricatorRepositoryCommit::IMPORTED_ALL, PhabricatorRepositoryCommit::IMPORTED_ALL);
         }
     }
     if ($this->identifiers !== null) {
         $min_unqualified = PhabricatorRepository::MINIMUM_UNQUALIFIED_HASH;
         $min_qualified = PhabricatorRepository::MINIMUM_QUALIFIED_HASH;
         $refs = array();
         $bare = array();
         foreach ($this->identifiers as $identifier) {
             $matches = null;
             preg_match('/^(?:[rR]([A-Z]+:?|[0-9]+:))?(.*)$/', $identifier, $matches);
             $repo = nonempty(rtrim($matches[1], ':'), null);
             $commit_identifier = nonempty($matches[2], null);
             if ($repo === null) {
                 if ($this->defaultRepository) {
                     $repo = $this->defaultRepository->getCallsign();
                 }
             }
             if ($repo === null) {
                 if (strlen($commit_identifier) < $min_unqualified) {
                     continue;
                 }
                 $bare[] = $commit_identifier;
             } else {
                 $refs[] = array('callsign' => $repo, 'identifier' => $commit_identifier);
             }
         }
         $sql = array();
         foreach ($bare as $identifier) {
             $sql[] = qsprintf($conn_r, '(commit.commitIdentifier LIKE %> AND ' . 'LENGTH(commit.commitIdentifier) = 40)', $identifier);
         }
         if ($refs) {
             $callsigns = ipull($refs, 'callsign');
             $repos = id(new PhabricatorRepositoryQuery())->setViewer($this->getViewer())->withIdentifiers($callsigns);
             $repos->execute();
             $repos = $repos->getIdentifierMap();
             foreach ($refs as $key => $ref) {
                 $repo = idx($repos, $ref['callsign']);
                 if (!$repo) {
                     continue;
                 }
                 if ($repo->isSVN()) {
                     if (!ctype_digit($ref['identifier'])) {
                         continue;
                     }
                     $sql[] = qsprintf($conn_r, '(commit.repositoryID = %d AND commit.commitIdentifier = %s)', $repo->getID(), (int) $ref['identifier']);
                 } else {
                     if (strlen($ref['identifier']) < $min_qualified) {
                         continue;
                     }
                     $sql[] = qsprintf($conn_r, '(commit.repositoryID = %d AND commit.commitIdentifier LIKE %>)', $repo->getID(), $ref['identifier']);
                 }
             }
         }
         if (!$sql) {
             // If we discarded all possible identifiers (e.g., they all referenced
             // bogus repositories or were all too short), make sure the query finds
             // nothing.
             throw new PhabricatorEmptyQueryException(pht('No commit identifiers.'));
         }
         $where[] = '(' . implode(' OR ', $sql) . ')';
     }
     if ($this->auditIDs !== null) {
         $where[] = qsprintf($conn_r, 'audit.id IN (%Ld)', $this->auditIDs);
     }
     if ($this->auditorPHIDs !== null) {
         $where[] = qsprintf($conn_r, 'audit.auditorPHID IN (%Ls)', $this->auditorPHIDs);
     }
     if ($this->auditAwaitingUser) {
         $awaiting_user_phid = $this->auditAwaitingUser->getPHID();
         // Exclude package and project audits associated with commits where
         // the user is the author.
         $where[] = qsprintf($conn_r, '(commit.authorPHID IS NULL OR commit.authorPHID != %s)
       OR (audit.auditorPHID = %s)', $awaiting_user_phid, $awaiting_user_phid);
     }
     $status = $this->auditStatus;
     if ($status !== null) {
         switch ($status) {
             case self::AUDIT_STATUS_PARTIAL:
                 $where[] = qsprintf($conn_r, 'commit.auditStatus = %d', PhabricatorAuditCommitStatusConstants::PARTIALLY_AUDITED);
                 break;
             case self::AUDIT_STATUS_ACCEPTED:
                 $where[] = qsprintf($conn_r, 'commit.auditStatus = %d', PhabricatorAuditCommitStatusConstants::FULLY_AUDITED);
                 break;
             case self::AUDIT_STATUS_CONCERN:
                 $where[] = qsprintf($conn_r, 'audit.auditStatus = %s', PhabricatorAuditStatusConstants::CONCERNED);
                 break;
             case self::AUDIT_STATUS_OPEN:
                 $where[] = qsprintf($conn_r, 'audit.auditStatus in (%Ls)', PhabricatorAuditStatusConstants::getOpenStatusConstants());
                 if ($this->auditAwaitingUser) {
                     $where[] = qsprintf($conn_r, 'awaiting.auditStatus IS NULL OR awaiting.auditStatus != %s', PhabricatorAuditStatusConstants::RESIGNED);
                 }
                 break;
             case self::AUDIT_STATUS_ANY:
                 break;
             default:
                 $valid = array(self::AUDIT_STATUS_ANY, self::AUDIT_STATUS_OPEN, self::AUDIT_STATUS_CONCERN, self::AUDIT_STATUS_ACCEPTED, self::AUDIT_STATUS_PARTIAL);
                 throw new Exception(pht("Unknown audit status '%s'! Valid statuses are: %s.", $status, implode(', ', $valid)));
         }
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($where);
 }
コード例 #3
0
 private function buildWhereClause($conn_r)
 {
     $where = array();
     if ($this->commitPHIDs) {
         $where[] = qsprintf($conn_r, 'req.commitPHID IN (%Ls)', $this->commitPHIDs);
     }
     if ($this->auditorPHIDs) {
         $where[] = qsprintf($conn_r, 'req.auditorPHID IN (%Ls)', $this->auditorPHIDs);
     }
     if ($this->awaitingUser) {
         // Exclude package and project audits associated with commits where
         // the user is the author.
         $where[] = qsprintf($conn_r, '(commit.authorPHID IS NULL OR commit.authorPHID != %s)
       OR (req.auditorPHID = %s)', $this->awaitingUser->getPHID(), $this->awaitingUser->getPHID());
     }
     $status = $this->status;
     switch ($status) {
         case self::STATUS_OPEN:
             $where[] = qsprintf($conn_r, 'req.auditStatus in (%Ls)', PhabricatorAuditStatusConstants::getOpenStatusConstants());
             if ($this->awaitingUser) {
                 $where[] = qsprintf($conn_r, 'awaiting.auditStatus IS NULL OR awaiting.auditStatus != %s', PhabricatorAuditStatusConstants::RESIGNED);
             }
             break;
         case self::STATUS_ANY:
             break;
         default:
             throw new Exception("Unknown status '{$status}'!");
     }
     if ($where) {
         $where = 'WHERE (' . implode(') AND (', $where) . ')';
     } else {
         $where = '';
     }
     return $where;
 }