Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / applications / differential / xaction / DifferentialRevisionAuthorTransaction.php
blobd60404b8e0ca534fae885c49a25956d5b9af6674
1 <?php
3 final class DifferentialRevisionAuthorTransaction
4 extends DifferentialRevisionTransactionType {
6 const TRANSACTIONTYPE = 'differential.revision.author';
7 const EDITKEY = 'author';
9 public function generateOldValue($object) {
10 return $object->getAuthorPHID();
13 public function generateNewValue($object, $value) {
14 return $value;
17 public function applyInternalEffects($object, $value) {
18 $object->setAuthorPHID($value);
21 public function validateTransactions($object, array $xactions) {
22 $actor = $this->getActor();
23 $errors = array();
25 if (!$xactions) {
26 return $errors;
29 foreach ($xactions as $xaction) {
30 $old = $xaction->generateOldValue($object);
31 $new = $xaction->getNewValue();
33 if ($old === $new) {
34 continue;
37 if (!$new) {
38 $errors[] = $this->newInvalidError(
39 pht('Revisions must have an assigned author.'),
40 $xaction);
41 continue;
44 $author_objects = id(new PhabricatorPeopleQuery())
45 ->setViewer($actor)
46 ->withPHIDs(array($new))
47 ->execute();
48 if (!$author_objects) {
49 $errors[] = $this->newInvalidError(
50 pht('Author "%s" is not a valid user.', $new),
51 $xaction);
52 continue;
56 return $errors;
59 public function getIcon() {
60 $author_phid = $this->getAuthorPHID();
61 $old_phid = $this->getOldValue();
62 $new_phid = $this->getNewValue();
64 $is_commandeer = ($author_phid === $new_phid);
65 $is_foist = ($author_phid === $old_phid);
67 if ($is_commandeer) {
68 return 'fa-flag';
71 if ($is_foist) {
72 return 'fa-gift';
75 return 'fa-user';
78 public function getColor() {
79 return 'sky';
82 public function getTitle() {
83 $author_phid = $this->getAuthorPHID();
84 $old_phid = $this->getOldValue();
85 $new_phid = $this->getNewValue();
87 $is_commandeer = ($author_phid === $new_phid);
88 $is_foist = ($author_phid === $old_phid);
90 if ($is_commandeer) {
91 return pht(
92 '%s commandeered this revision from %s.',
93 $this->renderAuthor(),
94 $this->renderOldHandle());
97 if ($is_foist) {
98 if ($new_phid) {
99 return pht(
100 '%s foisted this revision upon %s.',
101 $this->renderAuthor(),
102 $this->renderNewHandle());
103 } else {
105 // This isn't a valid transaction that can be applied, but happens in
106 // the preview if you temporarily delete the tokenizer value.
108 return pht(
109 '%s foisted this revision upon...',
110 $this->renderAuthor());
114 return pht(
115 '%s changed the author of this revision from %s to %s.',
116 $this->renderAuthor(),
117 $this->renderOldHandle(),
118 $this->renderNewHandle());
121 public function getTitleForFeed() {
122 $author_phid = $this->getAuthorPHID();
123 $old_phid = $this->getOldValue();
124 $new_phid = $this->getNewValue();
126 $is_commandeer = ($author_phid === $new_phid);
127 $is_foist = ($author_phid === $old_phid);
129 if ($is_commandeer) {
130 return pht(
131 '%s commandeered %s from %s.',
132 $this->renderAuthor(),
133 $this->renderObject(),
134 $this->renderOldHandle());
137 if ($is_foist) {
138 return pht(
139 '%s foisted %s upon %s.',
140 $this->renderAuthor(),
141 $this->renderObject(),
142 $this->renderNewHandle());
145 return pht(
146 '%s changed the author of %s from %s to %s.',
147 $this->renderAuthor(),
148 $this->renderObject(),
149 $this->renderOldHandle(),
150 $this->renderNewHandle());
154 public function getTransactionTypeForConduit($xaction) {
155 return 'author';
158 public function getFieldValuesForConduit($object, $data) {
159 return array(
160 'old' => $object->getOldValue(),
161 'new' => $object->getNewValue(),