@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.

Make DiffusionCommitSearch accept modern (string) constants

Summary:
Depends on D19650. Ref T13197. Allow `SearchCheckboxesField` to have a "deprecated" map of older aliases, then convert them to modern values.

On the API method page, show all the values.

This technically resolves the issue in PHI841, although I still plan to migrate behind this.

Test Plan:
{F5875363}

- Queried audits, fiddled with `?status=1,audited`, etc.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13197

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

+73 -20
+12 -15
src/applications/audit/constants/PhabricatorAuditCommitStatusConstants.php
··· 94 94 return idx($this->spec, 'closed'); 95 95 } 96 96 97 - public static function getStatusNameMap() { 98 - $map = self::getMap(); 99 - return ipull($map, 'name', 'legacy'); 100 - } 101 - 102 - public static function getStatusName($code) { 103 - return idx(self::getStatusNameMap(), $code, pht('Unknown')); 104 - } 105 - 106 97 public static function getOpenStatusConstants() { 107 98 $constants = array(); 108 99 foreach (self::getMap() as $map) { ··· 113 104 return $constants; 114 105 } 115 106 116 - public static function getStatusColor($code) { 107 + public static function newOptions() { 117 108 $map = self::getMap(); 118 - $map = ipull($map, 'color', 'legacy'); 119 - return idx($map, $code); 109 + return ipull($map, 'name'); 120 110 } 121 111 122 - public static function getStatusIcon($code) { 112 + public static function newDeprecatedOptions() { 123 113 $map = self::getMap(); 124 - $map = ipull($map, 'icon', 'legacy'); 125 - return idx($map, $code); 114 + 115 + $results = array(); 116 + foreach ($map as $key => $spec) { 117 + if (isset($spec['legacy'])) { 118 + $results[$spec['legacy']] = $key; 119 + } 120 + } 121 + 122 + return $results; 126 123 } 127 124 128 125 private static function getMap() {
+3 -1
src/applications/audit/query/PhabricatorCommitSearchEngine.php
··· 92 92 ->setLabel(pht('Audit Status')) 93 93 ->setKey('statuses') 94 94 ->setAliases(array('status')) 95 - ->setOptions(PhabricatorAuditCommitStatusConstants::getStatusNameMap()) 95 + ->setOptions(PhabricatorAuditCommitStatusConstants::newOptions()) 96 + ->setDeprecatedOptions( 97 + PhabricatorAuditCommitStatusConstants::newDeprecatedOptions()) 96 98 ->setDescription(pht('Find commits with given audit statuses.')), 97 99 id(new PhabricatorSearchDatasourceField()) 98 100 ->setLabel(pht('Repositories'))
+10
src/applications/conduit/data/ConduitConstantDescription.php
··· 4 4 5 5 private $key; 6 6 private $value; 7 + private $isDeprecated; 7 8 8 9 public function setKey($key) { 9 10 $this->key = $key; ··· 21 22 22 23 public function getValue() { 23 24 return $this->value; 25 + } 26 + 27 + public function setIsDeprecated($is_deprecated) { 28 + $this->isDeprecated = $is_deprecated; 29 + return $this; 30 + } 31 + 32 + public function getIsDeprecated() { 33 + return $this->isDeprecated; 24 34 } 25 35 26 36 }
+13 -2
src/applications/search/engine/PhabricatorSearchEngineAPIMethod.php
··· 230 230 231 231 $constants_rows = array(); 232 232 foreach ($constants as $constant) { 233 + if ($constant->getIsDeprecated()) { 234 + $icon = id(new PHUIIconView()) 235 + ->setIcon('fa-exclamation-triangle', 'red'); 236 + } else { 237 + $icon = null; 238 + } 239 + 233 240 $constants_rows[] = array( 234 241 $constant->getKey(), 235 - $constant->getValue(), 242 + array( 243 + $icon, 244 + ' ', 245 + $constant->getValue(), 246 + ), 236 247 ); 237 248 } 238 249 ··· 244 255 )) 245 256 ->setColumnClasses( 246 257 array( 247 - 'pre', 258 + 'mono', 248 259 'wide', 249 260 )); 250 261
+35 -2
src/applications/search/field/PhabricatorSearchCheckboxesField.php
··· 4 4 extends PhabricatorSearchField { 5 5 6 6 private $options; 7 + private $deprecatedOptions = array(); 7 8 8 9 public function setOptions(array $options) { 9 10 $this->options = $options; ··· 12 13 13 14 public function getOptions() { 14 15 return $this->options; 16 + } 17 + 18 + public function setDeprecatedOptions(array $deprecated_options) { 19 + $this->deprecatedOptions = $deprecated_options; 20 + return $this; 21 + } 22 + 23 + public function getDeprecatedOptions() { 24 + return $this->deprecatedOptions; 15 25 } 16 26 17 27 protected function getDefaultValue() { ··· 23 33 return array(); 24 34 } 25 35 26 - return $value; 36 + return $this->getCanonicalValue($value); 27 37 } 28 38 29 39 protected function getValueFromRequest(AphrontRequest $request, $key) { 30 - return $this->getListFromRequest($request, $key); 40 + $value = $this->getListFromRequest($request, $key); 41 + return $this->getCanonicalValue($value); 31 42 } 32 43 33 44 protected function newControl() { ··· 58 69 ->setValue($option); 59 70 } 60 71 72 + foreach ($this->getDeprecatedOptions() as $key => $value) { 73 + $list[] = id(new ConduitConstantDescription()) 74 + ->setKey($key) 75 + ->setIsDeprecated(true) 76 + ->setValue(pht('Deprecated alias for "%s".', $value)); 77 + } 78 + 61 79 return $list; 80 + } 81 + 82 + private function getCanonicalValue(array $values) { 83 + // Always map the current normal options to themselves. 84 + $normal_options = array_fuse(array_keys($this->getOptions())); 85 + 86 + // Map deprecated values to their new values. 87 + $deprecated_options = $this->getDeprecatedOptions(); 88 + 89 + $map = $normal_options + $deprecated_options; 90 + foreach ($values as $key => $value) { 91 + $values[$key] = idx($map, $value, $value); 92 + } 93 + 94 + return $values; 62 95 } 63 96 64 97 }