forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorProjectTransaction.php
168 lines (150 loc) · 4.96 KB
/
PhabricatorProjectTransaction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
final class PhabricatorProjectTransaction
extends PhabricatorApplicationTransaction {
const TYPE_NAME = 'project:name';
const TYPE_SLUGS = 'project:slugs';
const TYPE_STATUS = 'project:status';
const TYPE_IMAGE = 'project:image';
const TYPE_ICON = 'project:icon';
// NOTE: This is deprecated, members are just a normal edge now.
const TYPE_MEMBERS = 'project:members';
public function getApplicationName() {
return 'project';
}
public function getApplicationTransactionType() {
return PhabricatorProjectPHIDTypeProject::TYPECONST;
}
public function getRequiredHandlePHIDs() {
$old = $this->getOldValue();
$new = $this->getNewValue();
$req_phids = array();
switch ($this->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_MEMBERS:
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
$req_phids = array_merge($add, $rem);
break;
case PhabricatorProjectTransaction::TYPE_IMAGE:
$req_phids[] = $old;
$req_phids[] = $new;
break;
}
return array_merge($req_phids, parent::getRequiredHandlePHIDs());
}
public function getTitle() {
$old = $this->getOldValue();
$new = $this->getNewValue();
$author_handle = $this->renderHandleLink($this->getAuthorPHID());
switch ($this->getTransactionType()) {
case PhabricatorProjectTransaction::TYPE_NAME:
if ($old === null) {
return pht(
'%s created this project.',
$author_handle);
} else {
return pht(
'%s renamed this project from "%s" to "%s".',
$author_handle,
$old,
$new);
}
case PhabricatorProjectTransaction::TYPE_STATUS:
if ($old == 0) {
return pht(
'%s closed this project.',
$author_handle);
} else {
return pht(
'%s reopened this project.',
$author_handle);
}
case PhabricatorProjectTransaction::TYPE_IMAGE:
// TODO: Some day, it would be nice to show the images.
if (!$old) {
return pht(
'%s set this project\'s image to %s.',
$author_handle,
$this->renderHandleLink($new));
} else if (!$new) {
return pht(
'%s removed this project\'s image.',
$author_handle);
} else {
return pht(
'%s updated this project\'s image from %s to %s.',
$author_handle,
$this->renderHandleLink($old),
$this->renderHandleLink($new));
}
case PhabricatorProjectTransaction::TYPE_ICON:
return pht(
'%s set this project\'s icon to %s.',
$author_handle,
PhabricatorProjectIcon::getLabel($new));
case PhabricatorProjectTransaction::TYPE_SLUGS:
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
if ($add && $rem) {
return pht(
'%s changed project hashtag(s), added %d: %s; removed %d: %s',
$author_handle,
count($add),
$this->renderSlugList($add),
count($rem),
$this->renderSlugList($rem));
} else if ($add) {
return pht(
'%s added %d project hashtag(s): %s',
$author_handle,
count($add),
$this->renderSlugList($add));
} else if ($rem) {
return pht(
'%s removed %d project hashtag(s): %s',
$author_handle,
count($rem),
$this->renderSlugList($rem));
}
case PhabricatorProjectTransaction::TYPE_MEMBERS:
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
if ($add && $rem) {
return pht(
'%s changed project member(s), added %d: %s; removed %d: %s',
$author_handle,
count($add),
$this->renderHandleList($add),
count($rem),
$this->renderHandleList($rem));
} else if ($add) {
if (count($add) == 1 && (head($add) == $this->getAuthorPHID())) {
return pht(
'%s joined this project.',
$author_handle);
} else {
return pht(
'%s added %d project member(s): %s',
$author_handle,
count($add),
$this->renderHandleList($add));
}
} else if ($rem) {
if (count($rem) == 1 && (head($rem) == $this->getAuthorPHID())) {
return pht(
'%s left this project.',
$author_handle);
} else {
return pht(
'%s removed %d project member(s): %s',
$author_handle,
count($rem),
$this->renderHandleList($rem));
}
}
}
return parent::getTitle();
}
private function renderSlugList($slugs) {
return implode(', ', $slugs);
}
}