1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-03 19:31:02 +01:00

Migrate Project workboard to modular transactions

Summary: This was interesting, because there were a mix of callsites using transactions and others that just set the property on the `Project` object. I made everything consistent in using transactions to change this property. I also found an implementation of `getTitle()` that I don't think is ever being invoked since `shouldHide()` is returning `true`, but I migrated it anyway.

Test Plan: Unit tests pass + enabling/disabling workboards (and importing).

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D18004
This commit is contained in:
Austin McKinley 2017-05-23 11:54:37 -07:00
parent 7e822fc94f
commit 774fba3ce9
7 changed files with 68 additions and 27 deletions

View file

@ -3708,6 +3708,7 @@ phutil_register_library_map(array(
'PhabricatorProjectWatcherListView' => 'applications/project/view/PhabricatorProjectWatcherListView.php',
'PhabricatorProjectWorkboardBackgroundColor' => 'applications/project/constants/PhabricatorProjectWorkboardBackgroundColor.php',
'PhabricatorProjectWorkboardProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php',
'PhabricatorProjectWorkboardTransaction' => 'applications/project/xaction/PhabricatorProjectWorkboardTransaction.php',
'PhabricatorProjectsAncestorsSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsAncestorsSearchEngineAttachment.php',
'PhabricatorProjectsCurtainExtension' => 'applications/project/engineextension/PhabricatorProjectsCurtainExtension.php',
'PhabricatorProjectsEditEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsEditEngineExtension.php',
@ -9148,6 +9149,7 @@ phutil_register_library_map(array(
'PhabricatorProjectWatcherListView' => 'PhabricatorProjectUserListView',
'PhabricatorProjectWorkboardBackgroundColor' => 'Phobject',
'PhabricatorProjectWorkboardProfileMenuItem' => 'PhabricatorProfileMenuItem',
'PhabricatorProjectWorkboardTransaction' => 'PhabricatorProjectTransactionType',
'PhabricatorProjectsAncestorsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
'PhabricatorProjectsCurtainExtension' => 'PHUICurtainExtension',
'PhabricatorProjectsEditEngineExtension' => 'PhabricatorEditEngineExtension',

View file

@ -33,7 +33,8 @@ final class PhabricatorProjectBoardDisableController
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorProjectTransaction::TYPE_HASWORKBOARD)
->setTransactionType(
PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE)
->setNewValue(0);
id(new PhabricatorProjectTransactionEditor())

View file

@ -61,8 +61,18 @@ final class PhabricatorProjectBoardImportController
->setProperties($import_column->getProperties())
->save();
}
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(
PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE)
->setNewValue(1);
$project->setHasWorkboard(1)->save();
id(new PhabricatorProjectTransactionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($project, $xactions);
$table->saveTransaction();

View file

@ -966,7 +966,18 @@ final class PhabricatorProjectBoardViewController
->setProjectPHID($project->getPHID())
->save();
$project->setHasWorkboard(1)->save();
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(
PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE)
->setNewValue(1);
id(new PhabricatorProjectTransactionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())
->setURI($board_uri);
@ -1050,7 +1061,8 @@ final class PhabricatorProjectBoardViewController
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorProjectTransaction::TYPE_HASWORKBOARD)
->setTransactionType(
PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE)
->setNewValue(1);
id(new PhabricatorProjectTransactionEditor())

View file

@ -30,7 +30,6 @@ final class PhabricatorProjectTransactionEditor
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
$types[] = PhabricatorTransactions::TYPE_JOIN_POLICY;
$types[] = PhabricatorProjectTransaction::TYPE_HASWORKBOARD;
$types[] = PhabricatorProjectTransaction::TYPE_DEFAULT_SORT;
$types[] = PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER;
$types[] = PhabricatorProjectTransaction::TYPE_BACKGROUND;
@ -43,8 +42,6 @@ final class PhabricatorProjectTransactionEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_HASWORKBOARD:
return (int)$object->getHasWorkboard();
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
return $object->getDefaultWorkboardSort();
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
@ -64,8 +61,6 @@ final class PhabricatorProjectTransactionEditor
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
return $xaction->getNewValue();
case PhabricatorProjectTransaction::TYPE_HASWORKBOARD:
return (int)$xaction->getNewValue();
case PhabricatorProjectTransaction::TYPE_BACKGROUND:
$value = $xaction->getNewValue();
if (!strlen($value)) {
@ -82,9 +77,6 @@ final class PhabricatorProjectTransactionEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_HASWORKBOARD:
$object->setHasWorkboard($xaction->getNewValue());
return;
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
$object->setDefaultWorkboardSort($xaction->getNewValue());
return;
@ -107,7 +99,6 @@ final class PhabricatorProjectTransactionEditor
$new = $xaction->getNewValue();
switch ($xaction->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_HASWORKBOARD:
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
case PhabricatorProjectTransaction::TYPE_BACKGROUND:

View file

@ -3,7 +3,6 @@
final class PhabricatorProjectTransaction
extends PhabricatorModularTransaction {
const TYPE_HASWORKBOARD = 'project:hasworkboard';
const TYPE_DEFAULT_SORT = 'project:sort';
const TYPE_DEFAULT_FILTER = 'project:filter';
const TYPE_BACKGROUND = 'project:background';
@ -61,7 +60,6 @@ final class PhabricatorProjectTransaction
public function shouldHideForFeed() {
switch ($this->getTransactionType()) {
case self::TYPE_HASWORKBOARD:
case self::TYPE_DEFAULT_SORT:
case self::TYPE_DEFAULT_FILTER:
case self::TYPE_BACKGROUND:
@ -73,7 +71,7 @@ final class PhabricatorProjectTransaction
public function shouldHideForMail(array $xactions) {
switch ($this->getTransactionType()) {
case self::TYPE_HASWORKBOARD:
case PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE:
case self::TYPE_DEFAULT_SORT:
case self::TYPE_DEFAULT_FILTER:
case self::TYPE_BACKGROUND:
@ -142,17 +140,6 @@ final class PhabricatorProjectTransaction
}
break;
case self::TYPE_HASWORKBOARD:
if ($new) {
return pht(
'%s enabled the workboard for this project.',
$author_handle);
} else {
return pht(
'%s disabled the workboard for this project.',
$author_handle);
}
case self::TYPE_DEFAULT_SORT:
return pht(
'%s changed the default sort order for the project workboard.',

View file

@ -0,0 +1,38 @@
<?php
final class PhabricatorProjectWorkboardTransaction
extends PhabricatorProjectTransactionType {
const TRANSACTIONTYPE = 'project:hasworkboard';
public function generateOldValue($object) {
return (int)$object->getHasWorkboard();
}
public function generateNewValue($object, $value) {
return (int)$value;
}
public function applyInternalEffects($object, $value) {
$object->setHasWorkboard($value);
}
public function getTitle() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s enabled the workboard for this project.',
$this->renderAuthor());
} else {
return pht(
'%s disabled the workboard for this project.',
$this->renderAuthor());
}
}
public function shouldHide() {
return true;
}
}