Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/query/DifferentialRevisionQuery.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Flexible query API for Differential revisions. Example: | |||||
| * | |||||
| * // Load open revisions | |||||
| * $revisions = id(new DifferentialRevisionQuery()) | |||||
| * ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) | |||||
| * ->execute(); | |||||
| * | |||||
| * @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 $pathIDs = array(); | ||||
| private $status = 'status-any'; | private $status = 'status-any'; | ||||
| const STATUS_ANY = 'status-any'; | |||||
| const STATUS_OPEN = 'status-open'; | |||||
| const STATUS_ACCEPTED = 'status-accepted'; | |||||
| const STATUS_NEEDS_REVIEW = 'status-needs-review'; | |||||
| const STATUS_NEEDS_REVISION = 'status-needs-revision'; | |||||
| const STATUS_CLOSED = 'status-closed'; | |||||
| const STATUS_ABANDONED = 'status-abandoned'; | |||||
| 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 $commitPHIDs = array(); | private $commitPHIDs = array(); | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | /* -( Query Configuration )------------------------------------------------ */ | ||||
| */ | */ | ||||
| public function withCommitPHIDs(array $commit_phids) { | public function withCommitPHIDs(array $commit_phids) { | ||||
| $this->commitPHIDs = $commit_phids; | $this->commitPHIDs = $commit_phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * Filter results to revisions with a given status. Provide a class constant, | * Filter results to revisions with a given status. Provide a class constant, | ||||
| * such as `DifferentialRevisionQuery::STATUS_OPEN`. | * such as `DifferentialLegacyQuery::STATUS_OPEN`. | ||||
| * | * | ||||
| * @param const Class STATUS constant, like STATUS_OPEN. | * @param const Class STATUS constant, like STATUS_OPEN. | ||||
| * @return this | * @return this | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function withStatus($status_constant) { | public function withStatus($status_constant) { | ||||
| $this->status = $status_constant; | $this->status = $status_constant; | ||||
| return $this; | return $this; | ||||
| ▲ Show 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | if ($this->updatedEpochMax !== null) { | ||||
| $conn_r, | $conn_r, | ||||
| 'r.dateModified <= %d', | 'r.dateModified <= %d', | ||||
| $this->updatedEpochMax); | $this->updatedEpochMax); | ||||
| } | } | ||||
| // NOTE: Although the status constants are integers in PHP, the column is a | // NOTE: Although the status constants are integers in PHP, the column is a | ||||
| // string column in MySQL, and MySQL won't use keys on string columns if | // string column in MySQL, and MySQL won't use keys on string columns if | ||||
| // you put integers in the query. | // you put integers in the query. | ||||
| $statuses = DifferentialLegacyQuery::getQueryValues($this->status); | |||||
| switch ($this->status) { | if ($statuses !== null) { | ||||
| case self::STATUS_ANY: | |||||
| break; | |||||
| case self::STATUS_OPEN: | |||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'r.status IN (%Ls)', | |||||
| DifferentialRevisionStatus::getOpenStatuses()); | |||||
| break; | |||||
| case self::STATUS_NEEDS_REVIEW: | |||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'r.status IN (%Ls)', | |||||
| array( | |||||
| ArcanistDifferentialRevisionStatus::NEEDS_REVIEW, | |||||
| )); | |||||
| break; | |||||
| case self::STATUS_NEEDS_REVISION: | |||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'r.status IN (%Ls)', | |||||
| array( | |||||
| ArcanistDifferentialRevisionStatus::NEEDS_REVISION, | |||||
| )); | |||||
| break; | |||||
| case self::STATUS_ACCEPTED: | |||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'r.status IN (%Ls)', | |||||
| array( | |||||
| ArcanistDifferentialRevisionStatus::ACCEPTED, | |||||
| )); | |||||
| break; | |||||
| case self::STATUS_CLOSED: | |||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'r.status IN (%Ls)', | |||||
| DifferentialRevisionStatus::getClosedStatuses()); | |||||
| break; | |||||
| case self::STATUS_ABANDONED: | |||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'r.status IN (%Ls)', | 'r.status IN (%Ls)', | ||||
| array( | $statuses); | ||||
| ArcanistDifferentialRevisionStatus::ABANDONED, | |||||
| )); | |||||
| break; | |||||
| default: | |||||
| throw new Exception( | |||||
| pht("Unknown revision status filter constant '%s'!", $this->status)); | |||||
| } | } | ||||
| $where[] = $this->buildWhereClauseParts($conn_r); | $where[] = $this->buildWhereClauseParts($conn_r); | ||||
| return $this->formatWhereClause($where); | return $this->formatWhereClause($where); | ||||
| } | } | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 284 Lines • Show Last 20 Lines | |||||