1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 13:30:55 +01:00

Migrate Project status to modular transactions

Test Plan: Unit tests pass. Archived/activated some projects a couple times; observed expected transactions on timeline.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D17953
This commit is contained in:
Austin McKinley 2017-05-18 11:24:59 -07:00
parent 91eb22cb3a
commit f92059d84c
8 changed files with 76 additions and 61 deletions

View file

@ -34,7 +34,7 @@ foreach ($rows as $row) {
$type_map = array(
'name' => PhabricatorProjectNameTransaction::TRANSACTIONTYPE,
'members' => PhabricatorProjectTransaction::TYPE_MEMBERS,
'status' => PhabricatorProjectTransaction::TYPE_STATUS,
'status' => PhabricatorProjectStatusTransaction::TRANSACTIONTYPE,
'canview' => PhabricatorTransactions::TYPE_VIEW_POLICY,
'canedit' => PhabricatorTransactions::TYPE_EDIT_POLICY,
'canjoin' => PhabricatorTransactions::TYPE_JOIN_POLICY,

View file

@ -3669,6 +3669,7 @@ phutil_register_library_map(array(
'PhabricatorProjectSlugsTransaction' => 'applications/project/xaction/PhabricatorProjectSlugsTransaction.php',
'PhabricatorProjectStandardCustomField' => 'applications/project/customfield/PhabricatorProjectStandardCustomField.php',
'PhabricatorProjectStatus' => 'applications/project/constants/PhabricatorProjectStatus.php',
'PhabricatorProjectStatusTransaction' => 'applications/project/xaction/PhabricatorProjectStatusTransaction.php',
'PhabricatorProjectSubprojectWarningController' => 'applications/project/controller/PhabricatorProjectSubprojectWarningController.php',
'PhabricatorProjectSubprojectsController' => 'applications/project/controller/PhabricatorProjectSubprojectsController.php',
'PhabricatorProjectSubprojectsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php',
@ -9084,6 +9085,7 @@ phutil_register_library_map(array(
'PhabricatorStandardCustomFieldInterface',
),
'PhabricatorProjectStatus' => 'Phobject',
'PhabricatorProjectStatusTransaction' => 'PhabricatorProjectTransactionType',
'PhabricatorProjectSubprojectWarningController' => 'PhabricatorProjectController',
'PhabricatorProjectSubprojectsController' => 'PhabricatorProjectController',
'PhabricatorProjectSubprojectsProfileMenuItem' => 'PhabricatorProfileMenuItem',

View file

@ -32,7 +32,8 @@ final class PhabricatorProjectArchiveController
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorProjectTransaction::TYPE_STATUS)
->setTransactionType(
PhabricatorProjectStatusTransaction::TRANSACTIONTYPE)
->setNewValue($new_status);
id(new PhabricatorProjectTransactionEditor())

View file

@ -65,7 +65,8 @@ final class PhabricatorProjectColumnHideController
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorProjectTransaction::TYPE_STATUS)
->setTransactionType(
PhabricatorProjectStatusTransaction::TRANSACTIONTYPE)
->setNewValue($new_status);
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_STATUS;
$types[] = PhabricatorProjectTransaction::TYPE_IMAGE;
$types[] = PhabricatorProjectTransaction::TYPE_ICON;
$types[] = PhabricatorProjectTransaction::TYPE_COLOR;
@ -50,8 +49,6 @@ final class PhabricatorProjectTransactionEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_STATUS:
return $object->getStatus();
case PhabricatorProjectTransaction::TYPE_IMAGE:
return $object->getProfileImagePHID();
case PhabricatorProjectTransaction::TYPE_ICON:
@ -81,7 +78,6 @@ final class PhabricatorProjectTransactionEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_STATUS:
case PhabricatorProjectTransaction::TYPE_IMAGE:
case PhabricatorProjectTransaction::TYPE_ICON:
case PhabricatorProjectTransaction::TYPE_COLOR:
@ -109,9 +105,6 @@ final class PhabricatorProjectTransactionEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_STATUS:
$object->setStatus($xaction->getNewValue());
return;
case PhabricatorProjectTransaction::TYPE_IMAGE:
$object->setProfileImagePHID($xaction->getNewValue());
return;
@ -157,7 +150,6 @@ final class PhabricatorProjectTransactionEditor
$new = $xaction->getNewValue();
switch ($xaction->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_STATUS:
case PhabricatorProjectTransaction::TYPE_IMAGE:
case PhabricatorProjectTransaction::TYPE_ICON:
case PhabricatorProjectTransaction::TYPE_COLOR:
@ -343,7 +335,7 @@ final class PhabricatorProjectTransactionEditor
switch ($xaction->getTransactionType()) {
case PhabricatorProjectNameTransaction::TRANSACTIONTYPE:
case PhabricatorProjectTransaction::TYPE_STATUS:
case PhabricatorProjectStatusTransaction::TRANSACTIONTYPE:
case PhabricatorProjectTransaction::TYPE_IMAGE:
case PhabricatorProjectTransaction::TYPE_ICON:
case PhabricatorProjectTransaction::TYPE_COLOR:

View file

@ -20,7 +20,7 @@ final class PhabricatorProjectTestDataGenerator
$this->newProjectTitle());
$xactions[] = $this->newTransaction(
PhabricatorProjectTransaction::TYPE_STATUS,
PhabricatorProjectStatusTransaction::TRANSACTIONTYPE,
$this->newProjectStatus());
// Almost always make the author a member.

View file

@ -3,7 +3,6 @@
final class PhabricatorProjectTransaction
extends PhabricatorModularTransaction {
const TYPE_STATUS = 'project:status';
const TYPE_IMAGE = 'project:image';
const TYPE_ICON = 'project:icon';
const TYPE_COLOR = 'project:color';
@ -55,22 +54,6 @@ final class PhabricatorProjectTransaction
return array_merge($req_phids, parent::getRequiredHandlePHIDs());
}
public function getColor() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_STATUS:
if ($old == 0) {
return 'red';
} else {
return 'green';
}
}
return parent::getColor();
}
public function shouldHide() {
switch ($this->getTransactionType()) {
case PhabricatorTransactions::TYPE_EDGE:
@ -115,12 +98,6 @@ final class PhabricatorProjectTransaction
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_STATUS:
if ($old == 0) {
return 'fa-ban';
} else {
return 'fa-check';
}
case self::TYPE_LOCKED:
if ($new) {
return 'fa-lock';
@ -149,18 +126,6 @@ final class PhabricatorProjectTransaction
'%s created this project.',
$this->renderHandleLink($author_phid));
case self::TYPE_STATUS:
if ($old == 0) {
return pht(
'%s archived this project.',
$author_handle);
} else {
return pht(
'%s activated this project.',
$author_handle);
}
break;
case self::TYPE_IMAGE:
// TODO: Some day, it would be nice to show the images.
if (!$old) {
@ -288,18 +253,6 @@ final class PhabricatorProjectTransaction
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case self::TYPE_STATUS:
if ($old == 0) {
return pht(
'%s archived %s.',
$author_handle,
$object_handle);
} else {
return pht(
'%s activated %s.',
$author_handle,
$object_handle);
}
case self::TYPE_IMAGE:
// TODO: Some day, it would be nice to show the images.
if (!$old) {
@ -378,7 +331,7 @@ final class PhabricatorProjectTransaction
$tags[] = self::MAILTAG_OTHER;
}
break;
case self::TYPE_STATUS:
case PhabricatorProjectStatusTransaction::TRANSACTIONTYPE:
case self::TYPE_LOCKED:
default:
$tags[] = self::MAILTAG_OTHER;

View file

@ -0,0 +1,66 @@
<?php
final class PhabricatorProjectStatusTransaction
extends PhabricatorProjectTransactionType {
const TRANSACTIONTYPE = 'project:status';
public function generateOldValue($object) {
return $object->getStatus();
}
public function applyInternalEffects($object, $value) {
$object->setStatus($value);
}
public function getTitle() {
$old = $this->getOldValue();
if ($old == 0) {
return pht(
'%s archived this project.',
$this->renderAuthor());
} else {
return pht(
'%s activated this project.',
$this->renderAuthor());
}
}
public function getTitleForFeed() {
$old = $this->getOldValue();
if ($old == 0) {
return pht(
'%s archived %s.',
$this->renderAuthor(),
$this->renderObject());
} else {
return pht(
'%s activated %s.',
$this->renderAuthor(),
$this->renderObject());
}
}
public function getColor() {
$old = $this->getOldValue();
if ($old == 0) {
return 'red';
} else {
return 'green';
}
}
public function getIcon() {
$old = $this->getOldValue();
if ($old == 0) {
return 'fa-ban';
} else {
return 'fa-check';
}
}
}