@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 ApplicationTransactions for Releeph product activity

Summary:
Ref T3549. Ref T3663.

- Use transactions for activate/deactivate.
- Rename some "project" -> "product".

Test Plan:
- Activated products.
- Deactivated products.

{F135480}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T3663, T3549

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

+172 -22
+4 -2
src/__phutil_library_map__.php
··· 2516 2516 'ReleephPHIDTypeRequest' => 'applications/releeph/phid/ReleephPHIDTypeRequest.php', 2517 2517 'ReleephProductActionController' => 'applications/releeph/controller/project/ReleephProductActionController.php', 2518 2518 'ReleephProductController' => 'applications/releeph/controller/project/ReleephProductController.php', 2519 + 'ReleephProductEditor' => 'applications/releeph/editor/ReleephProductEditor.php', 2520 + 'ReleephProductHistoryController' => 'applications/releeph/controller/project/ReleephProductHistoryController.php', 2519 2521 'ReleephProductTransaction' => 'applications/releeph/storage/ReleephProductTransaction.php', 2520 2522 'ReleephProductTransactionQuery' => 'applications/releeph/query/ReleephProductTransactionQuery.php', 2521 2523 'ReleephProject' => 'applications/releeph/storage/ReleephProject.php', 2522 2524 'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php', 2523 2525 'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php', 2524 2526 'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php', 2525 - 'ReleephProjectHistoryController' => 'applications/releeph/controller/project/ReleephProjectHistoryController.php', 2526 2527 'ReleephProjectListController' => 'applications/releeph/controller/project/ReleephProjectListController.php', 2527 2528 'ReleephProjectQuery' => 'applications/releeph/query/ReleephProjectQuery.php', 2528 2529 'ReleephProjectSearchEngine' => 'applications/releeph/query/ReleephProjectSearchEngine.php', ··· 5490 5491 'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType', 5491 5492 'ReleephProductActionController' => 'ReleephProductController', 5492 5493 'ReleephProductController' => 'ReleephController', 5494 + 'ReleephProductEditor' => 'PhabricatorApplicationTransactionEditor', 5495 + 'ReleephProductHistoryController' => 'ReleephProductController', 5493 5496 'ReleephProductTransaction' => 'PhabricatorApplicationTransaction', 5494 5497 'ReleephProductTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 5495 5498 'ReleephProject' => ··· 5500 5503 'ReleephProjectController' => 'ReleephController', 5501 5504 'ReleephProjectCreateController' => 'ReleephProjectController', 5502 5505 'ReleephProjectEditController' => 'ReleephProjectController', 5503 - 'ReleephProjectHistoryController' => 'ReleephProductController', 5504 5506 'ReleephProjectListController' => 5505 5507 array( 5506 5508 0 => 'ReleephController',
+1 -1
src/applications/releeph/application/PhabricatorApplicationReleeph.php
··· 42 42 'edit/' => 'ReleephProjectEditController', 43 43 'cutbranch/' => 'ReleephBranchCreateController', 44 44 'action/(?P<action>.+)/' => 'ReleephProductActionController', 45 - 'history/' => 'ReleephProjectHistoryController', 45 + 'history/' => 'ReleephProductHistoryController', 46 46 ), 47 47 ), 48 48 'branch/' => array(
+17 -2
src/applications/releeph/controller/project/ReleephProductActionController.php
··· 42 42 } 43 43 44 44 if ($request->isFormPost()) { 45 + $type_active = ReleephProductTransaction::TYPE_ACTIVE; 46 + 47 + $xactions = array(); 45 48 if ($action == 'activate') { 46 - $product->setIsActive(1)->save(); 49 + $xactions[] = id(new ReleephProductTransaction()) 50 + ->setTransactionType($type_active) 51 + ->setNewValue(1); 47 52 } else { 48 - $product->deactivate($viewer)->save(); 53 + $xactions[] = id(new ReleephProductTransaction()) 54 + ->setTransactionType($type_active) 55 + ->setNewValue(0); 49 56 } 57 + 58 + $editor = id(new ReleephProductEditor()) 59 + ->setActor($viewer) 60 + ->setContentSourceFromRequest($request) 61 + ->setContinueOnNoEffect(true) 62 + ->setContinueOnMissingFields(true); 63 + 64 + $editor->applyTransactions($product, $xactions); 50 65 51 66 return id(new AphrontRedirectResponse())->setURI($product_uri); 52 67 }
+3 -2
src/applications/releeph/controller/project/ReleephProjectHistoryController.php src/applications/releeph/controller/project/ReleephProductHistoryController.php
··· 1 1 <?php 2 2 3 - final class ReleephProjectHistoryController extends ReleephProductController { 3 + final class ReleephProductHistoryController extends ReleephProductController { 4 4 5 5 private $id; 6 6 ··· 29 29 $timeline = id(new PhabricatorApplicationTransactionView()) 30 30 ->setUser($viewer) 31 31 ->setObjectPHID($product->getPHID()) 32 - ->setTransactions($xactions); 32 + ->setTransactions($xactions) 33 + ->setShouldTerminate(true); 33 34 34 35 $crumbs = $this->buildApplicationCrumbs(); 35 36 $crumbs->addTextCrumb(pht('History'));
+53
src/applications/releeph/editor/ReleephProductEditor.php
··· 1 + <?php 2 + 3 + final class ReleephProductEditor 4 + extends PhabricatorApplicationTransactionEditor { 5 + 6 + public function getTransactionTypes() { 7 + $types = parent::getTransactionTypes(); 8 + 9 + $types[] = ReleephProductTransaction::TYPE_ACTIVE; 10 + 11 + return $types; 12 + } 13 + 14 + public function getCustomTransactionOldValue( 15 + PhabricatorLiskDAO $object, 16 + PhabricatorApplicationTransaction $xaction) { 17 + 18 + switch ($xaction->getTransactionType()) { 19 + case ReleephProductTransaction::TYPE_ACTIVE: 20 + return (int)$object->getIsActive(); 21 + } 22 + } 23 + 24 + public function getCustomTransactionNewValue( 25 + PhabricatorLiskDAO $object, 26 + PhabricatorApplicationTransaction $xaction) { 27 + 28 + switch ($xaction->getTransactionType()) { 29 + case ReleephProductTransaction::TYPE_ACTIVE: 30 + return (int)$xaction->getNewValue(); 31 + } 32 + } 33 + 34 + public function applyCustomInternalTransaction( 35 + PhabricatorLiskDAO $object, 36 + PhabricatorApplicationTransaction $xaction) { 37 + $new = $xaction->getNewValue(); 38 + 39 + switch ($xaction->getTransactionType()) { 40 + case ReleephProductTransaction::TYPE_ACTIVE: 41 + $object->setIsActive($new); 42 + break; 43 + } 44 + } 45 + 46 + protected function applyCustomExternalTransaction( 47 + PhabricatorLiskDAO $object, 48 + PhabricatorApplicationTransaction $xaction) { 49 + 50 + return; 51 + } 52 + 53 + }
+94
src/applications/releeph/storage/ReleephProductTransaction.php
··· 3 3 final class ReleephProductTransaction 4 4 extends PhabricatorApplicationTransaction { 5 5 6 + const TYPE_ACTIVE = 'releeph:product:active'; 7 + 6 8 public function getApplicationName() { 7 9 return 'releeph'; 8 10 } 9 11 10 12 public function getApplicationTransactionType() { 11 13 return ReleephPHIDTypeProject::TYPECONST; 14 + } 15 + 16 + public function getColor() { 17 + $old = $this->getOldValue(); 18 + $new = $this->getNewValue(); 19 + 20 + switch ($this->getTransactionType()) { 21 + case self::TYPE_ACTIVE: 22 + if ($new) { 23 + return 'green'; 24 + } else { 25 + return 'black'; 26 + } 27 + break; 28 + } 29 + 30 + return parent::getColor(); 31 + } 32 + 33 + public function getIcon() { 34 + $old = $this->getOldValue(); 35 + $new = $this->getNewValue(); 36 + 37 + switch ($this->getTransactionType()) { 38 + case self::TYPE_ACTIVE: 39 + if ($new) { 40 + return 'edit'; 41 + } else { 42 + return 'delete'; 43 + } 44 + break; 45 + } 46 + 47 + return parent::getIcon(); 48 + } 49 + 50 + public function getTitle() { 51 + $author_phid = $this->getAuthorPHID(); 52 + 53 + $old = $this->getOldValue(); 54 + $new = $this->getNewValue(); 55 + 56 + switch ($this->getTransactionType()) { 57 + case self::TYPE_ACTIVE: 58 + if ($new) { 59 + return pht( 60 + '%s activated this product.', 61 + $this->renderHandleLink($author_phid)); 62 + } else { 63 + return pht( 64 + '%s deactivated this product.', 65 + $this->renderHandleLink($author_phid)); 66 + } 67 + break; 68 + } 69 + 70 + return parent::getTitle(); 71 + } 72 + 73 + public function getTitleForFeed(PhabricatorFeedStory $story) { 74 + $author_phid = $this->getAuthorPHID(); 75 + $object_phid = $this->getObjectPHID(); 76 + 77 + $old = $this->getOldValue(); 78 + $new = $this->getNewValue(); 79 + 80 + switch ($this->getTransactionType()) { 81 + case self::TYPE_ACTIVE: 82 + if ($new) { 83 + return pht( 84 + '%s activated release product %s.', 85 + $this->renderHandleLink($author_phid), 86 + $this->renderHandleLink($object_phid)); 87 + } else { 88 + return pht( 89 + '%s deactivated release product %s.', 90 + $this->renderHandleLink($author_phid), 91 + $this->renderHandleLink($object_phid)); 92 + } 93 + break; 94 + } 95 + 96 + return parent::getTitleForFeed($story); 97 + } 98 + 99 + public function getNoEffectDescription() { 100 + switch ($this->getTransactionType()) { 101 + case self::TYPE_ACTIVE: 102 + return pht('The product is already in that state.'); 103 + } 104 + 105 + return parent::getNoEffectDescription(); 12 106 } 13 107 14 108 }
-15
src/applications/releeph/storage/ReleephProject.php
··· 116 116 return new ReleephDefaultFieldSelector(); 117 117 } 118 118 119 - /** 120 - * Wrapper to setIsActive() that logs who deactivated a project 121 - */ 122 - public function deactivate(PhabricatorUser $actor) { 123 - return $this 124 - ->setIsActive(0) 125 - ->setDetail('last_deactivated_user', $actor->getPHID()) 126 - ->setDetail('last_deactivated_time', time()); 127 - } 128 - 129 - // Hide this from the public 130 - private function setIsActive($v) { 131 - return parent::setIsActive($v); 132 - } 133 - 134 119 private function getBannedNames() { 135 120 return array( 136 121 'branch', // no one's tried this... yet!