Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/xaction/ManiphestTaskOwnerTransaction.php
12256 views
1
<?php
2
3
final class ManiphestTaskOwnerTransaction
4
extends ManiphestTaskTransactionType {
5
6
const TRANSACTIONTYPE = 'reassign';
7
8
public function generateOldValue($object) {
9
return nonempty($object->getOwnerPHID(), null);
10
}
11
12
public function applyInternalEffects($object, $value) {
13
// Update the "ownerOrdering" column to contain the full name of the
14
// owner, if the task is assigned.
15
16
$handle = null;
17
if ($value) {
18
$handle = id(new PhabricatorHandleQuery())
19
->setViewer($this->getActor())
20
->withPHIDs(array($value))
21
->executeOne();
22
}
23
24
if ($handle) {
25
$object->setOwnerOrdering($handle->getName());
26
} else {
27
$object->setOwnerOrdering(null);
28
}
29
30
$object->setOwnerPHID($value);
31
}
32
33
public function getActionStrength() {
34
return 120;
35
}
36
37
public function getActionName() {
38
$old = $this->getOldValue();
39
$new = $this->getNewValue();
40
41
if ($this->getAuthorPHID() == $new) {
42
return pht('Claimed');
43
} else if (!$new) {
44
return pht('Unassigned');
45
} else if (!$old) {
46
return pht('Assigned');
47
} else {
48
return pht('Reassigned');
49
}
50
}
51
52
public function getTitle() {
53
$old = $this->getOldValue();
54
$new = $this->getNewValue();
55
56
if ($this->getAuthorPHID() == $new) {
57
return pht(
58
'%s claimed this task.',
59
$this->renderAuthor());
60
} else if (!$new) {
61
return pht(
62
'%s removed %s as the assignee of this task.',
63
$this->renderAuthor(),
64
$this->renderHandle($old));
65
} else if (!$old) {
66
return pht(
67
'%s assigned this task to %s.',
68
$this->renderAuthor(),
69
$this->renderHandle($new));
70
} else {
71
return pht(
72
'%s reassigned this task from %s to %s.',
73
$this->renderAuthor(),
74
$this->renderHandle($old),
75
$this->renderHandle($new));
76
}
77
}
78
79
public function getTitleForFeed() {
80
$old = $this->getOldValue();
81
$new = $this->getNewValue();
82
83
if ($this->getAuthorPHID() == $new) {
84
return pht(
85
'%s claimed %s.',
86
$this->renderAuthor(),
87
$this->renderObject());
88
} else if (!$new) {
89
return pht(
90
'%s placed %s up for grabs.',
91
$this->renderAuthor(),
92
$this->renderObject());
93
} else if (!$old) {
94
return pht(
95
'%s assigned %s to %s.',
96
$this->renderAuthor(),
97
$this->renderObject(),
98
$this->renderHandle($new));
99
} else {
100
return pht(
101
'%s reassigned %s from %s to %s.',
102
$this->renderAuthor(),
103
$this->renderObject(),
104
$this->renderHandle($old),
105
$this->renderHandle($new));
106
}
107
}
108
109
public function validateTransactions($object, array $xactions) {
110
$errors = array();
111
112
foreach ($xactions as $xaction) {
113
$old = $xaction->getOldValue();
114
$new = $xaction->getNewValue();
115
116
if (!phutil_nonempty_string($new)) {
117
continue;
118
}
119
120
if ($new === $old) {
121
continue;
122
}
123
124
$assignee_list = id(new PhabricatorPeopleQuery())
125
->setViewer($this->getActor())
126
->withPHIDs(array($new))
127
->execute();
128
129
if (!$assignee_list) {
130
$errors[] = $this->newInvalidError(
131
pht('User "%s" is not a valid user.', $new));
132
}
133
}
134
return $errors;
135
}
136
137
public function getIcon() {
138
return 'fa-user';
139
}
140
141
public function getColor() {
142
$old = $this->getOldValue();
143
$new = $this->getNewValue();
144
145
if ($this->getAuthorPHID() == $new) {
146
return 'green';
147
} else if (!$new) {
148
return 'black';
149
} else if (!$old) {
150
return 'green';
151
} else {
152
return 'green';
153
}
154
155
}
156
157
public function getTransactionTypeForConduit($xaction) {
158
return 'owner';
159
}
160
161
public function getFieldValuesForConduit($xaction, $data) {
162
return array(
163
'old' => $xaction->getOldValue(),
164
'new' => $xaction->getNewValue(),
165
);
166
}
167
168
}
169
170