Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / maniphest / xaction / ManiphestTaskPriorityTransaction.php
blob2a53bf7ef6253d87ea7e6df42248ee1cdcbe8d62
1 <?php
3 final class ManiphestTaskPriorityTransaction
4 extends ManiphestTaskTransactionType {
6 const TRANSACTIONTYPE = 'priority';
8 public function generateOldValue($object) {
9 return (string)$object->getPriority();
12 public function generateNewValue($object, $value) {
13 // `$value` is supposed to be a keyword, but if the priority
14 // assigned to a task has been removed from the config,
15 // no such keyword will be available. Other edits to the task
16 // should still be allowed, even if the priority is no longer
17 // valid, so treat this as a no-op.
18 if ($value === ManiphestTaskPriority::UNKNOWN_PRIORITY_KEYWORD) {
19 return (string)$object->getPriority();
22 return (string)ManiphestTaskPriority::getTaskPriorityFromKeyword($value);
25 public function applyInternalEffects($object, $value) {
26 $object->setPriority($value);
29 public function getActionStrength() {
30 return 110;
33 public function getActionName() {
34 $old = $this->getOldValue();
35 $new = $this->getNewValue();
37 if ($old == ManiphestTaskPriority::getDefaultPriority()) {
38 return pht('Triaged');
39 } else if ($old > $new) {
40 return pht('Lowered Priority');
41 } else {
42 return pht('Raised Priority');
46 public function getTitle() {
47 $old = $this->getOldValue();
48 $new = $this->getNewValue();
50 $old_name = ManiphestTaskPriority::getTaskPriorityName($old);
51 $new_name = ManiphestTaskPriority::getTaskPriorityName($new);
53 if ($old == ManiphestTaskPriority::getDefaultPriority()) {
54 return pht(
55 '%s triaged this task as %s priority.',
56 $this->renderAuthor(),
57 $this->renderValue($new_name));
58 } else if ($old > $new) {
59 return pht(
60 '%s lowered the priority of this task from %s to %s.',
61 $this->renderAuthor(),
62 $this->renderValue($old_name),
63 $this->renderValue($new_name));
64 } else {
65 return pht(
66 '%s raised the priority of this task from %s to %s.',
67 $this->renderAuthor(),
68 $this->renderValue($old_name),
69 $this->renderValue($new_name));
73 public function getTitleForFeed() {
74 $old = $this->getOldValue();
75 $new = $this->getNewValue();
77 $old_name = ManiphestTaskPriority::getTaskPriorityName($old);
78 $new_name = ManiphestTaskPriority::getTaskPriorityName($new);
80 if ($old == ManiphestTaskPriority::getDefaultPriority()) {
81 return pht(
82 '%s triaged %s as %s priority.',
83 $this->renderAuthor(),
84 $this->renderObject(),
85 $this->renderValue($new_name));
86 } else if ($old > $new) {
87 return pht(
88 '%s lowered the priority of %s from %s to %s.',
89 $this->renderAuthor(),
90 $this->renderObject(),
91 $this->renderValue($old_name),
92 $this->renderValue($new_name));
93 } else {
94 return pht(
95 '%s raised the priority of %s from %s to %s.',
96 $this->renderAuthor(),
97 $this->renderObject(),
98 $this->renderValue($old_name),
99 $this->renderValue($new_name));
103 public function getIcon() {
104 $old = $this->getOldValue();
105 $new = $this->getNewValue();
107 if ($old == ManiphestTaskPriority::getDefaultPriority()) {
108 return 'fa-arrow-right';
109 } else if ($old > $new) {
110 return 'fa-arrow-down';
111 } else {
112 return 'fa-arrow-up';
116 public function getColor() {
117 $old = $this->getOldValue();
118 $new = $this->getNewValue();
120 if ($old == ManiphestTaskPriority::getDefaultPriority()) {
121 return 'green';
122 } else if ($old > $new) {
123 return 'grey';
124 } else {
125 return 'yellow';
129 public function validateTransactions($object, array $xactions) {
130 $errors = array();
132 $content_source = $this->getEditor()->getContentSource();
133 $is_web = ($content_source instanceof PhabricatorWebContentSource);
135 foreach ($xactions as $xaction) {
136 $value = $xaction->getNewValue();
138 // If this is a legitimate keyword like "low" or "high", this transaction
139 // is fine and apply normally.
140 $keyword = ManiphestTaskPriority::getTaskPriorityFromKeyword($value);
141 if ($keyword !== null) {
142 continue;
145 // If this is the magic "don't change things" value for editing tasks
146 // with an obsolete priority constant in the database, let it through if
147 // this is a web edit.
148 if ($value === ManiphestTaskPriority::UNKNOWN_PRIORITY_KEYWORD) {
149 if ($is_web) {
150 continue;
154 $keyword_list = array();
155 foreach (ManiphestTaskPriority::getTaskPriorityMap() as $pri => $name) {
156 $keyword = ManiphestTaskPriority::getKeywordForTaskPriority($pri);
157 if ($keyword === null) {
158 continue;
160 $keyword_list[] = $keyword;
163 $errors[] = $this->newInvalidError(
164 pht(
165 'Task priority "%s" is not a valid task priority. Use a priority '.
166 'keyword to choose a task priority: %s.',
167 $value,
168 implode(', ', $keyword_list)),
169 $xaction);
172 return $errors;
175 public function getTransactionTypeForConduit($xaction) {
176 return 'priority';
179 public function getFieldValuesForConduit($xaction, $data) {
180 $old = $xaction->getOldValue();
181 if ($old !== null) {
182 $old = (int)$old;
183 $old_name = ManiphestTaskPriority::getTaskPriorityName($old);
184 } else {
185 $old_name = null;
188 $new = $xaction->getNewValue();
189 $new = (int)$new;
190 $new_name = ManiphestTaskPriority::getTaskPriorityName($new);
192 return array(
193 'old' => array(
194 'value' => $old,
195 'name' => $old_name,
197 'new' => array(
198 'value' => $new,
199 'name' => $new_name,