Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/query/DifferentialRevisionQuery.php
| Show First 20 Lines • Show All 536 Lines • ▼ Show 20 Lines | |||||
| /* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| private function buildJoinsClause($conn_r) { | private function buildJoinsClause(AphrontDatabaseConnection $conn) { | ||||
| $joins = array(); | $joins = array(); | ||||
| if ($this->pathIDs) { | if ($this->pathIDs) { | ||||
| $path_table = new DifferentialAffectedPath(); | $path_table = new DifferentialAffectedPath(); | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'JOIN %T p ON p.revisionID = r.id', | 'JOIN %T p ON p.revisionID = r.id', | ||||
| $path_table->getTableName()); | $path_table->getTableName()); | ||||
| } | } | ||||
| if ($this->commitHashes) { | if ($this->commitHashes) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'JOIN %T hash_rel ON hash_rel.revisionID = r.id', | 'JOIN %T hash_rel ON hash_rel.revisionID = r.id', | ||||
| ArcanistDifferentialRevisionHash::TABLE_NAME); | ArcanistDifferentialRevisionHash::TABLE_NAME); | ||||
| } | } | ||||
| if ($this->ccs) { | if ($this->ccs) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'JOIN %T e_ccs ON e_ccs.src = r.phid '. | 'JOIN %T e_ccs ON e_ccs.src = r.phid '. | ||||
| 'AND e_ccs.type = %s '. | 'AND e_ccs.type = %s '. | ||||
| 'AND e_ccs.dst in (%Ls)', | 'AND e_ccs.dst in (%Ls)', | ||||
| PhabricatorEdgeConfig::TABLE_NAME_EDGE, | PhabricatorEdgeConfig::TABLE_NAME_EDGE, | ||||
| PhabricatorObjectHasSubscriberEdgeType::EDGECONST, | PhabricatorObjectHasSubscriberEdgeType::EDGECONST, | ||||
| $this->ccs); | $this->ccs); | ||||
| } | } | ||||
| if ($this->reviewers) { | if ($this->reviewers) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'JOIN %T reviewer ON reviewer.revisionPHID = r.phid | 'JOIN %T reviewer ON reviewer.revisionPHID = r.phid | ||||
| AND reviewer.reviewerStatus != %s | AND reviewer.reviewerStatus != %s | ||||
| AND reviewer.reviewerPHID in (%Ls)', | AND reviewer.reviewerPHID in (%Ls)', | ||||
| id(new DifferentialReviewer())->getTableName(), | id(new DifferentialReviewer())->getTableName(), | ||||
| DifferentialReviewerStatus::STATUS_RESIGNED, | DifferentialReviewerStatus::STATUS_RESIGNED, | ||||
| $this->reviewers); | $this->reviewers); | ||||
| } | } | ||||
| if ($this->draftAuthors) { | if ($this->draftAuthors) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'JOIN %T has_draft ON has_draft.srcPHID = r.phid | 'JOIN %T has_draft ON has_draft.srcPHID = r.phid | ||||
| AND has_draft.type = %s | AND has_draft.type = %s | ||||
| AND has_draft.dstPHID IN (%Ls)', | AND has_draft.dstPHID IN (%Ls)', | ||||
| PhabricatorEdgeConfig::TABLE_NAME_EDGE, | PhabricatorEdgeConfig::TABLE_NAME_EDGE, | ||||
| PhabricatorObjectHasDraftEdgeType::EDGECONST, | PhabricatorObjectHasDraftEdgeType::EDGECONST, | ||||
| $this->draftAuthors); | $this->draftAuthors); | ||||
| } | } | ||||
| if ($this->commitPHIDs) { | if ($this->commitPHIDs) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'JOIN %T commits ON commits.revisionID = r.id', | 'JOIN %T commits ON commits.revisionID = r.id', | ||||
| DifferentialRevision::TABLE_COMMIT); | DifferentialRevision::TABLE_COMMIT); | ||||
| } | } | ||||
| $joins[] = $this->buildJoinClauseParts($conn_r); | $joins[] = $this->buildJoinClauseParts($conn); | ||||
| return $this->formatJoinClause($joins); | return $this->formatJoinClause($conn, $joins); | ||||
| } | } | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClause(AphrontDatabaseConnection $conn) { | ||||
| $where = array(); | $where = array(); | ||||
| if ($this->pathIDs) { | if ($this->pathIDs) { | ||||
| $path_clauses = array(); | $path_clauses = array(); | ||||
| $repo_info = igroup($this->pathIDs, 'repositoryID'); | $repo_info = igroup($this->pathIDs, 'repositoryID'); | ||||
| foreach ($repo_info as $repository_id => $paths) { | foreach ($repo_info as $repository_id => $paths) { | ||||
| $path_clauses[] = qsprintf( | $path_clauses[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| '(p.repositoryID = %d AND p.pathID IN (%Ld))', | '(p.repositoryID = %d AND p.pathID IN (%Ld))', | ||||
| $repository_id, | $repository_id, | ||||
| ipull($paths, 'pathID')); | ipull($paths, 'pathID')); | ||||
| } | } | ||||
| $path_clauses = '('.implode(' OR ', $path_clauses).')'; | $path_clauses = qsprintf($conn, '%LO', $path_clauses); | ||||
| $where[] = $path_clauses; | $where[] = $path_clauses; | ||||
| } | } | ||||
| if ($this->authors) { | if ($this->authors) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.authorPHID IN (%Ls)', | 'r.authorPHID IN (%Ls)', | ||||
| $this->authors); | $this->authors); | ||||
| } | } | ||||
| if ($this->revIDs) { | if ($this->revIDs) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.id IN (%Ld)', | 'r.id IN (%Ld)', | ||||
| $this->revIDs); | $this->revIDs); | ||||
| } | } | ||||
| if ($this->repositoryPHIDs) { | if ($this->repositoryPHIDs) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.repositoryPHID IN (%Ls)', | 'r.repositoryPHID IN (%Ls)', | ||||
| $this->repositoryPHIDs); | $this->repositoryPHIDs); | ||||
| } | } | ||||
| if ($this->commitHashes) { | if ($this->commitHashes) { | ||||
| $hash_clauses = array(); | $hash_clauses = array(); | ||||
| foreach ($this->commitHashes as $info) { | foreach ($this->commitHashes as $info) { | ||||
| list($type, $hash) = $info; | list($type, $hash) = $info; | ||||
| $hash_clauses[] = qsprintf( | $hash_clauses[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| '(hash_rel.type = %s AND hash_rel.hash = %s)', | '(hash_rel.type = %s AND hash_rel.hash = %s)', | ||||
| $type, | $type, | ||||
| $hash); | $hash); | ||||
| } | } | ||||
| $hash_clauses = '('.implode(' OR ', $hash_clauses).')'; | $hash_clauses = qsprintf($conn, '%LO', $hash_clauses); | ||||
| $where[] = $hash_clauses; | $where[] = $hash_clauses; | ||||
| } | } | ||||
| if ($this->commitPHIDs) { | if ($this->commitPHIDs) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'commits.commitPHID IN (%Ls)', | 'commits.commitPHID IN (%Ls)', | ||||
| $this->commitPHIDs); | $this->commitPHIDs); | ||||
| } | } | ||||
| if ($this->phids) { | if ($this->phids) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.phid IN (%Ls)', | 'r.phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->branches) { | if ($this->branches) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.branchName in (%Ls)', | 'r.branchName in (%Ls)', | ||||
| $this->branches); | $this->branches); | ||||
| } | } | ||||
| if ($this->updatedEpochMin !== null) { | if ($this->updatedEpochMin !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.dateModified >= %d', | 'r.dateModified >= %d', | ||||
| $this->updatedEpochMin); | $this->updatedEpochMin); | ||||
| } | } | ||||
| if ($this->updatedEpochMax !== null) { | if ($this->updatedEpochMax !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.dateModified <= %d', | 'r.dateModified <= %d', | ||||
| $this->updatedEpochMax); | $this->updatedEpochMax); | ||||
| } | } | ||||
| if ($this->createdEpochMin !== null) { | if ($this->createdEpochMin !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.dateCreated >= %d', | 'r.dateCreated >= %d', | ||||
| $this->createdEpochMin); | $this->createdEpochMin); | ||||
| } | } | ||||
| if ($this->createdEpochMax !== null) { | if ($this->createdEpochMax !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.dateCreated <= %d', | 'r.dateCreated <= %d', | ||||
| $this->createdEpochMax); | $this->createdEpochMax); | ||||
| } | } | ||||
| if ($this->statuses !== null) { | if ($this->statuses !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.status in (%Ls)', | 'r.status in (%Ls)', | ||||
| $this->statuses); | $this->statuses); | ||||
| } | } | ||||
| if ($this->isOpen !== null) { | if ($this->isOpen !== null) { | ||||
| if ($this->isOpen) { | if ($this->isOpen) { | ||||
| $statuses = DifferentialLegacyQuery::getModernValues( | $statuses = DifferentialLegacyQuery::getModernValues( | ||||
| DifferentialLegacyQuery::STATUS_OPEN); | DifferentialLegacyQuery::STATUS_OPEN); | ||||
| } else { | } else { | ||||
| $statuses = DifferentialLegacyQuery::getModernValues( | $statuses = DifferentialLegacyQuery::getModernValues( | ||||
| DifferentialLegacyQuery::STATUS_CLOSED); | DifferentialLegacyQuery::STATUS_CLOSED); | ||||
| } | } | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'r.status in (%Ls)', | 'r.status in (%Ls)', | ||||
| $statuses); | $statuses); | ||||
| } | } | ||||
| $where[] = $this->buildWhereClauseParts($conn_r); | $where[] = $this->buildWhereClauseParts($conn); | ||||
| return $this->formatWhereClause($where); | |||||
| return $this->formatWhereClause($conn, $where); | |||||
| } | } | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| protected function shouldGroupQueryResultRows() { | protected function shouldGroupQueryResultRows() { | ||||
| ▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines | |||||