1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-04 04:32:43 +01:00
phorge-phorge/src/applications/differential/xaction/DifferentialRevisionPlanChangesTransaction.php
epriestley a94528ee4a Expose Differential actions for "transaction.search" in a basic way
Summary:
See PHI725. Ref T13151. These actions are somewhat unusual and I considered different ways to represent them (make them look like "status" transactions; build multiple synthetic transactions) but ultimately landed on the simplest approach of just exposing them more or less as they exist internally.

I haven't included data for any of them. Most don't really have any data, but "accept" does. I'm holding off on providing more data until after T731, which may shake up the internal format.

Test Plan: Applied most of these transactions against a revision, queried for it with `transaction.search`, got distinguishable transactions out.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13151

Differential Revision: https://secure.phabricator.com/D19509
2018-06-28 08:51:55 -07:00

130 lines
3.4 KiB
PHP

<?php
final class DifferentialRevisionPlanChangesTransaction
extends DifferentialRevisionActionTransaction {
const TRANSACTIONTYPE = 'differential.revision.plan';
const ACTIONKEY = 'plan-changes';
protected function getRevisionActionLabel() {
return pht('Plan Changes');
}
protected function getRevisionActionDescription(
DifferentialRevision $revision) {
return pht(
'This revision will be removed from review queues until it is revised.');
}
public function getIcon() {
return 'fa-headphones';
}
public function getColor() {
return 'red';
}
protected function getRevisionActionOrder() {
return 200;
}
public function getActionName() {
return pht('Planned Changes');
}
public function getCommandKeyword() {
return 'planchanges';
}
public function getCommandAliases() {
return array(
'rethink',
);
}
public function getCommandSummary() {
return pht('Plan changes to a revision.');
}
public function generateOldValue($object) {
return $object->isChangePlanned();
}
public function applyInternalEffects($object, $value) {
$status_planned = DifferentialRevisionStatus::CHANGES_PLANNED;
$object->setModernRevisionStatus($status_planned);
}
protected function validateAction($object, PhabricatorUser $viewer) {
if ($object->isDraft()) {
// See PHI346. Until the "Draft" state fully unprototypes, allow drafts
// to be moved to "changes planned" via the API. This preserves the
// behavior of "arc diff --plan-changes". We still prevent this
// transition from the web UI.
// TODO: Remove this once drafts leave prototype.
$editor = $this->getEditor();
$type_web = PhabricatorWebContentSource::SOURCECONST;
if ($editor->getContentSource()->getSource() == $type_web) {
throw new Exception(
pht('You can not plan changes to a draft revision.'));
}
}
if ($object->isChangePlanned()) {
throw new Exception(
pht(
'You can not request review of this revision because this '.
'revision is already under review and the action would have '.
'no effect.'));
}
if ($object->isClosed()) {
throw new Exception(
pht(
'You can not plan changes to this this revision because it has '.
'already been closed.'));
}
if (!$this->isViewerRevisionAuthor($object, $viewer)) {
throw new Exception(
pht(
'You can not plan changes to this revision because you do not '.
'own it. Only the author of a revision can plan changes to it.'));
}
}
public function getTitle() {
if ($this->isDraftDemotion()) {
return pht(
'%s returned this revision to the author for changes because remote '.
'builds failed.',
$this->renderAuthor());
} else {
return pht(
'%s planned changes to this revision.',
$this->renderAuthor());
}
}
public function getTitleForFeed() {
return pht(
'%s planned changes to %s.',
$this->renderAuthor(),
$this->renderObject());
}
private function isDraftDemotion() {
return (bool)$this->getMetadataValue('draft.demote');
}
public function getTransactionTypeForConduit($xaction) {
return 'plan-changes';
}
public function getFieldValuesForConduit($object, $data) {
return array();
}
}