Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/controller/HarbormasterBuildableActionController.php
12256 views
1
<?php
2
3
final class HarbormasterBuildableActionController
4
extends HarbormasterController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
$id = $request->getURIData('id');
9
$action = $request->getURIData('action');
10
11
$buildable = id(new HarbormasterBuildableQuery())
12
->setViewer($viewer)
13
->withIDs(array($id))
14
->needBuilds(true)
15
->requireCapabilities(
16
array(
17
PhabricatorPolicyCapability::CAN_VIEW,
18
PhabricatorPolicyCapability::CAN_EDIT,
19
))
20
->executeOne();
21
if (!$buildable) {
22
return new Aphront404Response();
23
}
24
25
$message =
26
HarbormasterBuildMessageTransaction::getTransactionObjectForMessageType(
27
$action);
28
if (!$message) {
29
return new Aphront404Response();
30
}
31
32
$return_uri = '/'.$buildable->getMonogram();
33
34
// See T13348. Actions may apply to only a subset of builds, so give the
35
// user a preview of what will happen.
36
37
$can_send = array();
38
39
$rows = array();
40
$builds = $buildable->getBuilds();
41
foreach ($builds as $key => $build) {
42
$exception = null;
43
try {
44
$message->assertCanSendMessage($viewer, $build);
45
$can_send[$key] = $build;
46
} catch (HarbormasterMessageException $ex) {
47
$exception = $ex;
48
}
49
50
if (!$exception) {
51
$icon_icon = $message->getIcon();
52
$icon_color = 'green';
53
54
$title = $message->getHarbormasterBuildMessageName();
55
$body = $message->getHarbormasterBuildableMessageEffect();
56
} else {
57
$icon_icon = 'fa-times';
58
$icon_color = 'red';
59
60
$title = $ex->getTitle();
61
$body = $ex->getBody();
62
}
63
64
$icon = id(new PHUIIconView())
65
->setIcon($icon_icon)
66
->setColor($icon_color);
67
68
$build_name = phutil_tag(
69
'a',
70
array(
71
'href' => $build->getURI(),
72
'target' => '_blank',
73
),
74
pht('%s %s', $build->getObjectName(), $build->getName()));
75
76
$rows[] = array(
77
$icon,
78
$build_name,
79
$title,
80
$body,
81
);
82
}
83
84
$table = id(new AphrontTableView($rows))
85
->setHeaders(
86
array(
87
null,
88
pht('Build'),
89
pht('Action'),
90
pht('Details'),
91
))
92
->setColumnClasses(
93
array(
94
null,
95
null,
96
'pri',
97
'wide',
98
));
99
100
$table = phutil_tag(
101
'div',
102
array(
103
'class' => 'mlt mlb',
104
),
105
$table);
106
107
if ($request->isDialogFormPost() && $can_send) {
108
$editor = id(new HarbormasterBuildableTransactionEditor())
109
->setActor($viewer)
110
->setContentSourceFromRequest($request)
111
->setContinueOnNoEffect(true)
112
->setContinueOnMissingFields(true);
113
114
$xaction_type = HarbormasterBuildableMessageTransaction::TRANSACTIONTYPE;
115
116
$xaction = id(new HarbormasterBuildableTransaction())
117
->setTransactionType($xaction_type)
118
->setNewValue($action);
119
120
$editor->applyTransactions($buildable, array($xaction));
121
122
foreach ($can_send as $build) {
123
$build->sendMessage(
124
$viewer,
125
$message->getHarbormasterBuildMessageType());
126
}
127
128
return id(new AphrontRedirectResponse())->setURI($return_uri);
129
}
130
131
if (!$builds) {
132
$title = pht('No Builds');
133
$body = pht(
134
'This buildable has no builds, so you can not issue any commands.');
135
} else {
136
if ($can_send) {
137
$title = $message->newBuildableConfirmPromptTitle(
138
$builds,
139
$can_send);
140
141
$body = $message->newBuildableConfirmPromptBody(
142
$builds,
143
$can_send);
144
} else {
145
$title = pht('Unable to Send Command');
146
$body = pht(
147
'You can not send this command to any of the current builds '.
148
'for this buildable.');
149
}
150
151
$body = array(
152
pht('Builds for this buildable:'),
153
$table,
154
$body,
155
);
156
}
157
158
$warnings = $message->newBuildableConfirmPromptWarnings(
159
$builds,
160
$can_send);
161
162
if ($warnings) {
163
$body[] = id(new PHUIInfoView())
164
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
165
->setErrors($warnings);
166
}
167
168
$submit = $message->getHarbormasterBuildableMessageName();
169
170
$dialog = $this->newDialog()
171
->setWidth(AphrontDialogView::WIDTH_FULL)
172
->setTitle($title)
173
->appendChild($body)
174
->addCancelButton($return_uri);
175
176
if ($can_send) {
177
$dialog->addSubmitButton($submit);
178
}
179
180
return $dialog;
181
}
182
183
}
184
185