Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/xaction/DifferentialRevisionCloseTransaction.php
12256 views
1
<?php
2
3
final class DifferentialRevisionCloseTransaction
4
extends DifferentialRevisionActionTransaction {
5
6
const TRANSACTIONTYPE = 'differential.revision.close';
7
const ACTIONKEY = 'close';
8
9
protected function getRevisionActionLabel(
10
DifferentialRevision $revision,
11
PhabricatorUser $viewer) {
12
return pht('Close Revision');
13
}
14
15
protected function getRevisionActionDescription(
16
DifferentialRevision $revision,
17
PhabricatorUser $viewer) {
18
return pht('This revision will be closed.');
19
}
20
21
public function getIcon() {
22
return 'fa-check';
23
}
24
25
public function getColor() {
26
return 'indigo';
27
}
28
29
protected function getRevisionActionOrder() {
30
return 300;
31
}
32
33
public function getActionName() {
34
return pht('Closed');
35
}
36
37
public function generateOldValue($object) {
38
return $object->isClosed();
39
}
40
41
public function applyInternalEffects($object, $value) {
42
$was_accepted = $object->isAccepted();
43
44
$status_published = DifferentialRevisionStatus::PUBLISHED;
45
$object->setModernRevisionStatus($status_published);
46
47
$object->setProperty(
48
DifferentialRevision::PROPERTY_CLOSED_FROM_ACCEPTED,
49
$was_accepted);
50
51
// See T13300. When a revision is closed, we promote it out of "Draft"
52
// immediately. This usually happens when a user creates a draft revision
53
// and then lands the associated commit before the revision leaves draft.
54
$object->setShouldBroadcast(true);
55
}
56
57
protected function validateAction($object, PhabricatorUser $viewer) {
58
if ($this->hasEditor()) {
59
if ($this->getEditor()->getIsCloseByCommit()) {
60
// If we're closing a revision because we discovered a commit, we don't
61
// care what state it was in.
62
return;
63
}
64
}
65
66
if ($object->isClosed()) {
67
throw new Exception(
68
pht(
69
'You can not close this revision because it has already been '.
70
'closed. Only open revisions can be closed.'));
71
}
72
73
if (!$object->isAccepted()) {
74
throw new Exception(
75
pht(
76
'You can not close this revision because it has not been accepted. '.
77
'Revisions must be accepted before they can be closed.'));
78
}
79
80
$config_key = 'differential.always-allow-close';
81
if (!PhabricatorEnv::getEnvConfig($config_key)) {
82
if (!$this->isViewerRevisionAuthor($object, $viewer)) {
83
throw new Exception(
84
pht(
85
'You can not close this revision because you are not the '.
86
'author. You can only close revisions you own. You can change '.
87
'this behavior by adjusting the "%s" setting in Config.',
88
$config_key));
89
}
90
}
91
}
92
93
public function getTitle() {
94
$commit_phid = $this->getMetadataValue('commitPHID');
95
if ($commit_phid) {
96
$commit = id(new DiffusionCommitQuery())
97
->setViewer($this->getViewer())
98
->withPHIDs(array($commit_phid))
99
->needIdentities(true)
100
->executeOne();
101
} else {
102
$commit = null;
103
}
104
105
if (!$commit) {
106
return pht(
107
'%s closed this revision.',
108
$this->renderAuthor());
109
}
110
111
$author_phid = null;
112
if ($commit->hasAuthorIdentity()) {
113
$identity = $commit->getAuthorIdentity();
114
$author_phid = $identity->getIdentityDisplayPHID();
115
}
116
117
$committer_phid = null;
118
if ($commit->hasCommitterIdentity()) {
119
$identity = $commit->getCommitterIdentity();
120
$committer_phid = $identity->getIdentityDisplayPHID();
121
}
122
123
if (!$author_phid) {
124
return pht(
125
'Closed by commit %s.',
126
$this->renderHandle($commit_phid));
127
} else if (!$committer_phid || ($committer_phid === $author_phid)) {
128
return pht(
129
'Closed by commit %s (authored by %s).',
130
$this->renderHandle($commit_phid),
131
$this->renderHandle($author_phid));
132
} else {
133
return pht(
134
'Closed by commit %s (authored by %s, committed by %s).',
135
$this->renderHandle($commit_phid),
136
$this->renderHandle($author_phid),
137
$this->renderHandle($committer_phid));
138
}
139
}
140
141
public function getTitleForFeed() {
142
return pht(
143
'%s closed %s.',
144
$this->renderAuthor(),
145
$this->renderObject());
146
}
147
148
public function getTransactionTypeForConduit($xaction) {
149
return 'close';
150
}
151
152
public function getFieldValuesForConduit($object, $data) {
153
$commit_phid = $object->getMetadataValue('commitPHID');
154
155
if ($commit_phid) {
156
$commit_phids = array($commit_phid);
157
} else {
158
$commit_phids = array();
159
}
160
161
return array(
162
'commitPHIDs' => $commit_phids,
163
);
164
}
165
166
}
167
168