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

Consolidate transaction generation in EditType objects

Summary:
Ref T9132. This is a bit more cleanup to make adding CustomField support easier.

Right now, both `EditField` and `EditType` can actually generate a transaction. This doesn't matter too much in practice today, but gets a little more complicated a couple of diffs from now with CustomField stuff.

Instead, always use `EditType` to generate the transaction. In the future, this should give us less total code and make more things work cleanly by default.

Test Plan: Used web UI and Conduit to make various edits to pastes, including doing race-condition tests on "Projects".

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9132

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

+73 -78
+24 -11
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 630 630 631 631 $xactions = array(); 632 632 foreach ($fields as $field) { 633 - $xaction = $field->generateTransaction(clone $template); 633 + $types = $field->getWebEditTypes(); 634 + foreach ($types as $type) { 635 + $type_xactions = $type->generateTransactions( 636 + clone $template, 637 + array( 638 + 'value' => $field->getValueForTransaction(), 639 + )); 640 + 641 + if (!$type_xactions) { 642 + continue; 643 + } 634 644 635 - if (!$xaction) { 636 - continue; 645 + foreach ($type_xactions as $type_xaction) { 646 + $xactions[] = $type_xaction; 647 + } 637 648 } 638 - 639 - $xactions[] = $xaction; 640 649 } 641 650 642 651 $editor = $object->getApplicationTransactionEditor() ··· 941 950 942 951 $fields = $this->buildEditFields($object); 943 952 944 - $types = $this->getAllEditTypesFromFields($fields); 953 + $types = $this->getConduitEditTypesFromFields($fields); 945 954 $template = $object->getApplicationTransactionTemplate(); 946 955 947 956 $xactions = $this->getConduitTransactions($request, $types, $template); ··· 1031 1040 foreach ($xactions as $xaction) { 1032 1041 $type = $types[$xaction['type']]; 1033 1042 1034 - $results[] = $type->generateTransaction( 1043 + $type_xactions = $type->generateTransactions( 1035 1044 clone $template, 1036 1045 $xaction); 1046 + 1047 + foreach ($type_xactions as $type_xaction) { 1048 + $results[] = $type_xaction; 1049 + } 1037 1050 } 1038 1051 1039 1052 return $results; ··· 1044 1057 * @return map<string, PhabricatorEditType> 1045 1058 * @task conduit 1046 1059 */ 1047 - private function getAllEditTypesFromFields(array $fields) { 1060 + private function getConduitEditTypesFromFields(array $fields) { 1048 1061 $types = array(); 1049 1062 foreach ($fields as $field) { 1050 - $field_types = $field->getEditTransactionTypes(); 1063 + $field_types = $field->getConduitEditTypes(); 1051 1064 1052 1065 if ($field_types === null) { 1053 1066 continue; ··· 1061 1074 return $types; 1062 1075 } 1063 1076 1064 - public function getAllEditTypes() { 1077 + public function getConduitEditTypes() { 1065 1078 $config = $this->loadEditEngineConfiguration(null); 1066 1079 if (!$config) { 1067 1080 return array(); ··· 1069 1082 1070 1083 $object = $this->newEditableObject(); 1071 1084 $fields = $this->buildEditFields($object); 1072 - return $this->getAllEditTypesFromFields($fields); 1085 + return $this->getConduitEditTypesFromFields($fields); 1073 1086 } 1074 1087 1075 1088 final public static function getAllEditEngines() {
+1 -1
src/applications/transactions/editengine/PhabricatorEditEngineAPIMethod.php
··· 44 44 $engine = $this->newEditEngine() 45 45 ->setViewer($viewer); 46 46 47 - $types = $engine->getAllEditTypes(); 47 + $types = $engine->getConduitEditTypes(); 48 48 49 49 $out = array(); 50 50
-11
src/applications/transactions/editfield/PhabricatorCommentEditField.php
··· 11 11 return new PhabricatorCommentEditType(); 12 12 } 13 13 14 - public function generateTransaction( 15 - PhabricatorApplicationTransaction $xaction) { 16 - 17 - $spec = array( 18 - 'value' => $this->getValueForTransaction(), 19 - ); 20 - 21 - return head($this->getEditTransactionTypes()) 22 - ->generateTransaction($xaction, $spec); 23 - } 24 - 25 14 }
+14 -22
src/applications/transactions/editfield/PhabricatorEditField.php
··· 268 268 return $this; 269 269 } 270 270 271 - public function generateTransaction( 272 - PhabricatorApplicationTransaction $xaction) { 273 - 274 - if (!$this->getTransactionType()) { 275 - return null; 276 - } 277 - 278 - $xaction 279 - ->setTransactionType($this->getTransactionType()) 280 - ->setNewValue($this->getValueForTransaction()); 281 - 282 - foreach ($this->metadata as $key => $value) { 283 - $xaction->setMetadataValue($key, $value); 284 - } 285 - 286 - return $xaction; 287 - } 288 - 289 271 public function setMetadataValue($key, $value) { 290 272 $this->metadata[$key] = $value; 291 273 return $this; ··· 295 277 return $this->metadata; 296 278 } 297 279 298 - protected function getValueForTransaction() { 280 + public function getValueForTransaction() { 299 281 return $this->getValue(); 300 282 } 301 283 ··· 449 431 ->setValueType($this->getHTTPParameterType()->getTypeName()); 450 432 } 451 433 452 - protected function getEditTransactionType() { 434 + protected function getEditType() { 453 435 $transaction_type = $this->getTransactionType(); 454 436 455 437 if ($transaction_type === null) { ··· 465 447 ->setMetadata($this->getMetadata()); 466 448 } 467 449 468 - public function getEditTransactionTypes() { 469 - $edit_type = $this->getEditTransactionType(); 450 + public function getConduitEditTypes() { 451 + $edit_type = $this->getEditType(); 452 + 453 + if ($edit_type === null) { 454 + return null; 455 + } 456 + 457 + return array($edit_type); 458 + } 459 + 460 + public function getWebEditTypes() { 461 + $edit_type = $this->getEditType(); 470 462 471 463 if ($edit_type === null) { 472 464 return null;
+4 -4
src/applications/transactions/editfield/PhabricatorPHIDListEditField.php
··· 28 28 return new AphrontPHIDListHTTPParameterType(); 29 29 } 30 30 31 - protected function getValueForTransaction() { 31 + public function getValueForTransaction() { 32 32 $new = parent::getValueForTransaction(); 33 33 34 34 if (!$this->getUseEdgeTransactions()) { ··· 71 71 return parent::newEditType(); 72 72 } 73 73 74 - public function getEditTransactionTypes() { 74 + public function getConduitEditTypes() { 75 75 if (!$this->getUseEdgeTransactions()) { 76 - return parent::getEditTransactionTypes(); 76 + return parent::getConduitEditTypes(); 77 77 } 78 78 79 79 $transaction_type = $this->getTransactionType(); ··· 84 84 $type_key = $this->getEditTypeKey(); 85 85 $strings = $this->transactionDescriptions; 86 86 87 - $base = $this->getEditTransactionType(); 87 + $base = $this->getEditType(); 88 88 89 89 $add = id(clone $base) 90 90 ->setEditType($type_key.'.add')
+3 -8
src/applications/transactions/edittype/PhabricatorCommentEditType.php
··· 6 6 return id(new AphrontStringHTTPParameterType())->getTypeName(); 7 7 } 8 8 9 - public function generateTransaction( 9 + public function generateTransactions( 10 10 PhabricatorApplicationTransaction $template, 11 11 array $spec) { 12 12 13 13 $comment = $template->getApplicationTransactionCommentObject() 14 14 ->setContent(idx($spec, 'value')); 15 15 16 - $template 17 - ->setTransactionType($this->getTransactionType()) 16 + $xaction = $this->newTransaction($template) 18 17 ->attachComment($comment); 19 18 20 - foreach ($this->getMetadata() as $key => $value) { 21 - $template->setMetadataValue($key, $value); 22 - } 23 - 24 - return $template; 19 + return array($xaction); 25 20 } 26 21 27 22 public function getValueDescription() {
+10 -12
src/applications/transactions/edittype/PhabricatorEdgeEditType.php
··· 18 18 return 'list<phid>'; 19 19 } 20 20 21 - public function generateTransaction( 21 + public function generateTransactions( 22 22 PhabricatorApplicationTransaction $template, 23 23 array $spec) { 24 24 25 25 $value = idx($spec, 'value'); 26 - $value = array_fuse($value); 27 - $value = array( 28 - $this->getEdgeOperation() => $value, 29 - ); 30 26 31 - $template 32 - ->setTransactionType($this->getTransactionType()) 33 - ->setNewValue($value); 34 - 35 - foreach ($this->getMetadata() as $key => $value) { 36 - $template->setMetadataValue($key, $value); 27 + if ($this->getEdgeOperation() !== null) { 28 + $value = array_fuse($value); 29 + $value = array( 30 + $this->getEdgeOperation() => $value, 31 + ); 37 32 } 38 33 39 - return $template; 34 + $xaction = $this->newTransaction($template) 35 + ->setNewValue($value); 36 + 37 + return array($xaction); 40 38 } 41 39 42 40 public function setValueDescription($value_description) {
+14 -1
src/applications/transactions/edittype/PhabricatorEditType.php
··· 66 66 return $this->transactionType; 67 67 } 68 68 69 - abstract public function generateTransaction( 69 + abstract public function generateTransactions( 70 70 PhabricatorApplicationTransaction $template, 71 71 array $spec); 72 72 73 73 abstract public function getValueType(); 74 74 abstract public function getValueDescription(); 75 + 76 + protected function newTransaction( 77 + PhabricatorApplicationTransaction $template) { 78 + 79 + $xaction = id(clone $template) 80 + ->setTransactionType($this->getTransactionType()); 81 + 82 + foreach ($this->getMetadata() as $key => $value) { 83 + $xaction->setMetadataValue($key, $value); 84 + } 85 + 86 + return $xaction; 87 + } 75 88 76 89 }
+3 -8
src/applications/transactions/edittype/PhabricatorSimpleEditType.php
··· 14 14 return $this->valueType; 15 15 } 16 16 17 - public function generateTransaction( 17 + public function generateTransactions( 18 18 PhabricatorApplicationTransaction $template, 19 19 array $spec) { 20 20 21 - $template 22 - ->setTransactionType($this->getTransactionType()) 21 + $edit = $this->newTransaction($template) 23 22 ->setNewValue(idx($spec, 'value')); 24 23 25 - foreach ($this->getMetadata() as $key => $value) { 26 - $template->setMetadataValue($key, $value); 27 - } 28 - 29 - return $template; 24 + return array($edit); 30 25 } 31 26 32 27 public function setValueDescription($value_description) {