Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/query/DifferentialRevisionQuery.php
<?php | <?php | ||||
/** | /** | ||||
* @task config Query Configuration | * @task config Query Configuration | ||||
* @task exec Query Execution | * @task exec Query Execution | ||||
* @task internal Internals | * @task internal Internals | ||||
*/ | */ | ||||
final class DifferentialRevisionQuery | final class DifferentialRevisionQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $pathIDs = array(); | |||||
private $authors = array(); | private $authors = array(); | ||||
private $draftAuthors = array(); | private $draftAuthors = array(); | ||||
private $ccs = array(); | private $ccs = array(); | ||||
private $reviewers = array(); | private $reviewers = array(); | ||||
private $revIDs = array(); | private $revIDs = array(); | ||||
private $commitHashes = array(); | private $commitHashes = array(); | ||||
private $phids = array(); | private $phids = array(); | ||||
private $responsibles = array(); | private $responsibles = array(); | ||||
Show All 18 Lines | final class DifferentialRevisionQuery | ||||
private $needReviewers = false; | private $needReviewers = false; | ||||
private $needReviewerAuthority; | private $needReviewerAuthority; | ||||
private $needDrafts; | private $needDrafts; | ||||
private $needFlags; | private $needFlags; | ||||
/* -( Query Configuration )------------------------------------------------ */ | /* -( Query Configuration )------------------------------------------------ */ | ||||
/** | |||||
* Filter results to revisions which affect a Diffusion path ID in a given | |||||
* repository. You can call this multiple times to select revisions for | |||||
* several paths. | |||||
* | |||||
* @param int Diffusion repository ID. | |||||
* @param int Diffusion path ID. | |||||
* @return this | |||||
* @task config | |||||
*/ | |||||
public function withPath($repository_id, $path_id) { | |||||
$this->pathIDs[] = array( | |||||
'repositoryID' => $repository_id, | |||||
'pathID' => $path_id, | |||||
); | |||||
return $this; | |||||
} | |||||
/** | /** | ||||
* Find revisions affecting one or more items in a list of paths. | * Find revisions affecting one or more items in a list of paths. | ||||
* | * | ||||
* @param list<string> List of file paths. | * @param list<string> List of file paths. | ||||
* @return this | * @return this | ||||
* @task config | * @task config | ||||
*/ | */ | ||||
public function withPaths(array $paths) { | public function withPaths(array $paths) { | ||||
▲ Show 20 Lines • Show All 502 Lines • ▼ Show 20 Lines | |||||
/* -( Internals )---------------------------------------------------------- */ | /* -( Internals )---------------------------------------------------------- */ | ||||
/** | /** | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
private function buildJoinsClause(AphrontDatabaseConnection $conn) { | private function buildJoinsClause(AphrontDatabaseConnection $conn) { | ||||
$joins = array(); | $joins = array(); | ||||
if ($this->pathIDs) { | |||||
$path_table = new DifferentialAffectedPath(); | |||||
$joins[] = qsprintf( | |||||
$conn, | |||||
'JOIN %T p ON p.revisionID = r.id', | |||||
$path_table->getTableName()); | |||||
} | |||||
if ($this->paths) { | if ($this->paths) { | ||||
$path_table = new DifferentialAffectedPath(); | $path_table = new DifferentialAffectedPath(); | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn, | $conn, | ||||
'JOIN %R paths ON paths.revisionID = r.id', | 'JOIN %R paths ON paths.revisionID = r.id', | ||||
$path_table); | $path_table); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
/** | /** | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn) { | protected function buildWhereClause(AphrontDatabaseConnection $conn) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$where = array(); | $where = array(); | ||||
if ($this->pathIDs) { | |||||
$path_clauses = array(); | |||||
$repo_info = igroup($this->pathIDs, 'repositoryID'); | |||||
foreach ($repo_info as $repository_id => $paths) { | |||||
$path_clauses[] = qsprintf( | |||||
$conn, | |||||
'(p.repositoryID = %d AND p.pathID IN (%Ld))', | |||||
$repository_id, | |||||
ipull($paths, 'pathID')); | |||||
} | |||||
$path_clauses = qsprintf($conn, '%LO', $path_clauses); | |||||
$where[] = $path_clauses; | |||||
} | |||||
if ($this->paths !== null) { | if ($this->paths !== null) { | ||||
$paths = $this->paths; | $paths = $this->paths; | ||||
$path_map = id(new DiffusionPathIDQuery($paths)) | $path_map = id(new DiffusionPathIDQuery($paths)) | ||||
->loadPathIDs(); | ->loadPathIDs(); | ||||
if (!$path_map) { | if (!$path_map) { | ||||
// If none of the paths have entries in the PathID table, we can not | // If none of the paths have entries in the PathID table, we can not | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | /* -( Internals )---------------------------------------------------------- */ | ||||
} | } | ||||
/** | /** | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
protected function shouldGroupQueryResultRows() { | protected function shouldGroupQueryResultRows() { | ||||
if (count($this->pathIDs) > 1) { | |||||
return true; | |||||
} | |||||
if ($this->paths) { | if ($this->paths) { | ||||
// (If we have exactly one repository and exactly one path, we don't | // (If we have exactly one repository and exactly one path, we don't | ||||
// technically need to group, but it's simpler to always group.) | // technically need to group, but it's simpler to always group.) | ||||
return true; | return true; | ||||
} | } | ||||
if (count($this->ccs) > 1) { | if (count($this->ccs) > 1) { | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 284 Lines • Show Last 20 Lines |