Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/xaction/ManiphestTaskPriorityTransaction.php
12256 views
1
<?php
2
3
final class ManiphestTaskPriorityTransaction
4
extends ManiphestTaskTransactionType {
5
6
const TRANSACTIONTYPE = 'priority';
7
8
public function generateOldValue($object) {
9
return (string)$object->getPriority();
10
}
11
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();
20
}
21
22
return (string)ManiphestTaskPriority::getTaskPriorityFromKeyword($value);
23
}
24
25
public function applyInternalEffects($object, $value) {
26
$object->setPriority($value);
27
}
28
29
public function getActionStrength() {
30
return 110;
31
}
32
33
public function getActionName() {
34
$old = $this->getOldValue();
35
$new = $this->getNewValue();
36
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');
43
}
44
}
45
46
public function getTitle() {
47
$old = $this->getOldValue();
48
$new = $this->getNewValue();
49
50
$old_name = ManiphestTaskPriority::getTaskPriorityName($old);
51
$new_name = ManiphestTaskPriority::getTaskPriorityName($new);
52
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));
70
}
71
}
72
73
public function getTitleForFeed() {
74
$old = $this->getOldValue();
75
$new = $this->getNewValue();
76
77
$old_name = ManiphestTaskPriority::getTaskPriorityName($old);
78
$new_name = ManiphestTaskPriority::getTaskPriorityName($new);
79
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));
100
}
101
}
102
103
public function getIcon() {
104
$old = $this->getOldValue();
105
$new = $this->getNewValue();
106
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';
113
}
114
}
115
116
public function getColor() {
117
$old = $this->getOldValue();
118
$new = $this->getNewValue();
119
120
if ($old == ManiphestTaskPriority::getDefaultPriority()) {
121
return 'green';
122
} else if ($old > $new) {
123
return 'grey';
124
} else {
125
return 'yellow';
126
}
127
}
128
129
public function validateTransactions($object, array $xactions) {
130
$errors = array();
131
132
$content_source = $this->getEditor()->getContentSource();
133
$is_web = ($content_source instanceof PhabricatorWebContentSource);
134
135
foreach ($xactions as $xaction) {
136
$value = $xaction->getNewValue();
137
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;
143
}
144
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;
151
}
152
}
153
154
$keyword_list = array();
155
foreach (ManiphestTaskPriority::getTaskPriorityMap() as $pri => $name) {
156
$keyword = ManiphestTaskPriority::getKeywordForTaskPriority($pri);
157
if ($keyword === null) {
158
continue;
159
}
160
$keyword_list[] = $keyword;
161
}
162
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);
170
}
171
172
return $errors;
173
}
174
175
public function getTransactionTypeForConduit($xaction) {
176
return 'priority';
177
}
178
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;
186
}
187
188
$new = $xaction->getNewValue();
189
$new = (int)$new;
190
$new_name = ManiphestTaskPriority::getTaskPriorityName($new);
191
192
return array(
193
'old' => array(
194
'value' => $old,
195
'name' => $old_name,
196
),
197
'new' => array(
198
'value' => $new,
199
'name' => $new_name,
200
),
201
);
202
}
203
204
}
205
206