diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d44e9370bb..4089df2bbb 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -471,6 +471,7 @@ phutil_register_library_map(array( 'DifferentialJIRAIssuesCommitMessageField' => 'applications/differential/field/DifferentialJIRAIssuesCommitMessageField.php', 'DifferentialJIRAIssuesField' => 'applications/differential/customfield/DifferentialJIRAIssuesField.php', 'DifferentialLegacyHunk' => 'applications/differential/storage/DifferentialLegacyHunk.php', + 'DifferentialLegacyQuery' => 'applications/differential/constants/DifferentialLegacyQuery.php', 'DifferentialLineAdjustmentMap' => 'applications/differential/parser/DifferentialLineAdjustmentMap.php', 'DifferentialLintField' => 'applications/differential/customfield/DifferentialLintField.php', 'DifferentialLintStatus' => 'applications/differential/constants/DifferentialLintStatus.php', @@ -5447,6 +5448,7 @@ phutil_register_library_map(array( 'DifferentialJIRAIssuesCommitMessageField' => 'DifferentialCommitMessageCustomField', 'DifferentialJIRAIssuesField' => 'DifferentialStoredCustomField', 'DifferentialLegacyHunk' => 'DifferentialHunk', + 'DifferentialLegacyQuery' => 'Phobject', 'DifferentialLineAdjustmentMap' => 'Phobject', 'DifferentialLintField' => 'DifferentialHarbormasterField', 'DifferentialLintStatus' => 'Phobject', diff --git a/src/applications/differential/conduit/DifferentialFindConduitAPIMethod.php b/src/applications/differential/conduit/DifferentialFindConduitAPIMethod.php index 79d3fc5d7d..a199f599e8 100644 --- a/src/applications/differential/conduit/DifferentialFindConduitAPIMethod.php +++ b/src/applications/differential/conduit/DifferentialFindConduitAPIMethod.php @@ -52,12 +52,12 @@ final class DifferentialFindConduitAPIMethod switch ($type) { case 'open': $query - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) ->withAuthors($guids); break; case 'committable': $query - ->withStatus(DifferentialRevisionQuery::STATUS_ACCEPTED) + ->withStatus(DifferentialLegacyQuery::STATUS_ACCEPTED) ->withAuthors($guids); break; case 'revision-ids': diff --git a/src/applications/differential/conduit/DifferentialQueryConduitAPIMethod.php b/src/applications/differential/conduit/DifferentialQueryConduitAPIMethod.php index 1051983324..329a44c857 100644 --- a/src/applications/differential/conduit/DifferentialQueryConduitAPIMethod.php +++ b/src/applications/differential/conduit/DifferentialQueryConduitAPIMethod.php @@ -25,12 +25,7 @@ final class DifferentialQueryConduitAPIMethod $hash_types = ArcanistDifferentialRevisionHash::getTypes(); $hash_const = $this->formatStringConstants($hash_types); - $status_types = array( - DifferentialRevisionQuery::STATUS_ANY, - DifferentialRevisionQuery::STATUS_OPEN, - DifferentialRevisionQuery::STATUS_ACCEPTED, - DifferentialRevisionQuery::STATUS_CLOSED, - ); + $status_types = DifferentialLegacyQuery::getAllConstants(); $status_const = $this->formatStringConstants($status_types); $order_types = array( diff --git a/src/applications/differential/constants/DifferentialLegacyQuery.php b/src/applications/differential/constants/DifferentialLegacyQuery.php new file mode 100644 index 0000000000..4a20267f10 --- /dev/null +++ b/src/applications/differential/constants/DifferentialLegacyQuery.php @@ -0,0 +1,86 @@ +getLegacyKey(); + if ($legacy_key !== null) { + $values[] = $legacy_key; + } + } + + return $values; + } + + private static function getMap() { + $all = array( + DifferentialRevisionStatus::NEEDS_REVIEW, + DifferentialRevisionStatus::NEEDS_REVISION, + DifferentialRevisionStatus::CHANGES_PLANNED, + DifferentialRevisionStatus::ACCEPTED, + DifferentialRevisionStatus::PUBLISHED, + DifferentialRevisionStatus::ABANDONED, + ); + + $open = array(); + $closed = array(); + + foreach ($all as $status) { + $status_object = DifferentialRevisionStatus::newForStatus($status); + if ($status_object->isClosedStatus()) { + $closed[] = $status_object->getKey(); + } else { + $open[] = $status_object->getKey(); + } + } + + return array( + self::STATUS_ANY => $all, + self::STATUS_OPEN => $open, + self::STATUS_ACCEPTED => array( + DifferentialRevisionStatus::ACCEPTED, + ), + self::STATUS_NEEDS_REVIEW => array( + DifferentialRevisionStatus::NEEDS_REVIEW, + ), + self::STATUS_NEEDS_REVISION => array( + DifferentialRevisionStatus::NEEDS_REVISION, + ), + self::STATUS_CLOSED => $closed, + self::STATUS_ABANDONED => array( + DifferentialRevisionStatus::ABANDONED, + ), + ); + } + +} diff --git a/src/applications/differential/constants/DifferentialRevisionStatus.php b/src/applications/differential/constants/DifferentialRevisionStatus.php index caca7ed85b..37b51f1b3b 100644 --- a/src/applications/differential/constants/DifferentialRevisionStatus.php +++ b/src/applications/differential/constants/DifferentialRevisionStatus.php @@ -12,6 +12,14 @@ final class DifferentialRevisionStatus extends Phobject { private $key; private $spec = array(); + public function getKey() { + return $this->key; + } + + public function getLegacyKey() { + return idx($this->spec, 'legacy'); + } + public function getIcon() { return idx($this->spec, 'icon'); } @@ -52,6 +60,18 @@ final class DifferentialRevisionStatus extends Phobject { return ($this->key === self::CHANGES_PLANNED); } + public static function newForStatus($status) { + $result = new self(); + + $map = self::getMap(); + if (isset($map[$status])) { + $result->key = $status; + $result->spec = $map[$status]; + } + + return $result; + } + public static function newForLegacyStatus($legacy_status) { $result = new self(); @@ -135,33 +155,4 @@ final class DifferentialRevisionStatus extends Phobject { ); } - public static function getClosedStatuses() { - $statuses = array( - ArcanistDifferentialRevisionStatus::CLOSED, - ArcanistDifferentialRevisionStatus::ABANDONED, - ); - - if (PhabricatorEnv::getEnvConfig('differential.close-on-accept')) { - $statuses[] = ArcanistDifferentialRevisionStatus::ACCEPTED; - } - - return $statuses; - } - - public static function getOpenStatuses() { - return array_diff(self::getAllStatuses(), self::getClosedStatuses()); - } - - public static function getAllStatuses() { - return array( - ArcanistDifferentialRevisionStatus::NEEDS_REVIEW, - ArcanistDifferentialRevisionStatus::NEEDS_REVISION, - ArcanistDifferentialRevisionStatus::CHANGES_PLANNED, - ArcanistDifferentialRevisionStatus::ACCEPTED, - ArcanistDifferentialRevisionStatus::CLOSED, - ArcanistDifferentialRevisionStatus::ABANDONED, - ArcanistDifferentialRevisionStatus::IN_PREPARATION, - ); - } - } diff --git a/src/applications/differential/controller/DifferentialDiffViewController.php b/src/applications/differential/controller/DifferentialDiffViewController.php index dae65bb200..488d2cec82 100644 --- a/src/applications/differential/controller/DifferentialDiffViewController.php +++ b/src/applications/differential/controller/DifferentialDiffViewController.php @@ -177,7 +177,7 @@ final class DifferentialDiffViewController extends DifferentialController { $revisions = id(new DifferentialRevisionQuery()) ->setViewer($viewer) ->withAuthors(array($viewer->getPHID())) - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php index 5c7f5104f5..81b2aebda6 100644 --- a/src/applications/differential/controller/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/DifferentialRevisionViewController.php @@ -808,7 +808,7 @@ final class DifferentialRevisionViewController extends DifferentialController { $query = id(new DifferentialRevisionQuery()) ->setViewer($this->getRequest()->getUser()) - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) ->withUpdatedEpochBetween($recent, null) ->setOrder(DifferentialRevisionQuery::ORDER_MODIFIED) ->setLimit(10) diff --git a/src/applications/differential/query/DifferentialRevisionQuery.php b/src/applications/differential/query/DifferentialRevisionQuery.php index 701463e6a7..f53ec46a9f 100644 --- a/src/applications/differential/query/DifferentialRevisionQuery.php +++ b/src/applications/differential/query/DifferentialRevisionQuery.php @@ -1,13 +1,6 @@ withStatus(DifferentialRevisionQuery::STATUS_OPEN) - * ->execute(); - * * @task config Query Configuration * @task exec Query Execution * @task internal Internals @@ -18,13 +11,6 @@ final class DifferentialRevisionQuery private $pathIDs = array(); 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 $draftAuthors = array(); @@ -149,7 +135,7 @@ final class DifferentialRevisionQuery /** * 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. * @return this @@ -711,57 +697,12 @@ final class DifferentialRevisionQuery // 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 // you put integers in the query. - - switch ($this->status) { - 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( - $conn_r, - 'r.status IN (%Ls)', - array( - ArcanistDifferentialRevisionStatus::ABANDONED, - )); - break; - default: - throw new Exception( - pht("Unknown revision status filter constant '%s'!", $this->status)); + $statuses = DifferentialLegacyQuery::getQueryValues($this->status); + if ($statuses !== null) { + $where[] = qsprintf( + $conn_r, + 'r.status IN (%Ls)', + $statuses); } $where[] = $this->buildWhereClauseParts($conn_r); diff --git a/src/applications/differential/query/DifferentialRevisionSearchEngine.php b/src/applications/differential/query/DifferentialRevisionSearchEngine.php index ef88c0ea1c..8cb8ffd2fb 100644 --- a/src/applications/differential/query/DifferentialRevisionSearchEngine.php +++ b/src/applications/differential/query/DifferentialRevisionSearchEngine.php @@ -115,7 +115,7 @@ final class DifferentialRevisionSearchEngine return $query ->setParameter('responsiblePHIDs', array($viewer->getPHID())) - ->setParameter('status', DifferentialRevisionQuery::STATUS_OPEN) + ->setParameter('status', DifferentialLegacyQuery::STATUS_OPEN) ->setParameter('bucket', $bucket_key); case 'authored': return $query @@ -129,13 +129,13 @@ final class DifferentialRevisionSearchEngine private function getStatusOptions() { return array( - DifferentialRevisionQuery::STATUS_ANY => pht('All'), - DifferentialRevisionQuery::STATUS_OPEN => pht('Open'), - DifferentialRevisionQuery::STATUS_ACCEPTED => pht('Accepted'), - DifferentialRevisionQuery::STATUS_NEEDS_REVIEW => pht('Needs Review'), - DifferentialRevisionQuery::STATUS_NEEDS_REVISION => pht('Needs Revision'), - DifferentialRevisionQuery::STATUS_CLOSED => pht('Closed'), - DifferentialRevisionQuery::STATUS_ABANDONED => pht('Abandoned'), + DifferentialLegacyQuery::STATUS_ANY => pht('All'), + DifferentialLegacyQuery::STATUS_OPEN => pht('Open'), + DifferentialLegacyQuery::STATUS_ACCEPTED => pht('Accepted'), + DifferentialLegacyQuery::STATUS_NEEDS_REVIEW => pht('Needs Review'), + DifferentialLegacyQuery::STATUS_NEEDS_REVISION => pht('Needs Revision'), + DifferentialLegacyQuery::STATUS_CLOSED => pht('Closed'), + DifferentialLegacyQuery::STATUS_ABANDONED => pht('Abandoned'), ); } @@ -267,7 +267,7 @@ final class DifferentialRevisionSearchEngine $blocking_revisions = id(new DifferentialRevisionQuery()) ->setViewer($viewer) ->withPHIDs($revision_phids) - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) ->execute(); $blocking_revisions = mpull($blocking_revisions, null, 'getPHID'); diff --git a/src/applications/diffusion/controller/DiffusionBrowseController.php b/src/applications/diffusion/controller/DiffusionBrowseController.php index 06c8336f5c..32381207fa 100644 --- a/src/applications/diffusion/controller/DiffusionBrowseController.php +++ b/src/applications/diffusion/controller/DiffusionBrowseController.php @@ -1758,7 +1758,7 @@ final class DiffusionBrowseController extends DiffusionController { $revisions = id(new DifferentialRevisionQuery()) ->setViewer($viewer) ->withPath($repository->getID(), $path_id) - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) ->withUpdatedEpochBetween($recent, null) ->setOrder(DifferentialRevisionQuery::ORDER_MODIFIED) ->setLimit(10)