diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index abf0886972..31d4a73549 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2516,13 +2516,14 @@ phutil_register_library_map(array( 'ReleephPHIDTypeRequest' => 'applications/releeph/phid/ReleephPHIDTypeRequest.php', 'ReleephProductActionController' => 'applications/releeph/controller/project/ReleephProductActionController.php', 'ReleephProductController' => 'applications/releeph/controller/project/ReleephProductController.php', + 'ReleephProductEditor' => 'applications/releeph/editor/ReleephProductEditor.php', + 'ReleephProductHistoryController' => 'applications/releeph/controller/project/ReleephProductHistoryController.php', 'ReleephProductTransaction' => 'applications/releeph/storage/ReleephProductTransaction.php', 'ReleephProductTransactionQuery' => 'applications/releeph/query/ReleephProductTransactionQuery.php', 'ReleephProject' => 'applications/releeph/storage/ReleephProject.php', 'ReleephProjectController' => 'applications/releeph/controller/ReleephProjectController.php', 'ReleephProjectCreateController' => 'applications/releeph/controller/project/ReleephProjectCreateController.php', 'ReleephProjectEditController' => 'applications/releeph/controller/project/ReleephProjectEditController.php', - 'ReleephProjectHistoryController' => 'applications/releeph/controller/project/ReleephProjectHistoryController.php', 'ReleephProjectListController' => 'applications/releeph/controller/project/ReleephProjectListController.php', 'ReleephProjectQuery' => 'applications/releeph/query/ReleephProjectQuery.php', 'ReleephProjectSearchEngine' => 'applications/releeph/query/ReleephProjectSearchEngine.php', @@ -5490,6 +5491,8 @@ phutil_register_library_map(array( 'ReleephPHIDTypeRequest' => 'PhabricatorPHIDType', 'ReleephProductActionController' => 'ReleephProductController', 'ReleephProductController' => 'ReleephController', + 'ReleephProductEditor' => 'PhabricatorApplicationTransactionEditor', + 'ReleephProductHistoryController' => 'ReleephProductController', 'ReleephProductTransaction' => 'PhabricatorApplicationTransaction', 'ReleephProductTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'ReleephProject' => @@ -5500,7 +5503,6 @@ phutil_register_library_map(array( 'ReleephProjectController' => 'ReleephController', 'ReleephProjectCreateController' => 'ReleephProjectController', 'ReleephProjectEditController' => 'ReleephProjectController', - 'ReleephProjectHistoryController' => 'ReleephProductController', 'ReleephProjectListController' => array( 0 => 'ReleephController', diff --git a/src/applications/releeph/application/PhabricatorApplicationReleeph.php b/src/applications/releeph/application/PhabricatorApplicationReleeph.php index 66f1345d73..6ed13ab011 100644 --- a/src/applications/releeph/application/PhabricatorApplicationReleeph.php +++ b/src/applications/releeph/application/PhabricatorApplicationReleeph.php @@ -42,7 +42,7 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication { 'edit/' => 'ReleephProjectEditController', 'cutbranch/' => 'ReleephBranchCreateController', 'action/(?P.+)/' => 'ReleephProductActionController', - 'history/' => 'ReleephProjectHistoryController', + 'history/' => 'ReleephProductHistoryController', ), ), 'branch/' => array( diff --git a/src/applications/releeph/controller/project/ReleephProductActionController.php b/src/applications/releeph/controller/project/ReleephProductActionController.php index 3761c808c6..5337aebd72 100644 --- a/src/applications/releeph/controller/project/ReleephProductActionController.php +++ b/src/applications/releeph/controller/project/ReleephProductActionController.php @@ -42,12 +42,27 @@ final class ReleephProductActionController extends ReleephProductController { } if ($request->isFormPost()) { + $type_active = ReleephProductTransaction::TYPE_ACTIVE; + + $xactions = array(); if ($action == 'activate') { - $product->setIsActive(1)->save(); + $xactions[] = id(new ReleephProductTransaction()) + ->setTransactionType($type_active) + ->setNewValue(1); } else { - $product->deactivate($viewer)->save(); + $xactions[] = id(new ReleephProductTransaction()) + ->setTransactionType($type_active) + ->setNewValue(0); } + $editor = id(new ReleephProductEditor()) + ->setActor($viewer) + ->setContentSourceFromRequest($request) + ->setContinueOnNoEffect(true) + ->setContinueOnMissingFields(true); + + $editor->applyTransactions($product, $xactions); + return id(new AphrontRedirectResponse())->setURI($product_uri); } diff --git a/src/applications/releeph/controller/project/ReleephProjectHistoryController.php b/src/applications/releeph/controller/project/ReleephProductHistoryController.php similarity index 88% rename from src/applications/releeph/controller/project/ReleephProjectHistoryController.php rename to src/applications/releeph/controller/project/ReleephProductHistoryController.php index 873eb41073..cb76eba7e5 100644 --- a/src/applications/releeph/controller/project/ReleephProjectHistoryController.php +++ b/src/applications/releeph/controller/project/ReleephProductHistoryController.php @@ -1,6 +1,6 @@ setUser($viewer) ->setObjectPHID($product->getPHID()) - ->setTransactions($xactions); + ->setTransactions($xactions) + ->setShouldTerminate(true); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('History')); diff --git a/src/applications/releeph/editor/ReleephProductEditor.php b/src/applications/releeph/editor/ReleephProductEditor.php new file mode 100644 index 0000000000..93d59ceee3 --- /dev/null +++ b/src/applications/releeph/editor/ReleephProductEditor.php @@ -0,0 +1,53 @@ +getTransactionType()) { + case ReleephProductTransaction::TYPE_ACTIVE: + return (int)$object->getIsActive(); + } + } + + public function getCustomTransactionNewValue( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + switch ($xaction->getTransactionType()) { + case ReleephProductTransaction::TYPE_ACTIVE: + return (int)$xaction->getNewValue(); + } + } + + public function applyCustomInternalTransaction( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + $new = $xaction->getNewValue(); + + switch ($xaction->getTransactionType()) { + case ReleephProductTransaction::TYPE_ACTIVE: + $object->setIsActive($new); + break; + } + } + + protected function applyCustomExternalTransaction( + PhabricatorLiskDAO $object, + PhabricatorApplicationTransaction $xaction) { + + return; + } + +} diff --git a/src/applications/releeph/storage/ReleephProductTransaction.php b/src/applications/releeph/storage/ReleephProductTransaction.php index d34401a324..0a88262162 100644 --- a/src/applications/releeph/storage/ReleephProductTransaction.php +++ b/src/applications/releeph/storage/ReleephProductTransaction.php @@ -3,6 +3,8 @@ final class ReleephProductTransaction extends PhabricatorApplicationTransaction { + const TYPE_ACTIVE = 'releeph:product:active'; + public function getApplicationName() { return 'releeph'; } @@ -11,4 +13,96 @@ final class ReleephProductTransaction return ReleephPHIDTypeProject::TYPECONST; } + public function getColor() { + $old = $this->getOldValue(); + $new = $this->getNewValue(); + + switch ($this->getTransactionType()) { + case self::TYPE_ACTIVE: + if ($new) { + return 'green'; + } else { + return 'black'; + } + break; + } + + return parent::getColor(); + } + + public function getIcon() { + $old = $this->getOldValue(); + $new = $this->getNewValue(); + + switch ($this->getTransactionType()) { + case self::TYPE_ACTIVE: + if ($new) { + return 'edit'; + } else { + return 'delete'; + } + break; + } + + return parent::getIcon(); + } + + public function getTitle() { + $author_phid = $this->getAuthorPHID(); + + $old = $this->getOldValue(); + $new = $this->getNewValue(); + + switch ($this->getTransactionType()) { + case self::TYPE_ACTIVE: + if ($new) { + return pht( + '%s activated this product.', + $this->renderHandleLink($author_phid)); + } else { + return pht( + '%s deactivated this product.', + $this->renderHandleLink($author_phid)); + } + break; + } + + return parent::getTitle(); + } + + public function getTitleForFeed(PhabricatorFeedStory $story) { + $author_phid = $this->getAuthorPHID(); + $object_phid = $this->getObjectPHID(); + + $old = $this->getOldValue(); + $new = $this->getNewValue(); + + switch ($this->getTransactionType()) { + case self::TYPE_ACTIVE: + if ($new) { + return pht( + '%s activated release product %s.', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid)); + } else { + return pht( + '%s deactivated release product %s.', + $this->renderHandleLink($author_phid), + $this->renderHandleLink($object_phid)); + } + break; + } + + return parent::getTitleForFeed($story); + } + + public function getNoEffectDescription() { + switch ($this->getTransactionType()) { + case self::TYPE_ACTIVE: + return pht('The product is already in that state.'); + } + + return parent::getNoEffectDescription(); + } + } diff --git a/src/applications/releeph/storage/ReleephProject.php b/src/applications/releeph/storage/ReleephProject.php index 3258636caa..d811f50862 100644 --- a/src/applications/releeph/storage/ReleephProject.php +++ b/src/applications/releeph/storage/ReleephProject.php @@ -116,21 +116,6 @@ final class ReleephProject extends ReleephDAO return new ReleephDefaultFieldSelector(); } - /** - * Wrapper to setIsActive() that logs who deactivated a project - */ - public function deactivate(PhabricatorUser $actor) { - return $this - ->setIsActive(0) - ->setDetail('last_deactivated_user', $actor->getPHID()) - ->setDetail('last_deactivated_time', time()); - } - - // Hide this from the public - private function setIsActive($v) { - return parent::setIsActive($v); - } - private function getBannedNames() { return array( 'branch', // no one's tried this... yet!