Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php
12264 views
1
<?php
2
3
final class HarbormasterBuildMessageRestartTransaction
4
extends HarbormasterBuildMessageTransaction {
5
6
const TRANSACTIONTYPE = 'message/restart';
7
const MESSAGETYPE = 'restart';
8
9
public function getHarbormasterBuildMessageName() {
10
return pht('Restart Build');
11
}
12
13
public function getHarbormasterBuildableMessageName() {
14
return pht('Restart Builds');
15
}
16
17
public function getHarbormasterBuildableMessageEffect() {
18
return pht('Build will restart.');
19
}
20
21
public function newConfirmPromptTitle() {
22
return pht('Really restart build?');
23
}
24
25
public function newConfirmPromptBody() {
26
return pht(
27
'Progress on this build will be discarded and the build will restart. '.
28
'Side effects of the build will occur again. Really restart build?');
29
}
30
31
32
public function getHarbormasterBuildMessageDescription() {
33
return pht('Restart the build, discarding all progress.');
34
}
35
36
public function newBuildableConfirmPromptTitle(
37
array $builds,
38
array $sendable) {
39
return pht(
40
'Really restart %s build(s)?',
41
phutil_count($builds));
42
}
43
44
public function newBuildableConfirmPromptBody(
45
array $builds,
46
array $sendable) {
47
48
if (count($sendable) === count($builds)) {
49
return pht(
50
'All builds will restart.');
51
} else {
52
return pht(
53
'You can only restart some builds.');
54
}
55
}
56
57
public function newBuildableConfirmPromptWarnings(
58
array $builds,
59
array $sendable) {
60
61
$building = false;
62
foreach ($sendable as $build) {
63
if ($build->isBuilding()) {
64
$building = true;
65
break;
66
}
67
}
68
69
$warnings = array();
70
71
if ($building) {
72
$warnings[] = pht(
73
'Progress on running builds will be discarded.');
74
}
75
76
if ($sendable) {
77
$warnings[] = pht(
78
'When a build is restarted, side effects associated with '.
79
'the build may occur again.');
80
}
81
82
return $warnings;
83
}
84
85
public function getTitle() {
86
return pht(
87
'%s restarted this build.',
88
$this->renderAuthor());
89
}
90
91
public function getIcon() {
92
return 'fa-repeat';
93
}
94
95
public function applyInternalEffects($object, $value) {
96
$actor = $this->getActor();
97
$build = $object;
98
99
$build->restartBuild($actor);
100
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING);
101
}
102
103
protected function newCanApplyMessageAssertion(
104
PhabricatorUser $viewer,
105
HarbormasterBuild $build) {
106
107
if ($build->isAutobuild()) {
108
throw new HarbormasterMessageException(
109
pht('Can Not Restart Autobuild'),
110
pht(
111
'This build can not be restarted because it is an automatic '.
112
'build.'));
113
}
114
115
$restartable = HarbormasterBuildPlanBehavior::BEHAVIOR_RESTARTABLE;
116
$plan = $build->getBuildPlan();
117
118
// See T13526. Users who can't see the "BuildPlan" can end up here with
119
// no object. This is highly questionable.
120
if (!$plan) {
121
throw new HarbormasterMessageException(
122
pht('No Build Plan Permission'),
123
pht(
124
'You can not restart this build because you do not have '.
125
'permission to access the build plan.'));
126
}
127
128
$option = HarbormasterBuildPlanBehavior::getBehavior($restartable)
129
->getPlanOption($plan);
130
$option_key = $option->getKey();
131
132
$never_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_NEVER;
133
$is_never = ($option_key === $never_restartable);
134
if ($is_never) {
135
throw new HarbormasterMessageException(
136
pht('Build Plan Prevents Restart'),
137
pht(
138
'This build can not be restarted because the build plan is '.
139
'configured to prevent the build from restarting.'));
140
}
141
142
$failed_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_IF_FAILED;
143
$is_failed = ($option_key === $failed_restartable);
144
if ($is_failed) {
145
if (!$this->isFailed()) {
146
throw new HarbormasterMessageException(
147
pht('Only Restartable if Failed'),
148
pht(
149
'This build can not be restarted because the build plan is '.
150
'configured to prevent the build from restarting unless it '.
151
'has failed, and it has not failed.'));
152
}
153
}
154
155
}
156
157
protected function newCanSendMessageAssertion(
158
PhabricatorUser $viewer,
159
HarbormasterBuild $build) {
160
161
if ($build->isRestarting()) {
162
throw new HarbormasterMessageException(
163
pht('Already Restarting'),
164
pht(
165
'This build is already restarting. You can not reissue a restart '.
166
'command to a restarting build.'));
167
}
168
169
}
170
171
}
172
173