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

Use CustomFields to power Conduit auxiliary dictionaries

Summary: Ref T2222. Moves this Conduit stuff over.

Test Plan: Made Conduit calls, saw data in results.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

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

+104 -122
+2 -2
src/__phutil_library_map__.php
··· 2722 2722 'ConduitAPI_differential_getcommitpaths_Method' => 'ConduitAPIMethod', 2723 2723 'ConduitAPI_differential_getdiff_Method' => 'ConduitAPIMethod', 2724 2724 'ConduitAPI_differential_getrawdiff_Method' => 'ConduitAPIMethod', 2725 - 'ConduitAPI_differential_getrevision_Method' => 'ConduitAPIMethod', 2725 + 'ConduitAPI_differential_getrevision_Method' => 'ConduitAPI_differential_Method', 2726 2726 'ConduitAPI_differential_getrevisioncomments_Method' => 'ConduitAPI_differential_Method', 2727 2727 'ConduitAPI_differential_parsecommitmessage_Method' => 'ConduitAPIMethod', 2728 - 'ConduitAPI_differential_query_Method' => 'ConduitAPIMethod', 2728 + 'ConduitAPI_differential_query_Method' => 'ConduitAPI_differential_Method', 2729 2729 'ConduitAPI_differential_querydiffs_Method' => 'ConduitAPIMethod', 2730 2730 'ConduitAPI_differential_setdiffproperty_Method' => 'ConduitAPIMethod', 2731 2731 'ConduitAPI_differential_updaterevision_Method' => 'ConduitAPI_differential_Method',
+26
src/applications/differential/conduit/ConduitAPI_differential_Method.php
··· 148 148 $editor->applyTransactions($revision, $xactions); 149 149 } 150 150 151 + protected function loadCustomFieldsForRevisions( 152 + PhabricatorUser $viewer, 153 + array $revisions) { 154 + assert_instances_of($revisions, 'DifferentialRevision'); 155 + 156 + $results = array(); 157 + foreach ($revisions as $revision) { 158 + // TODO: This is inefficient and issues a query for each object. 159 + $field_list = PhabricatorCustomField::getObjectFields( 160 + $revision, 161 + PhabricatorCustomField::ROLE_CONDUIT); 162 + 163 + $field_list 164 + ->setViewer($viewer) 165 + ->readFieldsFromStorage($revision); 166 + 167 + foreach ($field_list->getFields() as $field) { 168 + $field_key = $field->getFieldKeyForConduit(); 169 + $value = $field->getConduitDictionaryValue(); 170 + $results[$revision->getPHID()][$field_key] = $value; 171 + } 172 + } 173 + 174 + return $results; 175 + } 176 + 151 177 }
+5 -27
src/applications/differential/conduit/ConduitAPI_differential_getrevision_Method.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group conduit 5 - */ 6 3 final class ConduitAPI_differential_getrevision_Method 7 - extends ConduitAPIMethod { 4 + extends ConduitAPI_differential_Method { 8 5 9 6 public function getMethodStatus() { 10 7 return self::METHOD_STATUS_DEPRECATED; ··· 73 70 ); 74 71 } 75 72 76 - $auxiliary_fields = $this->loadAuxiliaryFields( 77 - $revision, 78 - $request->getUser()); 73 + $field_data = $this->loadCustomFieldsForRevisions( 74 + $request->getUser(), 75 + array($revision)); 79 76 80 77 $dict = array( 81 78 'id' => $revision->getID(), ··· 93 90 'reviewerPHIDs' => $reviewer_phids, 94 91 'diffs' => $diff_dicts, 95 92 'commits' => $commit_dicts, 96 - 'auxiliary' => $auxiliary_fields, 93 + 'auxiliary' => idx($field_data, $revision->getPHID(), array()) 97 94 ); 98 95 99 96 return $dict; 100 - } 101 - 102 - private function loadAuxiliaryFields( 103 - DifferentialRevision $revision, 104 - PhabricatorUser $user) { 105 - $aux_fields = DifferentialFieldSelector::newSelector() 106 - ->getFieldSpecifications(); 107 - foreach ($aux_fields as $key => $aux_field) { 108 - $aux_field->setUser($user); 109 - if (!$aux_field->shouldAppearOnConduitView()) { 110 - unset($aux_fields[$key]); 111 - } 112 - } 113 - 114 - $aux_fields = DifferentialAuxiliaryField::loadFromStorage( 115 - $revision, 116 - $aux_fields); 117 - 118 - return mpull($aux_fields, 'getValueForConduit', 'getKeyForConduit'); 119 97 } 120 98 121 99 }
+9 -27
src/applications/differential/conduit/ConduitAPI_differential_query_Method.php
··· 1 1 <?php 2 2 3 - /** 4 - * @group conduit 5 - */ 6 3 final class ConduitAPI_differential_query_Method 7 - extends ConduitAPIMethod { 4 + extends ConduitAPI_differential_Method { 8 5 9 6 public function getMethodDescription() { 10 7 return "Query Differential revisions which match certain criteria."; ··· 191 188 192 189 $revisions = $query->execute(); 193 190 191 + $field_data = $this->loadCustomFieldsForRevisions( 192 + $request->getUser(), 193 + $revisions); 194 + 194 195 $results = array(); 195 196 foreach ($revisions as $revision) { 196 197 $diff = $revision->getActiveDiff(); ··· 199 200 } 200 201 201 202 $id = $revision->getID(); 202 - $auxiliary_fields = $this->loadAuxiliaryFields( 203 - $revision, $request->getUser()); 203 + $phid = $revision->getPHID(); 204 + 204 205 $result = array( 205 206 'id' => $id, 206 - 'phid' => $revision->getPHID(), 207 + 'phid' => $phid, 207 208 'title' => $revision->getTitle(), 208 209 'uri' => PhabricatorEnv::getProductionURI('/D'.$id), 209 210 'dateCreated' => $revision->getDateCreated(), ··· 222 223 'reviewers' => array_values($revision->getReviewers()), 223 224 'ccs' => array_values($revision->getCCPHIDs()), 224 225 'hashes' => $revision->getHashes(), 225 - 'auxiliary' => $auxiliary_fields, 226 + 'auxiliary' => idx($field_data, $phid, array()), 226 227 'arcanistProjectPHID' => $diff->getArcanistProjectPHID() 227 228 ); 228 229 ··· 236 237 } 237 238 238 239 return $results; 239 - } 240 - 241 - private function loadAuxiliaryFields( 242 - DifferentialRevision $revision, 243 - PhabricatorUser $user) { 244 - $aux_fields = DifferentialFieldSelector::newSelector() 245 - ->getFieldSpecifications(); 246 - foreach ($aux_fields as $key => $aux_field) { 247 - $aux_field->setUser($user); 248 - if (!$aux_field->shouldAppearOnConduitView()) { 249 - unset($aux_fields[$key]); 250 - } 251 - } 252 - 253 - $aux_fields = DifferentialAuxiliaryField::loadFromStorage( 254 - $revision, 255 - $aux_fields); 256 - 257 - return mpull($aux_fields, 'getValueForConduit', 'getKeyForConduit'); 258 240 } 259 241 260 242 }
+4
src/applications/differential/customfield/DifferentialBlameRevisionField.php
··· 111 111 return $this->getValue(); 112 112 } 113 113 114 + public function shouldAppearInConduitDictionary() { 115 + return true; 116 + } 117 + 114 118 }
+4
src/applications/differential/customfield/DifferentialCoreCustomField.php
··· 126 126 return $this->getValue(); 127 127 } 128 128 129 + public function getConduitDictionaryValue() { 130 + return $this->getValue(); 131 + } 132 + 129 133 }
+14
src/applications/differential/customfield/DifferentialDependsOnField.php
··· 7 7 return 'differential:depends-on'; 8 8 } 9 9 10 + public function getFieldKeyForConduit() { 11 + return 'phabricator:depends-on'; 12 + } 13 + 10 14 public function getFieldName() { 11 15 return pht('Depends On'); 12 16 } ··· 43 47 'Create a dependendency between revisions by writing '. 44 48 '"Depends on D123" in your summary.'), 45 49 ); 50 + } 51 + 52 + public function shouldAppearInConduitDictionary() { 53 + return true; 54 + } 55 + 56 + public function getConduitDictionaryValue() { 57 + return PhabricatorEdgeQuery::loadDestinationPHIDs( 58 + $this->getObject()->getPHID(), 59 + PhabricatorEdgeConfig::TYPE_DREV_DEPENDS_ON_DREV); 46 60 } 47 61 48 62 }
+4
src/applications/differential/customfield/DifferentialJIRAIssuesField.php
··· 268 268 return implode(', ', $value); 269 269 } 270 270 271 + public function shouldAppearInConduitDictionary() { 272 + return true; 273 + } 274 + 271 275 }
+4
src/applications/differential/customfield/DifferentialRevertPlanField.php
··· 143 143 return $this->getValue(); 144 144 } 145 145 146 + public function shouldAppearInConduitDictionary() { 147 + return true; 148 + } 149 + 146 150 }
+4
src/applications/differential/customfield/DifferentialStoredCustomField.php
··· 44 44 return $this; 45 45 } 46 46 47 + public function getConduitDictionaryValue() { 48 + return $this->getValue(); 49 + } 50 + 47 51 }
-8
src/applications/differential/field/specification/DifferentialBlameRevisionFieldSpecification.php
··· 53 53 return $engine->markupText($this->value); 54 54 } 55 55 56 - public function shouldAppearOnConduitView() { 57 - return true; 58 - } 59 - 60 - public function getValueForConduit() { 61 - return $this->value; 62 - } 63 - 64 56 public function shouldAppearOnCommitMessage() { 65 57 return true; 66 58 }
-12
src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php
··· 35 35 PhabricatorEdgeConfig::TYPE_DREV_DEPENDS_ON_DREV); 36 36 } 37 37 38 - public function shouldAppearOnConduitView() { 39 - return true; 40 - } 41 - 42 - public function getValueForConduit() { 43 - return $this->getDependentRevisionPHIDs(); 44 - } 45 - 46 - public function getKeyForConduit() { 47 - return 'phabricator:depends-on'; 48 - } 49 - 50 38 }
-30
src/applications/differential/field/specification/DifferentialFieldSpecification.php
··· 13 13 * @task view Extending the Revision View Interface 14 14 * @task list Extending the Revision List Interface 15 15 * @task mail Extending the E-mail Interface 16 - * @task conduit Extending the Conduit View Interface 17 16 * @task commit Extending Commit Messages 18 17 * @task load Loading Additional Data 19 18 * @task context Contextual Data ··· 382 381 */ 383 382 public function renderValueForDiffView() { 384 383 throw new DifferentialFieldSpecificationIncompleteException($this); 385 - } 386 - 387 - 388 - /* -( Extending the Conduit Interface )------------------------------------ */ 389 - 390 - 391 - /** 392 - * @task conduit 393 - */ 394 - public function shouldAppearOnConduitView() { 395 - return false; 396 - } 397 - 398 - /** 399 - * @task conduit 400 - */ 401 - public function getValueForConduit() { 402 - throw new DifferentialFieldSpecificationIncompleteException($this); 403 - } 404 - 405 - /** 406 - * @task conduit 407 - */ 408 - public function getKeyForConduit() { 409 - $key = $this->getStorageKey(); 410 - if ($key === null) { 411 - throw new DifferentialFieldSpecificationIncompleteException($this); 412 - } 413 - return $key; 414 384 } 415 385 416 386 /* -( Extending the Search Interface )------------------------------------ */
-8
src/applications/differential/field/specification/DifferentialJIRAIssuesFieldSpecification.php
··· 65 65 return phutil_implode_html(phutil_tag('br'), $links); 66 66 } 67 67 68 - public function shouldAppearOnConduitView() { 69 - return true; 70 - } 71 - 72 - public function getValueForConduit() { 73 - return $this->value; 74 - } 75 - 76 68 public function shouldAppearOnCommitMessage() { 77 69 return true; 78 70 }
-8
src/applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php
··· 50 50 return $this->value; 51 51 } 52 52 53 - public function shouldAppearOnConduitView() { 54 - return true; 55 - } 56 - 57 - public function getValueForConduit() { 58 - return $this->value; 59 - } 60 - 61 53 public function shouldAppearOnCommitMessage() { 62 54 return true; 63 55 }
+28
src/infrastructure/customfield/field/PhabricatorCustomField.php
··· 27 27 const ROLE_VIEW = 'view'; 28 28 const ROLE_LIST = 'list'; 29 29 const ROLE_GLOBALSEARCH = 'GlobalSearch'; 30 + const ROLE_CONDUIT = 'conduit'; 30 31 31 32 32 33 /* -( Building Applications with Custom Fields )--------------------------- */ ··· 257 258 return $this->shouldAppearInListView(); 258 259 case self::ROLE_GLOBALSEARCH: 259 260 return $this->shouldAppearInGlobalSearch(); 261 + case self::ROLE_CONDUIT: 262 + return $this->shouldAppearInConduitDictionary(); 260 263 case self::ROLE_DEFAULT: 261 264 return true; 262 265 default: ··· 1164 1167 return $this->proxy->updateAbstractDocument($document); 1165 1168 } 1166 1169 return $document; 1170 + } 1171 + 1172 + 1173 + /* -( Conduit )------------------------------------------------------------ */ 1174 + 1175 + 1176 + /** 1177 + * @task conduit 1178 + */ 1179 + public function shouldAppearInConduitDictionary() { 1180 + if ($this->proxy) { 1181 + return $this->proxy->shouldAppearInConduitDictionary(); 1182 + } 1183 + return false; 1184 + } 1185 + 1186 + 1187 + /** 1188 + * @task conduit 1189 + */ 1190 + public function getConduitDictionaryValue() { 1191 + if ($this->proxy) { 1192 + return $this->proxy->getConduitDictionaryValue(); 1193 + } 1194 + throw new PhabricatorCustomFieldImplementationIncompleteException($this); 1167 1195 } 1168 1196 1169 1197