Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/storage/ManiphestTransaction.php
12256 views
1
<?php
2
3
final class ManiphestTransaction
4
extends PhabricatorModularTransaction {
5
6
const MAILTAG_STATUS = 'maniphest-status';
7
const MAILTAG_OWNER = 'maniphest-owner';
8
const MAILTAG_PRIORITY = 'maniphest-priority';
9
const MAILTAG_CC = 'maniphest-cc';
10
const MAILTAG_PROJECTS = 'maniphest-projects';
11
const MAILTAG_COMMENT = 'maniphest-comment';
12
const MAILTAG_COLUMN = 'maniphest-column';
13
const MAILTAG_UNBLOCK = 'maniphest-unblock';
14
const MAILTAG_OTHER = 'maniphest-other';
15
16
17
public function getApplicationName() {
18
return 'maniphest';
19
}
20
21
public function getApplicationTransactionType() {
22
return ManiphestTaskPHIDType::TYPECONST;
23
}
24
25
public function getApplicationTransactionCommentObject() {
26
return new ManiphestTransactionComment();
27
}
28
29
public function getBaseTransactionClass() {
30
return 'ManiphestTaskTransactionType';
31
}
32
33
public function shouldGenerateOldValue() {
34
switch ($this->getTransactionType()) {
35
case ManiphestTaskEdgeTransaction::TRANSACTIONTYPE:
36
case ManiphestTaskUnblockTransaction::TRANSACTIONTYPE:
37
return false;
38
}
39
40
return parent::shouldGenerateOldValue();
41
}
42
43
public function getRequiredHandlePHIDs() {
44
$phids = parent::getRequiredHandlePHIDs();
45
46
$new = $this->getNewValue();
47
$old = $this->getOldValue();
48
49
switch ($this->getTransactionType()) {
50
case ManiphestTaskOwnerTransaction::TRANSACTIONTYPE:
51
if ($new) {
52
$phids[] = $new;
53
}
54
55
if ($old) {
56
$phids[] = $old;
57
}
58
break;
59
case ManiphestTaskMergedIntoTransaction::TRANSACTIONTYPE:
60
$phids[] = $new;
61
break;
62
case ManiphestTaskMergedFromTransaction::TRANSACTIONTYPE:
63
$phids = array_merge($phids, $new);
64
break;
65
case ManiphestTaskEdgeTransaction::TRANSACTIONTYPE:
66
$phids = array_mergev(
67
array(
68
$phids,
69
array_keys(nonempty($old, array())),
70
array_keys(nonempty($new, array())),
71
));
72
break;
73
case ManiphestTaskAttachTransaction::TRANSACTIONTYPE:
74
$old = nonempty($old, array());
75
$new = nonempty($new, array());
76
$phids = array_mergev(
77
array(
78
$phids,
79
array_keys(idx($new, 'FILE', array())),
80
array_keys(idx($old, 'FILE', array())),
81
));
82
break;
83
case ManiphestTaskUnblockTransaction::TRANSACTIONTYPE:
84
foreach (array_keys($new) as $phid) {
85
$phids[] = $phid;
86
}
87
break;
88
case ManiphestTaskStatusTransaction::TRANSACTIONTYPE:
89
$commit_phid = $this->getMetadataValue('commitPHID');
90
if ($commit_phid) {
91
$phids[] = $commit_phid;
92
}
93
break;
94
}
95
96
return $phids;
97
}
98
99
public function getActionName() {
100
$old = $this->getOldValue();
101
$new = $this->getNewValue();
102
switch ($this->getTransactionType()) {
103
case PhabricatorTransactions::TYPE_COLUMNS:
104
return pht('Changed Project Column');
105
}
106
107
return parent::getActionName();
108
}
109
110
public function getIcon() {
111
switch ($this->getTransactionType()) {
112
case PhabricatorTransactions::TYPE_COLUMNS:
113
return 'fa-columns';
114
}
115
116
return parent::getIcon();
117
}
118
119
120
public function getTitle() {
121
$author_phid = $this->getAuthorPHID();
122
123
$old = $this->getOldValue();
124
$new = $this->getNewValue();
125
126
switch ($this->getTransactionType()) {
127
case PhabricatorTransactions::TYPE_SUBTYPE:
128
return pht(
129
'%s changed the subtype of this task from "%s" to "%s".',
130
$this->renderHandleLink($author_phid),
131
$this->renderSubtypeName($old),
132
$this->renderSubtypeName($new));
133
break;
134
}
135
136
return parent::getTitle();
137
}
138
139
public function getTitleForFeed() {
140
$author_phid = $this->getAuthorPHID();
141
$object_phid = $this->getObjectPHID();
142
143
$old = $this->getOldValue();
144
$new = $this->getNewValue();
145
146
switch ($this->getTransactionType()) {
147
case PhabricatorTransactions::TYPE_SUBTYPE:
148
return pht(
149
'%s changed the subtype of %s from "%s" to "%s".',
150
$this->renderHandleLink($author_phid),
151
$this->renderHandleLink($object_phid),
152
$this->renderSubtypeName($old),
153
$this->renderSubtypeName($new));
154
}
155
156
return parent::getTitleForFeed();
157
}
158
159
public function getMailTags() {
160
$tags = array();
161
switch ($this->getTransactionType()) {
162
case ManiphestTaskMergedIntoTransaction::TRANSACTIONTYPE:
163
case ManiphestTaskStatusTransaction::TRANSACTIONTYPE:
164
$tags[] = self::MAILTAG_STATUS;
165
break;
166
case ManiphestTaskOwnerTransaction::TRANSACTIONTYPE:
167
$tags[] = self::MAILTAG_OWNER;
168
break;
169
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
170
$tags[] = self::MAILTAG_CC;
171
break;
172
case PhabricatorTransactions::TYPE_EDGE:
173
switch ($this->getMetadataValue('edge:type')) {
174
case PhabricatorProjectObjectHasProjectEdgeType::EDGECONST:
175
$tags[] = self::MAILTAG_PROJECTS;
176
break;
177
default:
178
$tags[] = self::MAILTAG_OTHER;
179
break;
180
}
181
break;
182
case ManiphestTaskPriorityTransaction::TRANSACTIONTYPE:
183
$tags[] = self::MAILTAG_PRIORITY;
184
break;
185
case ManiphestTaskUnblockTransaction::TRANSACTIONTYPE:
186
$tags[] = self::MAILTAG_UNBLOCK;
187
break;
188
case PhabricatorTransactions::TYPE_COLUMNS:
189
$tags[] = self::MAILTAG_COLUMN;
190
break;
191
case PhabricatorTransactions::TYPE_COMMENT:
192
$tags[] = self::MAILTAG_COMMENT;
193
break;
194
default:
195
$tags[] = self::MAILTAG_OTHER;
196
break;
197
}
198
return $tags;
199
}
200
201
public function getNoEffectDescription() {
202
switch ($this->getTransactionType()) {
203
case ManiphestTaskStatusTransaction::TRANSACTIONTYPE:
204
return pht('The task already has the selected status.');
205
case ManiphestTaskOwnerTransaction::TRANSACTIONTYPE:
206
return pht('The task already has the selected owner.');
207
case ManiphestTaskPriorityTransaction::TRANSACTIONTYPE:
208
return pht('The task already has the selected priority.');
209
}
210
211
return parent::getNoEffectDescription();
212
}
213
214
public function renderSubtypeName($value) {
215
$object = $this->getObject();
216
$map = $object->newEditEngineSubtypeMap();
217
218
if (!$map->isValidSubtype($value)) {
219
return $value;
220
}
221
222
return $map->getSubtype($value)->getName();
223
}
224
225
}
226
227