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() {
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');
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()) {
55 '%s triaged this task as %s priority.',
56 $this->renderAuthor(),
57 $this->renderValue($new_name));
58 } else if ($old > $new) {
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));
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()) {
82 '%s triaged %s as %s priority.',
83 $this->renderAuthor(),
84 $this->renderObject(),
85 $this->renderValue($new_name));
86 } else if ($old > $new) {
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));
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';
112 return 'fa-arrow-up';
116 public function getColor() {
117 $old = $this->getOldValue();
118 $new = $this->getNewValue();
120 if ($old == ManiphestTaskPriority
::getDefaultPriority()) {
122 } else if ($old > $new) {
129 public function validateTransactions($object, array $xactions) {
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) {
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
) {
154 $keyword_list = array();
155 foreach (ManiphestTaskPriority
::getTaskPriorityMap() as $pri => $name) {
156 $keyword = ManiphestTaskPriority
::getKeywordForTaskPriority($pri);
157 if ($keyword === null) {
160 $keyword_list[] = $keyword;
163 $errors[] = $this->newInvalidError(
165 'Task priority "%s" is not a valid task priority. Use a priority '.
166 'keyword to choose a task priority: %s.',
168 implode(', ', $keyword_list)),
175 public function getTransactionTypeForConduit($xaction) {
179 public function getFieldValuesForConduit($xaction, $data) {
180 $old = $xaction->getOldValue();
183 $old_name = ManiphestTaskPriority
::getTaskPriorityName($old);
188 $new = $xaction->getNewValue();
190 $new_name = ManiphestTaskPriority
::getTaskPriorityName($new);