Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/query/DifferentialRevisionQuery.php
Show All 20 Lines | final class DifferentialRevisionQuery | ||||
private $branches = array(); | private $branches = array(); | ||||
private $repositoryPHIDs; | private $repositoryPHIDs; | ||||
private $updatedEpochMin; | private $updatedEpochMin; | ||||
private $updatedEpochMax; | private $updatedEpochMax; | ||||
private $statuses; | private $statuses; | ||||
private $isOpen; | private $isOpen; | ||||
private $createdEpochMin; | private $createdEpochMin; | ||||
private $createdEpochMax; | private $createdEpochMax; | ||||
private $noReviewers; | |||||
const ORDER_MODIFIED = 'order-modified'; | const ORDER_MODIFIED = 'order-modified'; | ||||
const ORDER_CREATED = 'order-created'; | const ORDER_CREATED = 'order-created'; | ||||
private $needActiveDiffs = false; | private $needActiveDiffs = false; | ||||
private $needDiffIDs = false; | private $needDiffIDs = false; | ||||
private $needCommitPHIDs = false; | private $needCommitPHIDs = false; | ||||
private $needHashes = false; | private $needHashes = false; | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | /* -( Query Configuration )------------------------------------------------ */ | ||||
* reviewers. Calling this function will clear anything set by previous calls | * reviewers. Calling this function will clear anything set by previous calls | ||||
* to @{method:withReviewers}. | * to @{method:withReviewers}. | ||||
* | * | ||||
* @param array List of PHIDs of reviewers | * @param array List of PHIDs of reviewers | ||||
* @return this | * @return this | ||||
* @task config | * @task config | ||||
*/ | */ | ||||
public function withReviewers(array $reviewer_phids) { | public function withReviewers(array $reviewer_phids) { | ||||
$this->reviewers = $reviewer_phids; | if ($reviewer_phids === array()) { | ||||
throw new Exception( | |||||
pht( | |||||
'Empty "withReviewers()" constraint is invalid. Provide one or '. | |||||
'more values, or remove the constraint.')); | |||||
} | |||||
$with_none = false; | |||||
foreach ($reviewer_phids as $key => $phid) { | |||||
switch ($phid) { | |||||
case DifferentialNoReviewersDatasource::FUNCTION_TOKEN: | |||||
$with_none = true; | |||||
unset($reviewer_phids[$key]); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
$this->noReviewers = $with_none; | |||||
if ($reviewer_phids) { | |||||
$this->reviewers = array_values($reviewer_phids); | |||||
} | |||||
return $this; | return $this; | ||||
} | } | ||||
/** | /** | ||||
* Filter results to revisions that have one of the provided commit hashes. | * Filter results to revisions that have one of the provided commit hashes. | ||||
* Calling this function will clear anything set by previous calls to | * Calling this function will clear anything set by previous calls to | ||||
* @{method:withCommitHashes}. | * @{method:withCommitHashes}. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 457 Lines • ▼ Show 20 Lines | if ($this->ccs) { | ||||
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, | $conn, | ||||
'JOIN %T reviewer ON reviewer.revisionPHID = r.phid | 'LEFT 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->noReviewers) { | |||||
$joins[] = qsprintf( | |||||
$conn, | |||||
'LEFT JOIN %T no_reviewer ON no_reviewer.revisionPHID = r.phid | |||||
AND no_reviewer.reviewerStatus != %s', | |||||
id(new DifferentialReviewer())->getTableName(), | |||||
DifferentialReviewerStatus::STATUS_RESIGNED); | |||||
} | |||||
if ($this->draftAuthors) { | if ($this->draftAuthors) { | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn, | $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, | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | if ($this->isOpen !== null) { | ||||
DifferentialLegacyQuery::STATUS_CLOSED); | DifferentialLegacyQuery::STATUS_CLOSED); | ||||
} | } | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'r.status in (%Ls)', | 'r.status in (%Ls)', | ||||
$statuses); | $statuses); | ||||
} | } | ||||
$reviewer_subclauses = array(); | |||||
if ($this->noReviewers) { | |||||
$reviewer_subclauses[] = qsprintf( | |||||
$conn, | |||||
'no_reviewer.reviewerPHID IS NULL'); | |||||
} | |||||
if ($this->reviewers) { | |||||
$reviewer_subclauses[] = qsprintf( | |||||
$conn, | |||||
'reviewer.reviewerPHID IS NOT NULL'); | |||||
} | |||||
if ($reviewer_subclauses) { | |||||
$where[] = qsprintf($conn, '%LO', $reviewer_subclauses); | |||||
} | |||||
$where[] = $this->buildWhereClauseParts($conn); | $where[] = $this->buildWhereClauseParts($conn); | ||||
return $this->formatWhereClause($conn, $where); | return $this->formatWhereClause($conn, $where); | ||||
} | } | ||||
/** | /** | ||||
* @task internal | * @task internal | ||||
*/ | */ | ||||
protected function shouldGroupQueryResultRows() { | protected function shouldGroupQueryResultRows() { | ||||
$join_triggers = array_merge( | $join_triggers = array_merge( | ||||
$this->pathIDs, | $this->pathIDs, | ||||
$this->ccs, | $this->ccs, | ||||
$this->reviewers); | $this->reviewers); | ||||
if (count($join_triggers) > 1) { | if (count($join_triggers) > 1) { | ||||
return true; | return true; | ||||
} | } | ||||
if ($this->noReviewers) { | |||||
return true; | |||||
} | |||||
return parent::shouldGroupQueryResultRows(); | return parent::shouldGroupQueryResultRows(); | ||||
} | } | ||||
public function getBuiltinOrders() { | public function getBuiltinOrders() { | ||||
$orders = parent::getBuiltinOrders() + array( | $orders = parent::getBuiltinOrders() + array( | ||||
'updated' => array( | 'updated' => array( | ||||
'vector' => array('updated', 'id'), | 'vector' => array('updated', 'id'), | ||||
'name' => pht('Date Updated (Latest First)'), | 'name' => pht('Date Updated (Latest First)'), | ||||
▲ Show 20 Lines • Show All 262 Lines • Show Last 20 Lines |