@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Pull legacy revision query status filters out of the main Query class

Summary:
Ref T2543. Currently, Differential uses a set of hard-coded query filters (like "open" and "closed") to query revisions by status (for example, "open" means any of "review, revision, changes planned, accepted [usually]").

In other applications, like Maniphest, we've replaced this with a low level list of the actual statuses, plus higher level convenience UI through tokenizer functions. This basically has all of the benefits of the hard-coded filters with none of the drawbacks, and is generally more flexible.

I'd like to do that in Differential, too, although we'll need to keep the legacy maps around for a while because they're used by `differential.find` and `differential.getrevision`. To prepare for this, pull all the legacy stuff out into a separate class. Then I'll modernize where I can, and we can get rid of this junk some day.

Test Plan: Grepped for `RevisionQuery::STATUS`. Ran queries via Differential UI.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T2543

Differential Revision: https://secure.phabricator.com/D18343

+130 -115
+2
src/__phutil_library_map__.php
··· 471 471 'DifferentialJIRAIssuesCommitMessageField' => 'applications/differential/field/DifferentialJIRAIssuesCommitMessageField.php', 472 472 'DifferentialJIRAIssuesField' => 'applications/differential/customfield/DifferentialJIRAIssuesField.php', 473 473 'DifferentialLegacyHunk' => 'applications/differential/storage/DifferentialLegacyHunk.php', 474 + 'DifferentialLegacyQuery' => 'applications/differential/constants/DifferentialLegacyQuery.php', 474 475 'DifferentialLineAdjustmentMap' => 'applications/differential/parser/DifferentialLineAdjustmentMap.php', 475 476 'DifferentialLintField' => 'applications/differential/customfield/DifferentialLintField.php', 476 477 'DifferentialLintStatus' => 'applications/differential/constants/DifferentialLintStatus.php', ··· 5447 5448 'DifferentialJIRAIssuesCommitMessageField' => 'DifferentialCommitMessageCustomField', 5448 5449 'DifferentialJIRAIssuesField' => 'DifferentialStoredCustomField', 5449 5450 'DifferentialLegacyHunk' => 'DifferentialHunk', 5451 + 'DifferentialLegacyQuery' => 'Phobject', 5450 5452 'DifferentialLineAdjustmentMap' => 'Phobject', 5451 5453 'DifferentialLintField' => 'DifferentialHarbormasterField', 5452 5454 'DifferentialLintStatus' => 'Phobject',
+2 -2
src/applications/differential/conduit/DifferentialFindConduitAPIMethod.php
··· 52 52 switch ($type) { 53 53 case 'open': 54 54 $query 55 - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 55 + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) 56 56 ->withAuthors($guids); 57 57 break; 58 58 case 'committable': 59 59 $query 60 - ->withStatus(DifferentialRevisionQuery::STATUS_ACCEPTED) 60 + ->withStatus(DifferentialLegacyQuery::STATUS_ACCEPTED) 61 61 ->withAuthors($guids); 62 62 break; 63 63 case 'revision-ids':
+1 -6
src/applications/differential/conduit/DifferentialQueryConduitAPIMethod.php
··· 25 25 $hash_types = ArcanistDifferentialRevisionHash::getTypes(); 26 26 $hash_const = $this->formatStringConstants($hash_types); 27 27 28 - $status_types = array( 29 - DifferentialRevisionQuery::STATUS_ANY, 30 - DifferentialRevisionQuery::STATUS_OPEN, 31 - DifferentialRevisionQuery::STATUS_ACCEPTED, 32 - DifferentialRevisionQuery::STATUS_CLOSED, 33 - ); 28 + $status_types = DifferentialLegacyQuery::getAllConstants(); 34 29 $status_const = $this->formatStringConstants($status_types); 35 30 36 31 $order_types = array(
+86
src/applications/differential/constants/DifferentialLegacyQuery.php
··· 1 + <?php 2 + 3 + final class DifferentialLegacyQuery 4 + extends Phobject { 5 + 6 + const STATUS_ANY = 'status-any'; 7 + const STATUS_OPEN = 'status-open'; 8 + const STATUS_ACCEPTED = 'status-accepted'; 9 + const STATUS_NEEDS_REVIEW = 'status-needs-review'; 10 + const STATUS_NEEDS_REVISION = 'status-needs-revision'; 11 + const STATUS_CLOSED = 'status-closed'; 12 + const STATUS_ABANDONED = 'status-abandoned'; 13 + 14 + public static function getAllConstants() { 15 + return array_keys(self::getMap()); 16 + } 17 + 18 + public static function getQueryValues($status) { 19 + if ($status === self::STATUS_ANY) { 20 + return null; 21 + } 22 + 23 + $map = self::getMap(); 24 + if (!isset($map[$status])) { 25 + throw new Exception( 26 + pht( 27 + 'Unknown revision status filter constant "%s".', 28 + $status)); 29 + } 30 + 31 + $values = array(); 32 + foreach ($map[$status] as $status_constant) { 33 + $status_object = DifferentialRevisionStatus::newForStatus( 34 + $status_constant); 35 + 36 + $legacy_key = $status_object->getLegacyKey(); 37 + if ($legacy_key !== null) { 38 + $values[] = $legacy_key; 39 + } 40 + } 41 + 42 + return $values; 43 + } 44 + 45 + private static function getMap() { 46 + $all = array( 47 + DifferentialRevisionStatus::NEEDS_REVIEW, 48 + DifferentialRevisionStatus::NEEDS_REVISION, 49 + DifferentialRevisionStatus::CHANGES_PLANNED, 50 + DifferentialRevisionStatus::ACCEPTED, 51 + DifferentialRevisionStatus::PUBLISHED, 52 + DifferentialRevisionStatus::ABANDONED, 53 + ); 54 + 55 + $open = array(); 56 + $closed = array(); 57 + 58 + foreach ($all as $status) { 59 + $status_object = DifferentialRevisionStatus::newForStatus($status); 60 + if ($status_object->isClosedStatus()) { 61 + $closed[] = $status_object->getKey(); 62 + } else { 63 + $open[] = $status_object->getKey(); 64 + } 65 + } 66 + 67 + return array( 68 + self::STATUS_ANY => $all, 69 + self::STATUS_OPEN => $open, 70 + self::STATUS_ACCEPTED => array( 71 + DifferentialRevisionStatus::ACCEPTED, 72 + ), 73 + self::STATUS_NEEDS_REVIEW => array( 74 + DifferentialRevisionStatus::NEEDS_REVIEW, 75 + ), 76 + self::STATUS_NEEDS_REVISION => array( 77 + DifferentialRevisionStatus::NEEDS_REVISION, 78 + ), 79 + self::STATUS_CLOSED => $closed, 80 + self::STATUS_ABANDONED => array( 81 + DifferentialRevisionStatus::ABANDONED, 82 + ), 83 + ); 84 + } 85 + 86 + }
+20 -29
src/applications/differential/constants/DifferentialRevisionStatus.php
··· 12 12 private $key; 13 13 private $spec = array(); 14 14 15 + public function getKey() { 16 + return $this->key; 17 + } 18 + 19 + public function getLegacyKey() { 20 + return idx($this->spec, 'legacy'); 21 + } 22 + 15 23 public function getIcon() { 16 24 return idx($this->spec, 'icon'); 17 25 } ··· 50 58 51 59 public function isChangePlanned() { 52 60 return ($this->key === self::CHANGES_PLANNED); 61 + } 62 + 63 + public static function newForStatus($status) { 64 + $result = new self(); 65 + 66 + $map = self::getMap(); 67 + if (isset($map[$status])) { 68 + $result->key = $status; 69 + $result->spec = $map[$status]; 70 + } 71 + 72 + return $result; 53 73 } 54 74 55 75 public static function newForLegacyStatus($legacy_status) { ··· 132 152 'color.tag' => 'indigo', 133 153 'color.ansi' => null, 134 154 ), 135 - ); 136 - } 137 - 138 - public static function getClosedStatuses() { 139 - $statuses = array( 140 - ArcanistDifferentialRevisionStatus::CLOSED, 141 - ArcanistDifferentialRevisionStatus::ABANDONED, 142 - ); 143 - 144 - if (PhabricatorEnv::getEnvConfig('differential.close-on-accept')) { 145 - $statuses[] = ArcanistDifferentialRevisionStatus::ACCEPTED; 146 - } 147 - 148 - return $statuses; 149 - } 150 - 151 - public static function getOpenStatuses() { 152 - return array_diff(self::getAllStatuses(), self::getClosedStatuses()); 153 - } 154 - 155 - public static function getAllStatuses() { 156 - return array( 157 - ArcanistDifferentialRevisionStatus::NEEDS_REVIEW, 158 - ArcanistDifferentialRevisionStatus::NEEDS_REVISION, 159 - ArcanistDifferentialRevisionStatus::CHANGES_PLANNED, 160 - ArcanistDifferentialRevisionStatus::ACCEPTED, 161 - ArcanistDifferentialRevisionStatus::CLOSED, 162 - ArcanistDifferentialRevisionStatus::ABANDONED, 163 - ArcanistDifferentialRevisionStatus::IN_PREPARATION, 164 155 ); 165 156 } 166 157
+1 -1
src/applications/differential/controller/DifferentialDiffViewController.php
··· 177 177 $revisions = id(new DifferentialRevisionQuery()) 178 178 ->setViewer($viewer) 179 179 ->withAuthors(array($viewer->getPHID())) 180 - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 180 + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) 181 181 ->requireCapabilities( 182 182 array( 183 183 PhabricatorPolicyCapability::CAN_VIEW,
+1 -1
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 808 808 809 809 $query = id(new DifferentialRevisionQuery()) 810 810 ->setViewer($this->getRequest()->getUser()) 811 - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 811 + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) 812 812 ->withUpdatedEpochBetween($recent, null) 813 813 ->setOrder(DifferentialRevisionQuery::ORDER_MODIFIED) 814 814 ->setLimit(10)
+7 -66
src/applications/differential/query/DifferentialRevisionQuery.php
··· 1 1 <?php 2 2 3 3 /** 4 - * Flexible query API for Differential revisions. Example: 5 - * 6 - * // Load open revisions 7 - * $revisions = id(new DifferentialRevisionQuery()) 8 - * ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 9 - * ->execute(); 10 - * 11 4 * @task config Query Configuration 12 5 * @task exec Query Execution 13 6 * @task internal Internals ··· 18 11 private $pathIDs = array(); 19 12 20 13 private $status = 'status-any'; 21 - const STATUS_ANY = 'status-any'; 22 - const STATUS_OPEN = 'status-open'; 23 - const STATUS_ACCEPTED = 'status-accepted'; 24 - const STATUS_NEEDS_REVIEW = 'status-needs-review'; 25 - const STATUS_NEEDS_REVISION = 'status-needs-revision'; 26 - const STATUS_CLOSED = 'status-closed'; 27 - const STATUS_ABANDONED = 'status-abandoned'; 28 14 29 15 private $authors = array(); 30 16 private $draftAuthors = array(); ··· 149 135 150 136 /** 151 137 * Filter results to revisions with a given status. Provide a class constant, 152 - * such as `DifferentialRevisionQuery::STATUS_OPEN`. 138 + * such as `DifferentialLegacyQuery::STATUS_OPEN`. 153 139 * 154 140 * @param const Class STATUS constant, like STATUS_OPEN. 155 141 * @return this ··· 711 697 // NOTE: Although the status constants are integers in PHP, the column is a 712 698 // string column in MySQL, and MySQL won't use keys on string columns if 713 699 // you put integers in the query. 714 - 715 - switch ($this->status) { 716 - case self::STATUS_ANY: 717 - break; 718 - case self::STATUS_OPEN: 719 - $where[] = qsprintf( 720 - $conn_r, 721 - 'r.status IN (%Ls)', 722 - DifferentialRevisionStatus::getOpenStatuses()); 723 - break; 724 - case self::STATUS_NEEDS_REVIEW: 725 - $where[] = qsprintf( 726 - $conn_r, 727 - 'r.status IN (%Ls)', 728 - array( 729 - ArcanistDifferentialRevisionStatus::NEEDS_REVIEW, 730 - )); 731 - break; 732 - case self::STATUS_NEEDS_REVISION: 733 - $where[] = qsprintf( 734 - $conn_r, 735 - 'r.status IN (%Ls)', 736 - array( 737 - ArcanistDifferentialRevisionStatus::NEEDS_REVISION, 738 - )); 739 - break; 740 - case self::STATUS_ACCEPTED: 741 - $where[] = qsprintf( 742 - $conn_r, 743 - 'r.status IN (%Ls)', 744 - array( 745 - ArcanistDifferentialRevisionStatus::ACCEPTED, 746 - )); 747 - break; 748 - case self::STATUS_CLOSED: 749 - $where[] = qsprintf( 750 - $conn_r, 751 - 'r.status IN (%Ls)', 752 - DifferentialRevisionStatus::getClosedStatuses()); 753 - break; 754 - case self::STATUS_ABANDONED: 755 - $where[] = qsprintf( 756 - $conn_r, 757 - 'r.status IN (%Ls)', 758 - array( 759 - ArcanistDifferentialRevisionStatus::ABANDONED, 760 - )); 761 - break; 762 - default: 763 - throw new Exception( 764 - pht("Unknown revision status filter constant '%s'!", $this->status)); 700 + $statuses = DifferentialLegacyQuery::getQueryValues($this->status); 701 + if ($statuses !== null) { 702 + $where[] = qsprintf( 703 + $conn_r, 704 + 'r.status IN (%Ls)', 705 + $statuses); 765 706 } 766 707 767 708 $where[] = $this->buildWhereClauseParts($conn_r);
+9 -9
src/applications/differential/query/DifferentialRevisionSearchEngine.php
··· 115 115 116 116 return $query 117 117 ->setParameter('responsiblePHIDs', array($viewer->getPHID())) 118 - ->setParameter('status', DifferentialRevisionQuery::STATUS_OPEN) 118 + ->setParameter('status', DifferentialLegacyQuery::STATUS_OPEN) 119 119 ->setParameter('bucket', $bucket_key); 120 120 case 'authored': 121 121 return $query ··· 129 129 130 130 private function getStatusOptions() { 131 131 return array( 132 - DifferentialRevisionQuery::STATUS_ANY => pht('All'), 133 - DifferentialRevisionQuery::STATUS_OPEN => pht('Open'), 134 - DifferentialRevisionQuery::STATUS_ACCEPTED => pht('Accepted'), 135 - DifferentialRevisionQuery::STATUS_NEEDS_REVIEW => pht('Needs Review'), 136 - DifferentialRevisionQuery::STATUS_NEEDS_REVISION => pht('Needs Revision'), 137 - DifferentialRevisionQuery::STATUS_CLOSED => pht('Closed'), 138 - DifferentialRevisionQuery::STATUS_ABANDONED => pht('Abandoned'), 132 + DifferentialLegacyQuery::STATUS_ANY => pht('All'), 133 + DifferentialLegacyQuery::STATUS_OPEN => pht('Open'), 134 + DifferentialLegacyQuery::STATUS_ACCEPTED => pht('Accepted'), 135 + DifferentialLegacyQuery::STATUS_NEEDS_REVIEW => pht('Needs Review'), 136 + DifferentialLegacyQuery::STATUS_NEEDS_REVISION => pht('Needs Revision'), 137 + DifferentialLegacyQuery::STATUS_CLOSED => pht('Closed'), 138 + DifferentialLegacyQuery::STATUS_ABANDONED => pht('Abandoned'), 139 139 ); 140 140 } 141 141 ··· 267 267 $blocking_revisions = id(new DifferentialRevisionQuery()) 268 268 ->setViewer($viewer) 269 269 ->withPHIDs($revision_phids) 270 - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 270 + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) 271 271 ->execute(); 272 272 $blocking_revisions = mpull($blocking_revisions, null, 'getPHID'); 273 273
+1 -1
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 1758 1758 $revisions = id(new DifferentialRevisionQuery()) 1759 1759 ->setViewer($viewer) 1760 1760 ->withPath($repository->getID(), $path_id) 1761 - ->withStatus(DifferentialRevisionQuery::STATUS_OPEN) 1761 + ->withStatus(DifferentialLegacyQuery::STATUS_OPEN) 1762 1762 ->withUpdatedEpochBetween($recent, null) 1763 1763 ->setOrder(DifferentialRevisionQuery::ORDER_MODIFIED) 1764 1764 ->setLimit(10)