Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / applications / differential / xaction / DifferentialRevisionPlanChangesTransaction.php
blob144152526dba79f20e1fb85ad03941f9ced5ebf6
1 <?php
3 final class DifferentialRevisionPlanChangesTransaction
4 extends DifferentialRevisionActionTransaction {
6 const TRANSACTIONTYPE = 'differential.revision.plan';
7 const ACTIONKEY = 'plan-changes';
9 protected function getRevisionActionLabel(
10 DifferentialRevision $revision,
11 PhabricatorUser $viewer) {
12 return pht('Plan Changes');
15 protected function getRevisionActionDescription(
16 DifferentialRevision $revision,
17 PhabricatorUser $viewer) {
18 return pht(
19 'This revision will be removed from review queues until it is revised.');
22 public function getIcon() {
23 return 'fa-headphones';
26 public function getColor() {
27 return 'red';
30 protected function getRevisionActionOrder() {
31 return 200;
34 public function getActionName() {
35 return pht('Planned Changes');
38 public function getCommandKeyword() {
39 return 'planchanges';
42 public function getCommandAliases() {
43 return array(
44 'rethink',
48 public function getCommandSummary() {
49 return pht('Plan changes to a revision.');
52 public function generateOldValue($object) {
53 return $object->isChangePlanned();
56 public function applyInternalEffects($object, $value) {
57 $status_planned = DifferentialRevisionStatus::CHANGES_PLANNED;
58 $object->setModernRevisionStatus($status_planned);
61 protected function validateAction($object, PhabricatorUser $viewer) {
62 if ($object->isDraft()) {
64 // See PHI346. Until the "Draft" state fully unprototypes, allow drafts
65 // to be moved to "changes planned" via the API. This preserves the
66 // behavior of "arc diff --plan-changes". We still prevent this
67 // transition from the web UI.
68 // TODO: Remove this once drafts leave prototype.
70 $editor = $this->getEditor();
71 $type_web = PhabricatorWebContentSource::SOURCECONST;
72 if ($editor->getContentSource()->getSource() == $type_web) {
73 throw new Exception(
74 pht('You can not plan changes to a draft revision.'));
78 if ($object->isChangePlanned()) {
79 throw new Exception(
80 pht(
81 'You can not request review of this revision because this '.
82 'revision is already under review and the action would have '.
83 'no effect.'));
86 if ($object->isClosed()) {
87 throw new Exception(
88 pht(
89 'You can not plan changes to this this revision because it has '.
90 'already been closed.'));
93 if (!$this->isViewerRevisionAuthor($object, $viewer)) {
94 throw new Exception(
95 pht(
96 'You can not plan changes to this revision because you do not '.
97 'own it. Only the author of a revision can plan changes to it.'));
101 public function getTitle() {
102 if ($this->isDraftDemotion()) {
103 return pht(
104 '%s returned this revision to the author for changes because remote '.
105 'builds failed.',
106 $this->renderAuthor());
107 } else {
108 return pht(
109 '%s planned changes to this revision.',
110 $this->renderAuthor());
114 public function getTitleForFeed() {
115 return pht(
116 '%s planned changes to %s.',
117 $this->renderAuthor(),
118 $this->renderObject());
121 private function isDraftDemotion() {
122 return (bool)$this->getMetadataValue('draft.demote');
125 public function getTransactionTypeForConduit($xaction) {
126 return 'plan-changes';
129 public function getFieldValuesForConduit($object, $data) {
130 return array();