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

Move Harbormaster Build Plans to modular transactions

Summary: Depends on D20216. Ref T13258. Bland infrastructure update to prepare for bigger things.

Test Plan: Created and edited a build plan.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13258

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

+149 -154
+7 -1
src/__phutil_library_map__.php
··· 1334 1334 'HarbormasterBuildPlanEditEngine' => 'applications/harbormaster/editor/HarbormasterBuildPlanEditEngine.php', 1335 1335 'HarbormasterBuildPlanEditor' => 'applications/harbormaster/editor/HarbormasterBuildPlanEditor.php', 1336 1336 'HarbormasterBuildPlanNameNgrams' => 'applications/harbormaster/storage/configuration/HarbormasterBuildPlanNameNgrams.php', 1337 + 'HarbormasterBuildPlanNameTransaction' => 'applications/harbormaster/xaction/plan/HarbormasterBuildPlanNameTransaction.php', 1337 1338 'HarbormasterBuildPlanPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildPlanPHIDType.php', 1338 1339 'HarbormasterBuildPlanQuery' => 'applications/harbormaster/query/HarbormasterBuildPlanQuery.php', 1339 1340 'HarbormasterBuildPlanSearchAPIMethod' => 'applications/harbormaster/conduit/HarbormasterBuildPlanSearchAPIMethod.php', 1340 1341 'HarbormasterBuildPlanSearchEngine' => 'applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php', 1342 + 'HarbormasterBuildPlanStatusTransaction' => 'applications/harbormaster/xaction/plan/HarbormasterBuildPlanStatusTransaction.php', 1341 1343 'HarbormasterBuildPlanTransaction' => 'applications/harbormaster/storage/configuration/HarbormasterBuildPlanTransaction.php', 1342 1344 'HarbormasterBuildPlanTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildPlanTransactionQuery.php', 1345 + 'HarbormasterBuildPlanTransactionType' => 'applications/harbormaster/xaction/plan/HarbormasterBuildPlanTransactionType.php', 1343 1346 'HarbormasterBuildQuery' => 'applications/harbormaster/query/HarbormasterBuildQuery.php', 1344 1347 'HarbormasterBuildRequest' => 'applications/harbormaster/engine/HarbormasterBuildRequest.php', 1345 1348 'HarbormasterBuildSearchConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterBuildSearchConduitAPIMethod.php', ··· 6943 6946 'HarbormasterBuildPlanEditEngine' => 'PhabricatorEditEngine', 6944 6947 'HarbormasterBuildPlanEditor' => 'PhabricatorApplicationTransactionEditor', 6945 6948 'HarbormasterBuildPlanNameNgrams' => 'PhabricatorSearchNgrams', 6949 + 'HarbormasterBuildPlanNameTransaction' => 'HarbormasterBuildPlanTransactionType', 6946 6950 'HarbormasterBuildPlanPHIDType' => 'PhabricatorPHIDType', 6947 6951 'HarbormasterBuildPlanQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6948 6952 'HarbormasterBuildPlanSearchAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 6949 6953 'HarbormasterBuildPlanSearchEngine' => 'PhabricatorApplicationSearchEngine', 6950 - 'HarbormasterBuildPlanTransaction' => 'PhabricatorApplicationTransaction', 6954 + 'HarbormasterBuildPlanStatusTransaction' => 'HarbormasterBuildPlanTransactionType', 6955 + 'HarbormasterBuildPlanTransaction' => 'PhabricatorModularTransaction', 6951 6956 'HarbormasterBuildPlanTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 6957 + 'HarbormasterBuildPlanTransactionType' => 'PhabricatorModularTransactionType', 6952 6958 'HarbormasterBuildQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6953 6959 'HarbormasterBuildRequest' => 'Phobject', 6954 6960 'HarbormasterBuildSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
+2 -2
src/applications/harbormaster/controller/HarbormasterPlanDisableController.php
··· 19 19 return new Aphront404Response(); 20 20 } 21 21 22 - $plan_uri = $this->getApplicationURI('plan/'.$plan->getID().'/'); 22 + $plan_uri = $plan->getURI(); 23 23 24 24 if ($request->isFormPost()) { 25 25 26 - $type_status = HarbormasterBuildPlanTransaction::TYPE_STATUS; 26 + $type_status = HarbormasterBuildPlanStatusTransaction::TRANSACTIONTYPE; 27 27 28 28 $v_status = $plan->isDisabled() 29 29 ? HarbormasterBuildPlan::STATUS_ACTIVE
+2 -1
src/applications/harbormaster/editor/HarbormasterBuildPlanEditEngine.php
··· 82 82 ->setKey('name') 83 83 ->setLabel(pht('Name')) 84 84 ->setIsRequired(true) 85 - ->setTransactionType(HarbormasterBuildPlanTransaction::TYPE_NAME) 85 + ->setTransactionType( 86 + HarbormasterBuildPlanNameTransaction::TRANSACTIONTYPE) 86 87 ->setDescription(pht('The build plan name.')) 87 88 ->setConduitDescription(pht('Rename the plan.')) 88 89 ->setConduitTypeDescription(pht('New plan name.'))
+8 -85
src/applications/harbormaster/editor/HarbormasterBuildPlanEditor.php
··· 11 11 return pht('Harbormaster Build Plans'); 12 12 } 13 13 14 + public function getCreateObjectTitle($author, $object) { 15 + return pht('%s created this build plan.', $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 } 17 25 18 26 public function getTransactionTypes() { 19 27 $types = parent::getTransactionTypes(); 20 - $types[] = HarbormasterBuildPlanTransaction::TYPE_NAME; 21 - $types[] = HarbormasterBuildPlanTransaction::TYPE_STATUS; 22 28 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 23 29 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 24 30 return $types; 25 31 } 26 - 27 - protected function getCustomTransactionOldValue( 28 - PhabricatorLiskDAO $object, 29 - PhabricatorApplicationTransaction $xaction) { 30 - switch ($xaction->getTransactionType()) { 31 - case HarbormasterBuildPlanTransaction::TYPE_NAME: 32 - if ($this->getIsNewObject()) { 33 - return null; 34 - } 35 - return $object->getName(); 36 - case HarbormasterBuildPlanTransaction::TYPE_STATUS: 37 - return $object->getPlanStatus(); 38 - } 39 - 40 - return parent::getCustomTransactionOldValue($object, $xaction); 41 - } 42 - 43 - protected function getCustomTransactionNewValue( 44 - PhabricatorLiskDAO $object, 45 - PhabricatorApplicationTransaction $xaction) { 46 - switch ($xaction->getTransactionType()) { 47 - case HarbormasterBuildPlanTransaction::TYPE_NAME: 48 - return $xaction->getNewValue(); 49 - case HarbormasterBuildPlanTransaction::TYPE_STATUS: 50 - return $xaction->getNewValue(); 51 - } 52 - return parent::getCustomTransactionNewValue($object, $xaction); 53 - } 54 - 55 - protected function applyCustomInternalTransaction( 56 - PhabricatorLiskDAO $object, 57 - PhabricatorApplicationTransaction $xaction) { 58 - switch ($xaction->getTransactionType()) { 59 - case HarbormasterBuildPlanTransaction::TYPE_NAME: 60 - $object->setName($xaction->getNewValue()); 61 - return; 62 - case HarbormasterBuildPlanTransaction::TYPE_STATUS: 63 - $object->setPlanStatus($xaction->getNewValue()); 64 - return; 65 - } 66 - return parent::applyCustomInternalTransaction($object, $xaction); 67 - } 68 - 69 - protected function applyCustomExternalTransaction( 70 - PhabricatorLiskDAO $object, 71 - PhabricatorApplicationTransaction $xaction) { 72 - switch ($xaction->getTransactionType()) { 73 - case HarbormasterBuildPlanTransaction::TYPE_NAME: 74 - case HarbormasterBuildPlanTransaction::TYPE_STATUS: 75 - return; 76 - } 77 - return parent::applyCustomExternalTransaction($object, $xaction); 78 - } 79 - 80 - protected function validateTransaction( 81 - PhabricatorLiskDAO $object, 82 - $type, 83 - array $xactions) { 84 - 85 - $errors = parent::validateTransaction($object, $type, $xactions); 86 - 87 - switch ($type) { 88 - case HarbormasterBuildPlanTransaction::TYPE_NAME: 89 - $missing = $this->validateIsEmptyTextField( 90 - $object->getName(), 91 - $xactions); 92 - 93 - if ($missing) { 94 - $error = new PhabricatorApplicationTransactionValidationError( 95 - $type, 96 - pht('Required'), 97 - pht('You must choose a name for your build plan.'), 98 - last($xactions)); 99 - 100 - $error->setIsMissingFieldError(true); 101 - $errors[] = $error; 102 - } 103 - break; 104 - } 105 - 106 - return $errors; 107 - } 108 - 109 32 110 33 }
+10
src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php
··· 84 84 return ($this->getPlanStatus() == self::STATUS_DISABLED); 85 85 } 86 86 87 + public function getURI() { 88 + return urisprintf( 89 + '/harbormaster/plan/%s/', 90 + $this->getID()); 91 + } 92 + 93 + public function getObjectName() { 94 + return pht('Build Plan %d', $this->getID()); 95 + } 96 + 87 97 88 98 /* -( Autoplans )---------------------------------------------------------- */ 89 99
+3 -65
src/applications/harbormaster/storage/configuration/HarbormasterBuildPlanTransaction.php
··· 1 1 <?php 2 2 3 3 final class HarbormasterBuildPlanTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_NAME = 'harbormaster:name'; 7 - const TYPE_STATUS = 'harbormaster:status'; 4 + extends PhabricatorModularTransaction { 8 5 9 6 public function getApplicationName() { 10 7 return 'harbormaster'; ··· 14 11 return HarbormasterBuildPlanPHIDType::TYPECONST; 15 12 } 16 13 17 - public function getIcon() { 18 - $old = $this->getOldValue(); 19 - $new = $this->getNewValue(); 20 - 21 - switch ($this->getTransactionType()) { 22 - case self::TYPE_NAME: 23 - if ($old === null) { 24 - return 'fa-plus'; 25 - } 26 - break; 27 - } 28 - 29 - return parent::getIcon(); 30 - } 31 - 32 - public function getColor() { 33 - $old = $this->getOldValue(); 34 - $new = $this->getNewValue(); 35 - 36 - switch ($this->getTransactionType()) { 37 - case self::TYPE_NAME: 38 - if ($old === null) { 39 - return 'green'; 40 - } 41 - break; 42 - } 43 - 44 - return parent::getIcon(); 45 - } 46 - 47 - public function getTitle() { 48 - $old = $this->getOldValue(); 49 - $new = $this->getNewValue(); 50 - $author_handle = $this->renderHandleLink($this->getAuthorPHID()); 51 - 52 - switch ($this->getTransactionType()) { 53 - case self::TYPE_NAME: 54 - if ($old === null) { 55 - return pht( 56 - '%s created this build plan.', 57 - $author_handle); 58 - } else { 59 - return pht( 60 - '%s renamed this build plan from "%s" to "%s".', 61 - $author_handle, 62 - $old, 63 - $new); 64 - } 65 - case self::TYPE_STATUS: 66 - if ($new == HarbormasterBuildPlan::STATUS_DISABLED) { 67 - return pht( 68 - '%s disabled this build plan.', 69 - $author_handle); 70 - } else { 71 - return pht( 72 - '%s enabled this build plan.', 73 - $author_handle); 74 - } 75 - } 76 - 77 - return parent::getTitle(); 14 + public function getBaseTransactionClass() { 15 + return 'HarbormasterBuildPlanTransactionType'; 78 16 } 79 17 80 18 }
+46
src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanNameTransaction.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildPlanNameTransaction 4 + extends HarbormasterBuildPlanTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'harbormaster:name'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setName($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s renamed this build plan from "%s" to "%s".', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function validateTransactions($object, array $xactions) { 25 + $errors = array(); 26 + 27 + if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { 28 + $errors[] = $this->newRequiredError( 29 + pht('You must choose a name for your build plan.')); 30 + } 31 + 32 + return $errors; 33 + } 34 + 35 + public function getTransactionTypeForConduit($xaction) { 36 + return 'name'; 37 + } 38 + 39 + public function getFieldValuesForConduit($xaction, $data) { 40 + return array( 41 + 'old' => $xaction->getOldValue(), 42 + 'new' => $xaction->getNewValue(), 43 + ); 44 + } 45 + 46 + }
+67
src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanStatusTransaction.php
··· 1 + <?php 2 + 3 + final class HarbormasterBuildPlanStatusTransaction 4 + extends HarbormasterBuildPlanTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'harbormaster:status'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getPlanStatus(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setPlanStatus($value); 14 + } 15 + 16 + public function getTitle() { 17 + $new = $this->getNewValue(); 18 + if ($new === HarbormasterBuildPlan::STATUS_DISABLED) { 19 + return pht( 20 + '%s disabled this build plan.', 21 + $this->renderAuthor()); 22 + } else { 23 + return pht( 24 + '%s enabled this build plan.', 25 + $this->renderAuthor()); 26 + } 27 + } 28 + 29 + public function validateTransactions($object, array $xactions) { 30 + $errors = array(); 31 + 32 + $options = array( 33 + HarbormasterBuildPlan::STATUS_DISABLED, 34 + HarbormasterBuildPlan::STATUS_ACTIVE, 35 + ); 36 + $options = array_fuse($options); 37 + 38 + foreach ($xactions as $xaction) { 39 + $new = $xaction->getNewValue(); 40 + 41 + if (!isset($options[$new])) { 42 + $errors[] = $this->newInvalidError( 43 + pht( 44 + 'Status "%s" is not a valid build plan status. Valid '. 45 + 'statuses are: %s.', 46 + $new, 47 + implode(', ', $options))); 48 + continue; 49 + } 50 + 51 + } 52 + 53 + return $errors; 54 + } 55 + 56 + public function getTransactionTypeForConduit($xaction) { 57 + return 'status'; 58 + } 59 + 60 + public function getFieldValuesForConduit($xaction, $data) { 61 + return array( 62 + 'old' => $xaction->getOldValue(), 63 + 'new' => $xaction->getNewValue(), 64 + ); 65 + } 66 + 67 + }
+4
src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanTransactionType.php
··· 1 + <?php 2 + 3 + abstract class HarbormasterBuildPlanTransactionType 4 + extends PhabricatorModularTransactionType {}