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:
parent
7e822fc94f
commit
774fba3ce9
7 changed files with 68 additions and 27 deletions
|
@ -3708,6 +3708,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorProjectWatcherListView' => 'applications/project/view/PhabricatorProjectWatcherListView.php',
|
'PhabricatorProjectWatcherListView' => 'applications/project/view/PhabricatorProjectWatcherListView.php',
|
||||||
'PhabricatorProjectWorkboardBackgroundColor' => 'applications/project/constants/PhabricatorProjectWorkboardBackgroundColor.php',
|
'PhabricatorProjectWorkboardBackgroundColor' => 'applications/project/constants/PhabricatorProjectWorkboardBackgroundColor.php',
|
||||||
'PhabricatorProjectWorkboardProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php',
|
'PhabricatorProjectWorkboardProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php',
|
||||||
|
'PhabricatorProjectWorkboardTransaction' => 'applications/project/xaction/PhabricatorProjectWorkboardTransaction.php',
|
||||||
'PhabricatorProjectsAncestorsSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsAncestorsSearchEngineAttachment.php',
|
'PhabricatorProjectsAncestorsSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsAncestorsSearchEngineAttachment.php',
|
||||||
'PhabricatorProjectsCurtainExtension' => 'applications/project/engineextension/PhabricatorProjectsCurtainExtension.php',
|
'PhabricatorProjectsCurtainExtension' => 'applications/project/engineextension/PhabricatorProjectsCurtainExtension.php',
|
||||||
'PhabricatorProjectsEditEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsEditEngineExtension.php',
|
'PhabricatorProjectsEditEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsEditEngineExtension.php',
|
||||||
|
@ -9148,6 +9149,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorProjectWatcherListView' => 'PhabricatorProjectUserListView',
|
'PhabricatorProjectWatcherListView' => 'PhabricatorProjectUserListView',
|
||||||
'PhabricatorProjectWorkboardBackgroundColor' => 'Phobject',
|
'PhabricatorProjectWorkboardBackgroundColor' => 'Phobject',
|
||||||
'PhabricatorProjectWorkboardProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
'PhabricatorProjectWorkboardProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||||
|
'PhabricatorProjectWorkboardTransaction' => 'PhabricatorProjectTransactionType',
|
||||||
'PhabricatorProjectsAncestorsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
|
'PhabricatorProjectsAncestorsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
|
||||||
'PhabricatorProjectsCurtainExtension' => 'PHUICurtainExtension',
|
'PhabricatorProjectsCurtainExtension' => 'PHUICurtainExtension',
|
||||||
'PhabricatorProjectsEditEngineExtension' => 'PhabricatorEditEngineExtension',
|
'PhabricatorProjectsEditEngineExtension' => 'PhabricatorEditEngineExtension',
|
||||||
|
|
|
@ -33,7 +33,8 @@ final class PhabricatorProjectBoardDisableController
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
|
|
||||||
$xactions[] = id(new PhabricatorProjectTransaction())
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
||||||
->setTransactionType(PhabricatorProjectTransaction::TYPE_HASWORKBOARD)
|
->setTransactionType(
|
||||||
|
PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE)
|
||||||
->setNewValue(0);
|
->setNewValue(0);
|
||||||
|
|
||||||
id(new PhabricatorProjectTransactionEditor())
|
id(new PhabricatorProjectTransactionEditor())
|
||||||
|
|
|
@ -61,8 +61,18 @@ final class PhabricatorProjectBoardImportController
|
||||||
->setProperties($import_column->getProperties())
|
->setProperties($import_column->getProperties())
|
||||||
->save();
|
->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();
|
$table->saveTransaction();
|
||||||
|
|
||||||
|
|
|
@ -966,7 +966,18 @@ final class PhabricatorProjectBoardViewController
|
||||||
->setProjectPHID($project->getPHID())
|
->setProjectPHID($project->getPHID())
|
||||||
->save();
|
->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())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI($board_uri);
|
->setURI($board_uri);
|
||||||
|
@ -1050,7 +1061,8 @@ final class PhabricatorProjectBoardViewController
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
|
|
||||||
$xactions[] = id(new PhabricatorProjectTransaction())
|
$xactions[] = id(new PhabricatorProjectTransaction())
|
||||||
->setTransactionType(PhabricatorProjectTransaction::TYPE_HASWORKBOARD)
|
->setTransactionType(
|
||||||
|
PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE)
|
||||||
->setNewValue(1);
|
->setNewValue(1);
|
||||||
|
|
||||||
id(new PhabricatorProjectTransactionEditor())
|
id(new PhabricatorProjectTransactionEditor())
|
||||||
|
|
|
@ -30,7 +30,6 @@ final class PhabricatorProjectTransactionEditor
|
||||||
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||||
$types[] = PhabricatorTransactions::TYPE_JOIN_POLICY;
|
$types[] = PhabricatorTransactions::TYPE_JOIN_POLICY;
|
||||||
|
|
||||||
$types[] = PhabricatorProjectTransaction::TYPE_HASWORKBOARD;
|
|
||||||
$types[] = PhabricatorProjectTransaction::TYPE_DEFAULT_SORT;
|
$types[] = PhabricatorProjectTransaction::TYPE_DEFAULT_SORT;
|
||||||
$types[] = PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER;
|
$types[] = PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER;
|
||||||
$types[] = PhabricatorProjectTransaction::TYPE_BACKGROUND;
|
$types[] = PhabricatorProjectTransaction::TYPE_BACKGROUND;
|
||||||
|
@ -43,8 +42,6 @@ final class PhabricatorProjectTransactionEditor
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PhabricatorProjectTransaction::TYPE_HASWORKBOARD:
|
|
||||||
return (int)$object->getHasWorkboard();
|
|
||||||
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
|
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
|
||||||
return $object->getDefaultWorkboardSort();
|
return $object->getDefaultWorkboardSort();
|
||||||
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
|
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
|
||||||
|
@ -64,8 +61,6 @@ final class PhabricatorProjectTransactionEditor
|
||||||
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
|
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
|
||||||
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
|
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
|
||||||
return $xaction->getNewValue();
|
return $xaction->getNewValue();
|
||||||
case PhabricatorProjectTransaction::TYPE_HASWORKBOARD:
|
|
||||||
return (int)$xaction->getNewValue();
|
|
||||||
case PhabricatorProjectTransaction::TYPE_BACKGROUND:
|
case PhabricatorProjectTransaction::TYPE_BACKGROUND:
|
||||||
$value = $xaction->getNewValue();
|
$value = $xaction->getNewValue();
|
||||||
if (!strlen($value)) {
|
if (!strlen($value)) {
|
||||||
|
@ -82,9 +77,6 @@ final class PhabricatorProjectTransactionEditor
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
PhabricatorApplicationTransaction $xaction) {
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PhabricatorProjectTransaction::TYPE_HASWORKBOARD:
|
|
||||||
$object->setHasWorkboard($xaction->getNewValue());
|
|
||||||
return;
|
|
||||||
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
|
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
|
||||||
$object->setDefaultWorkboardSort($xaction->getNewValue());
|
$object->setDefaultWorkboardSort($xaction->getNewValue());
|
||||||
return;
|
return;
|
||||||
|
@ -107,7 +99,6 @@ final class PhabricatorProjectTransactionEditor
|
||||||
$new = $xaction->getNewValue();
|
$new = $xaction->getNewValue();
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
switch ($xaction->getTransactionType()) {
|
||||||
case PhabricatorProjectTransaction::TYPE_HASWORKBOARD:
|
|
||||||
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
|
case PhabricatorProjectTransaction::TYPE_DEFAULT_SORT:
|
||||||
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
|
case PhabricatorProjectTransaction::TYPE_DEFAULT_FILTER:
|
||||||
case PhabricatorProjectTransaction::TYPE_BACKGROUND:
|
case PhabricatorProjectTransaction::TYPE_BACKGROUND:
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
final class PhabricatorProjectTransaction
|
final class PhabricatorProjectTransaction
|
||||||
extends PhabricatorModularTransaction {
|
extends PhabricatorModularTransaction {
|
||||||
|
|
||||||
const TYPE_HASWORKBOARD = 'project:hasworkboard';
|
|
||||||
const TYPE_DEFAULT_SORT = 'project:sort';
|
const TYPE_DEFAULT_SORT = 'project:sort';
|
||||||
const TYPE_DEFAULT_FILTER = 'project:filter';
|
const TYPE_DEFAULT_FILTER = 'project:filter';
|
||||||
const TYPE_BACKGROUND = 'project:background';
|
const TYPE_BACKGROUND = 'project:background';
|
||||||
|
@ -61,7 +60,6 @@ final class PhabricatorProjectTransaction
|
||||||
|
|
||||||
public function shouldHideForFeed() {
|
public function shouldHideForFeed() {
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_HASWORKBOARD:
|
|
||||||
case self::TYPE_DEFAULT_SORT:
|
case self::TYPE_DEFAULT_SORT:
|
||||||
case self::TYPE_DEFAULT_FILTER:
|
case self::TYPE_DEFAULT_FILTER:
|
||||||
case self::TYPE_BACKGROUND:
|
case self::TYPE_BACKGROUND:
|
||||||
|
@ -73,7 +71,7 @@ final class PhabricatorProjectTransaction
|
||||||
|
|
||||||
public function shouldHideForMail(array $xactions) {
|
public function shouldHideForMail(array $xactions) {
|
||||||
switch ($this->getTransactionType()) {
|
switch ($this->getTransactionType()) {
|
||||||
case self::TYPE_HASWORKBOARD:
|
case PhabricatorProjectWorkboardTransaction::TRANSACTIONTYPE:
|
||||||
case self::TYPE_DEFAULT_SORT:
|
case self::TYPE_DEFAULT_SORT:
|
||||||
case self::TYPE_DEFAULT_FILTER:
|
case self::TYPE_DEFAULT_FILTER:
|
||||||
case self::TYPE_BACKGROUND:
|
case self::TYPE_BACKGROUND:
|
||||||
|
@ -142,17 +140,6 @@ final class PhabricatorProjectTransaction
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case self::TYPE_DEFAULT_SORT:
|
||||||
return pht(
|
return pht(
|
||||||
'%s changed the default sort order for the project workboard.',
|
'%s changed the default sort order for the project workboard.',
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue