1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

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
This commit is contained in:
epriestley 2014-03-29 09:16:02 -07:00
parent d3dbbec88d
commit c7bcecb9b0
7 changed files with 172 additions and 22 deletions

View file

@ -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',

View file

@ -42,7 +42,7 @@ final class PhabricatorApplicationReleeph extends PhabricatorApplication {
'edit/' => 'ReleephProjectEditController',
'cutbranch/' => 'ReleephBranchCreateController',
'action/(?P<action>.+)/' => 'ReleephProductActionController',
'history/' => 'ReleephProjectHistoryController',
'history/' => 'ReleephProductHistoryController',
),
),
'branch/' => array(

View file

@ -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);
}

View file

@ -1,6 +1,6 @@
<?php
final class ReleephProjectHistoryController extends ReleephProductController {
final class ReleephProductHistoryController extends ReleephProductController {
private $id;
@ -29,7 +29,8 @@ final class ReleephProjectHistoryController extends ReleephProductController {
$timeline = id(new PhabricatorApplicationTransactionView())
->setUser($viewer)
->setObjectPHID($product->getPHID())
->setTransactions($xactions);
->setTransactions($xactions)
->setShouldTerminate(true);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('History'));

View file

@ -0,0 +1,53 @@
<?php
final class ReleephProductEditor
extends PhabricatorApplicationTransactionEditor {
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = ReleephProductTransaction::TYPE_ACTIVE;
return $types;
}
public function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->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;
}
}

View file

@ -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();
}
}

View file

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