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

Modularize transactions for Drydock Blueprints

Summary: Ref PHI243. This is a followup to D18822, which added an edit-only `drydock.blueprint.edit`. By modularizing transactions (here) and then adding a "type" transaction (next change) I intend to remove the "edit-only" limitation and make this API method fully functional.

Test Plan: Created and edited blueprints via the web UI. Edited blueprints via the API. Disabled/enabled blueprints (currently web UI only).

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

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

+133 -127
+7 -1
src/__phutil_library_map__.php
··· 1008 1008 'DrydockBlueprintCustomField' => 'applications/drydock/customfield/DrydockBlueprintCustomField.php', 1009 1009 'DrydockBlueprintDatasource' => 'applications/drydock/typeahead/DrydockBlueprintDatasource.php', 1010 1010 'DrydockBlueprintDisableController' => 'applications/drydock/controller/DrydockBlueprintDisableController.php', 1011 + 'DrydockBlueprintDisableTransaction' => 'applications/drydock/xaction/DrydockBlueprintDisableTransaction.php', 1011 1012 'DrydockBlueprintEditConduitAPIMethod' => 'applications/drydock/conduit/DrydockBlueprintEditConduitAPIMethod.php', 1012 1013 'DrydockBlueprintEditController' => 'applications/drydock/controller/DrydockBlueprintEditController.php', 1013 1014 'DrydockBlueprintEditEngine' => 'applications/drydock/editor/DrydockBlueprintEditEngine.php', ··· 1016 1017 'DrydockBlueprintImplementationTestCase' => 'applications/drydock/blueprint/__tests__/DrydockBlueprintImplementationTestCase.php', 1017 1018 'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php', 1018 1019 'DrydockBlueprintNameNgrams' => 'applications/drydock/storage/DrydockBlueprintNameNgrams.php', 1020 + 'DrydockBlueprintNameTransaction' => 'applications/drydock/xaction/DrydockBlueprintNameTransaction.php', 1019 1021 'DrydockBlueprintPHIDType' => 'applications/drydock/phid/DrydockBlueprintPHIDType.php', 1020 1022 'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php', 1021 1023 'DrydockBlueprintSearchConduitAPIMethod' => 'applications/drydock/conduit/DrydockBlueprintSearchConduitAPIMethod.php', 1022 1024 'DrydockBlueprintSearchEngine' => 'applications/drydock/query/DrydockBlueprintSearchEngine.php', 1023 1025 'DrydockBlueprintTransaction' => 'applications/drydock/storage/DrydockBlueprintTransaction.php', 1024 1026 'DrydockBlueprintTransactionQuery' => 'applications/drydock/query/DrydockBlueprintTransactionQuery.php', 1027 + 'DrydockBlueprintTransactionType' => 'applications/drydock/xaction/DrydockBlueprintTransactionType.php', 1025 1028 'DrydockBlueprintViewController' => 'applications/drydock/controller/DrydockBlueprintViewController.php', 1026 1029 'DrydockCommand' => 'applications/drydock/storage/DrydockCommand.php', 1027 1030 'DrydockCommandError' => 'applications/drydock/exception/DrydockCommandError.php', ··· 6102 6105 'DrydockBlueprintCustomField' => 'PhabricatorCustomField', 6103 6106 'DrydockBlueprintDatasource' => 'PhabricatorTypeaheadDatasource', 6104 6107 'DrydockBlueprintDisableController' => 'DrydockBlueprintController', 6108 + 'DrydockBlueprintDisableTransaction' => 'DrydockBlueprintTransactionType', 6105 6109 'DrydockBlueprintEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 6106 6110 'DrydockBlueprintEditController' => 'DrydockBlueprintController', 6107 6111 'DrydockBlueprintEditEngine' => 'PhabricatorEditEngine', ··· 6110 6114 'DrydockBlueprintImplementationTestCase' => 'PhabricatorTestCase', 6111 6115 'DrydockBlueprintListController' => 'DrydockBlueprintController', 6112 6116 'DrydockBlueprintNameNgrams' => 'PhabricatorSearchNgrams', 6117 + 'DrydockBlueprintNameTransaction' => 'DrydockBlueprintTransactionType', 6113 6118 'DrydockBlueprintPHIDType' => 'PhabricatorPHIDType', 6114 6119 'DrydockBlueprintQuery' => 'DrydockQuery', 6115 6120 'DrydockBlueprintSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 6116 6121 'DrydockBlueprintSearchEngine' => 'PhabricatorApplicationSearchEngine', 6117 - 'DrydockBlueprintTransaction' => 'PhabricatorApplicationTransaction', 6122 + 'DrydockBlueprintTransaction' => 'PhabricatorModularTransaction', 6118 6123 'DrydockBlueprintTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 6124 + 'DrydockBlueprintTransactionType' => 'PhabricatorModularTransactionType', 6119 6125 'DrydockBlueprintViewController' => 'DrydockBlueprintController', 6120 6126 'DrydockCommand' => array( 6121 6127 'DrydockDAO',
+2 -1
src/applications/drydock/controller/DrydockBlueprintDisableController.php
··· 28 28 $xactions = array(); 29 29 30 30 $xactions[] = id(new DrydockBlueprintTransaction()) 31 - ->setTransactionType(DrydockBlueprintTransaction::TYPE_DISABLED) 31 + ->setTransactionType( 32 + DrydockBlueprintDisableTransaction::TRANSACTIONTYPE) 32 33 ->setNewValue($is_disable ? 1 : 0); 33 34 34 35 $editor = id(new DrydockBlueprintEditor())
+1 -1
src/applications/drydock/editor/DrydockBlueprintEditEngine.php
··· 121 121 ->setKey('name') 122 122 ->setLabel(pht('Name')) 123 123 ->setDescription(pht('Name of the blueprint.')) 124 - ->setTransactionType(DrydockBlueprintTransaction::TYPE_NAME) 124 + ->setTransactionType(DrydockBlueprintNameTransaction::TRANSACTIONTYPE) 125 125 ->setIsRequired(true) 126 126 ->setValue($object->getBlueprintName()), 127 127 );
+8 -92
src/applications/drydock/editor/DrydockBlueprintEditor.php
··· 11 11 return pht('Drydock Blueprints'); 12 12 } 13 13 14 + public function getCreateObjectTitle($author, $object) { 15 + return pht('%s created this blueprint.', $author); 16 + } 17 + 18 + public function getCreateObjectTitleForFeed($author, $object) { 19 + return pht('%s created %s.', $author, $object); 20 + } 21 + 14 22 protected function supportsSearch() { 15 23 return true; 16 24 } ··· 21 29 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 22 30 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 23 31 24 - $types[] = DrydockBlueprintTransaction::TYPE_NAME; 25 - $types[] = DrydockBlueprintTransaction::TYPE_DISABLED; 26 - 27 32 return $types; 28 - } 29 - 30 - protected function getCustomTransactionOldValue( 31 - PhabricatorLiskDAO $object, 32 - PhabricatorApplicationTransaction $xaction) { 33 - 34 - switch ($xaction->getTransactionType()) { 35 - case DrydockBlueprintTransaction::TYPE_NAME: 36 - return $object->getBlueprintName(); 37 - case DrydockBlueprintTransaction::TYPE_DISABLED: 38 - return (int)$object->getIsDisabled(); 39 - } 40 - 41 - return parent::getCustomTransactionOldValue($object, $xaction); 42 - } 43 - 44 - protected function getCustomTransactionNewValue( 45 - PhabricatorLiskDAO $object, 46 - PhabricatorApplicationTransaction $xaction) { 47 - 48 - switch ($xaction->getTransactionType()) { 49 - case DrydockBlueprintTransaction::TYPE_NAME: 50 - return $xaction->getNewValue(); 51 - case DrydockBlueprintTransaction::TYPE_DISABLED: 52 - return (int)$xaction->getNewValue(); 53 - } 54 - 55 - return parent::getCustomTransactionNewValue($object, $xaction); 56 - } 57 - 58 - protected function applyCustomInternalTransaction( 59 - PhabricatorLiskDAO $object, 60 - PhabricatorApplicationTransaction $xaction) { 61 - 62 - switch ($xaction->getTransactionType()) { 63 - case DrydockBlueprintTransaction::TYPE_NAME: 64 - $object->setBlueprintName($xaction->getNewValue()); 65 - return; 66 - case DrydockBlueprintTransaction::TYPE_DISABLED: 67 - $object->setIsDisabled((int)$xaction->getNewValue()); 68 - return; 69 - } 70 - 71 - return parent::applyCustomInternalTransaction($object, $xaction); 72 - } 73 - 74 - protected function applyCustomExternalTransaction( 75 - PhabricatorLiskDAO $object, 76 - PhabricatorApplicationTransaction $xaction) { 77 - 78 - switch ($xaction->getTransactionType()) { 79 - case DrydockBlueprintTransaction::TYPE_NAME: 80 - case DrydockBlueprintTransaction::TYPE_DISABLED: 81 - return; 82 - } 83 - 84 - return parent::applyCustomExternalTransaction($object, $xaction); 85 - } 86 - 87 - 88 - protected function validateTransaction( 89 - PhabricatorLiskDAO $object, 90 - $type, 91 - array $xactions) { 92 - 93 - $errors = parent::validateTransaction($object, $type, $xactions); 94 - 95 - switch ($type) { 96 - case DrydockBlueprintTransaction::TYPE_NAME: 97 - $missing = $this->validateIsEmptyTextField( 98 - $object->getBlueprintName(), 99 - $xactions); 100 - 101 - if ($missing) { 102 - $error = new PhabricatorApplicationTransactionValidationError( 103 - $type, 104 - pht('Required'), 105 - pht('You must choose a name for this blueprint.'), 106 - nonempty(last($xactions), null)); 107 - 108 - $error->setIsMissingFieldError(true); 109 - $errors[] = $error; 110 - continue; 111 - } 112 - 113 - break; 114 - } 115 - 116 - return $errors; 117 33 } 118 34 119 35 }
+3 -32
src/applications/drydock/storage/DrydockBlueprintTransaction.php
··· 1 1 <?php 2 2 3 3 final class DrydockBlueprintTransaction 4 - extends PhabricatorApplicationTransaction { 4 + extends PhabricatorModularTransaction { 5 5 6 6 const TYPE_NAME = 'drydock:blueprint:name'; 7 7 const TYPE_DISABLED = 'drydock:blueprint:disabled'; ··· 14 14 return DrydockBlueprintPHIDType::TYPECONST; 15 15 } 16 16 17 - public function getTitle() { 18 - $old = $this->getOldValue(); 19 - $new = $this->getNewValue(); 20 - $author_handle = $this->renderHandleLink($this->getAuthorPHID()); 21 - 22 - switch ($this->getTransactionType()) { 23 - case self::TYPE_NAME: 24 - if (!strlen($old)) { 25 - return pht( 26 - '%s created this blueprint.', 27 - $author_handle); 28 - } else { 29 - return pht( 30 - '%s renamed this blueprint from "%s" to "%s".', 31 - $author_handle, 32 - $old, 33 - $new); 34 - } 35 - case self::TYPE_DISABLED: 36 - if ($new) { 37 - return pht( 38 - '%s disabled this blueprint.', 39 - $author_handle); 40 - } else { 41 - return pht( 42 - '%s enabled this blueprint.', 43 - $author_handle); 44 - } 45 - } 46 - 47 - return parent::getTitle(); 17 + public function getBaseTransactionClass() { 18 + return 'DrydockBlueprintTransactionType'; 48 19 } 49 20 50 21 }
+48
src/applications/drydock/xaction/DrydockBlueprintDisableTransaction.php
··· 1 + <?php 2 + 3 + final class DrydockBlueprintDisableTransaction 4 + extends DrydockBlueprintTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'drydock:blueprint:disabled'; 7 + 8 + public function generateOldValue($object) { 9 + return (bool)$object->getIsDisabled(); 10 + } 11 + 12 + public function generateNewValue($object, $value) { 13 + return (bool)$value; 14 + } 15 + 16 + public function applyInternalEffects($object, $value) { 17 + $object->setIsDisabled((int)$value); 18 + } 19 + 20 + public function getTitle() { 21 + $new = $this->getNewValue(); 22 + if ($new) { 23 + return pht( 24 + '%s disabled this blueprint.', 25 + $this->renderAuthor()); 26 + } else { 27 + return pht( 28 + '%s enabled this blueprint.', 29 + $this->renderAuthor()); 30 + } 31 + } 32 + 33 + public function getTitleForFeed() { 34 + $new = $this->getNewValue(); 35 + if ($new) { 36 + return pht( 37 + '%s disabled %s.', 38 + $this->renderAuthor(), 39 + $this->renderObject()); 40 + } else { 41 + return pht( 42 + '%s enabled %s.', 43 + $this->renderAuthor(), 44 + $this->renderObject()); 45 + } 46 + } 47 + 48 + }
+60
src/applications/drydock/xaction/DrydockBlueprintNameTransaction.php
··· 1 + <?php 2 + 3 + final class DrydockBlueprintNameTransaction 4 + extends DrydockBlueprintTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'drydock:blueprint:name'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getBlueprintName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setBlueprintName($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s renamed this blueprint from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function getTitleForFeed() { 25 + $old = $this->getOldValue(); 26 + $new = $this->getNewValue(); 27 + 28 + return pht( 29 + '%s renamed %s from %s to %s.', 30 + $this->renderAuthor(), 31 + $this->renderObject(), 32 + $this->renderOldValue(), 33 + $this->renderNewValue()); 34 + } 35 + 36 + public function validateTransactions($object, array $xactions) { 37 + $errors = array(); 38 + 39 + $name = $object->getBlueprintName(); 40 + if ($this->isEmptyTextTransaction($name, $xactions)) { 41 + $errors[] = $this->newRequiredError( 42 + pht('Blueprints must have a name.')); 43 + } 44 + 45 + $max_length = $object->getColumnMaximumByteLength('blueprintName'); 46 + foreach ($xactions as $xaction) { 47 + $new_value = $xaction->getNewValue(); 48 + 49 + $new_length = strlen($new_value); 50 + if ($new_length > $max_length) { 51 + $errors[] = $this->newInvalidError( 52 + pht('Blueprint names can be no longer than %s characters.', 53 + new PhutilNumber($max_length))); 54 + } 55 + } 56 + 57 + return $errors; 58 + } 59 + 60 + }
+4
src/applications/drydock/xaction/DrydockBlueprintTransactionType.php
··· 1 + <?php 2 + 3 + abstract class DrydockBlueprintTransactionType 4 + extends PhabricatorModularTransactionType {}