Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/xaction/DifferentialRevisionAuthorTransaction.php
12256 views
1
<?php
2
3
final class DifferentialRevisionAuthorTransaction
4
extends DifferentialRevisionTransactionType {
5
6
const TRANSACTIONTYPE = 'differential.revision.author';
7
const EDITKEY = 'author';
8
9
public function generateOldValue($object) {
10
return $object->getAuthorPHID();
11
}
12
13
public function generateNewValue($object, $value) {
14
return $value;
15
}
16
17
public function applyInternalEffects($object, $value) {
18
$object->setAuthorPHID($value);
19
}
20
21
public function validateTransactions($object, array $xactions) {
22
$actor = $this->getActor();
23
$errors = array();
24
25
if (!$xactions) {
26
return $errors;
27
}
28
29
foreach ($xactions as $xaction) {
30
$old = $xaction->generateOldValue($object);
31
$new = $xaction->getNewValue();
32
33
if ($old === $new) {
34
continue;
35
}
36
37
if (!$new) {
38
$errors[] = $this->newInvalidError(
39
pht('Revisions must have an assigned author.'),
40
$xaction);
41
continue;
42
}
43
44
$author_objects = id(new PhabricatorPeopleQuery())
45
->setViewer($actor)
46
->withPHIDs(array($new))
47
->execute();
48
if (!$author_objects) {
49
$errors[] = $this->newInvalidError(
50
pht('Author "%s" is not a valid user.', $new),
51
$xaction);
52
continue;
53
}
54
}
55
56
return $errors;
57
}
58
59
public function getIcon() {
60
$author_phid = $this->getAuthorPHID();
61
$old_phid = $this->getOldValue();
62
$new_phid = $this->getNewValue();
63
64
$is_commandeer = ($author_phid === $new_phid);
65
$is_foist = ($author_phid === $old_phid);
66
67
if ($is_commandeer) {
68
return 'fa-flag';
69
}
70
71
if ($is_foist) {
72
return 'fa-gift';
73
}
74
75
return 'fa-user';
76
}
77
78
public function getColor() {
79
return 'sky';
80
}
81
82
public function getTitle() {
83
$author_phid = $this->getAuthorPHID();
84
$old_phid = $this->getOldValue();
85
$new_phid = $this->getNewValue();
86
87
$is_commandeer = ($author_phid === $new_phid);
88
$is_foist = ($author_phid === $old_phid);
89
90
if ($is_commandeer) {
91
return pht(
92
'%s commandeered this revision from %s.',
93
$this->renderAuthor(),
94
$this->renderOldHandle());
95
}
96
97
if ($is_foist) {
98
if ($new_phid) {
99
return pht(
100
'%s foisted this revision upon %s.',
101
$this->renderAuthor(),
102
$this->renderNewHandle());
103
} else {
104
105
// This isn't a valid transaction that can be applied, but happens in
106
// the preview if you temporarily delete the tokenizer value.
107
108
return pht(
109
'%s foisted this revision upon...',
110
$this->renderAuthor());
111
}
112
}
113
114
return pht(
115
'%s changed the author of this revision from %s to %s.',
116
$this->renderAuthor(),
117
$this->renderOldHandle(),
118
$this->renderNewHandle());
119
}
120
121
public function getTitleForFeed() {
122
$author_phid = $this->getAuthorPHID();
123
$old_phid = $this->getOldValue();
124
$new_phid = $this->getNewValue();
125
126
$is_commandeer = ($author_phid === $new_phid);
127
$is_foist = ($author_phid === $old_phid);
128
129
if ($is_commandeer) {
130
return pht(
131
'%s commandeered %s from %s.',
132
$this->renderAuthor(),
133
$this->renderObject(),
134
$this->renderOldHandle());
135
}
136
137
if ($is_foist) {
138
return pht(
139
'%s foisted %s upon %s.',
140
$this->renderAuthor(),
141
$this->renderObject(),
142
$this->renderNewHandle());
143
}
144
145
return pht(
146
'%s changed the author of %s from %s to %s.',
147
$this->renderAuthor(),
148
$this->renderObject(),
149
$this->renderOldHandle(),
150
$this->renderNewHandle());
151
152
}
153
154
public function getTransactionTypeForConduit($xaction) {
155
return 'author';
156
}
157
158
public function getFieldValuesForConduit($object, $data) {
159
return array(
160
'old' => $object->getOldValue(),
161
'new' => $object->getNewValue(),
162
);
163
}
164
165
}
166
167