Differential D21691 Diff 51704 src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php
<?php | <?php | ||||
final class HarbormasterBuildMessageRestartTransaction | final class HarbormasterBuildMessageRestartTransaction | ||||
extends HarbormasterBuildMessageTransaction { | extends HarbormasterBuildMessageTransaction { | ||||
const TRANSACTIONTYPE = 'message/restart'; | const TRANSACTIONTYPE = 'message/restart'; | ||||
const MESSAGETYPE = 'restart'; | |||||
public function getMessageType() { | public function getHarbormasterBuildMessageName() { | ||||
return 'restart'; | return pht('Restart Build'); | ||||
} | |||||
public function getHarbormasterBuildableMessageName() { | |||||
return pht('Restart Builds'); | |||||
} | |||||
public function getHarbormasterBuildableMessageEffect() { | |||||
return pht('Build will restart.'); | |||||
} | |||||
public function newConfirmPromptTitle() { | |||||
return pht('Really restart build?'); | |||||
} | |||||
public function newConfirmPromptBody() { | |||||
return pht( | |||||
'Progress on this build will be discarded and the build will restart. '. | |||||
'Side effects of the build will occur again. Really restart build?'); | |||||
} | |||||
public function newBuildableConfirmPromptTitle( | |||||
array $builds, | |||||
array $sendable) { | |||||
return pht( | |||||
'Really restart %s build(s)?', | |||||
phutil_count($builds)); | |||||
} | |||||
public function newBuildableConfirmPromptBody( | |||||
array $builds, | |||||
array $sendable) { | |||||
if (count($sendable) === count($builds)) { | |||||
return pht( | |||||
'All builds will restart.'); | |||||
} else { | |||||
return pht( | |||||
'You can only restart some builds.'); | |||||
} | |||||
} | |||||
public function newBuildableConfirmPromptWarnings( | |||||
array $builds, | |||||
array $sendable) { | |||||
$building = false; | |||||
foreach ($sendable as $build) { | |||||
if ($build->isBuilding()) { | |||||
$building = true; | |||||
break; | |||||
} | |||||
} | |||||
$warnings = array(); | |||||
if ($building) { | |||||
$warnings[] = pht( | |||||
'Progress on running builds will be discarded.'); | |||||
} | |||||
if ($sendable) { | |||||
$warnings[] = pht( | |||||
'When a build is restarted, side effects associated with '. | |||||
'the build may occur again.'); | |||||
} | |||||
return $warnings; | |||||
} | } | ||||
public function getTitle() { | public function getTitle() { | ||||
return pht( | return pht( | ||||
'%s restarted this build.', | '%s restarted this build.', | ||||
$this->renderAuthor()); | $this->renderAuthor()); | ||||
} | } | ||||
public function getIcon() { | public function getIcon() { | ||||
return 'fa-backward'; | return 'fa-repeat'; | ||||
} | } | ||||
public function applyInternalEffects($object, $value) { | public function applyInternalEffects($object, $value) { | ||||
$actor = $this->getActor(); | $actor = $this->getActor(); | ||||
$build = $object; | $build = $object; | ||||
$build->restartBuild($actor); | $build->restartBuild($actor); | ||||
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING); | $build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING); | ||||
} | } | ||||
protected function newCanApplyMessageAssertion( | |||||
PhabricatorUser $viewer, | |||||
HarbormasterBuild $build) { | |||||
if ($build->isAutobuild()) { | |||||
throw new HarbormasterRestartException( | |||||
pht('Can Not Restart Autobuild'), | |||||
pht( | |||||
'This build can not be restarted because it is an automatic '. | |||||
'build.')); | |||||
} | |||||
$restartable = HarbormasterBuildPlanBehavior::BEHAVIOR_RESTARTABLE; | |||||
$plan = $build->getBuildPlan(); | |||||
// See T13526. Users who can't see the "BuildPlan" can end up here with | |||||
// no object. This is highly questionable. | |||||
if (!$plan) { | |||||
throw new HarbormasterRestartException( | |||||
pht('No Build Plan Permission'), | |||||
pht( | |||||
'You can not restart this build because you do not have '. | |||||
'permission to access the build plan.')); | |||||
} | |||||
$option = HarbormasterBuildPlanBehavior::getBehavior($restartable) | |||||
->getPlanOption($plan); | |||||
$option_key = $option->getKey(); | |||||
$never_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_NEVER; | |||||
$is_never = ($option_key === $never_restartable); | |||||
if ($is_never) { | |||||
throw new HarbormasterRestartException( | |||||
pht('Build Plan Prevents Restart'), | |||||
pht( | |||||
'This build can not be restarted because the build plan is '. | |||||
'configured to prevent the build from restarting.')); | |||||
} | |||||
$failed_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_IF_FAILED; | |||||
$is_failed = ($option_key === $failed_restartable); | |||||
if ($is_failed) { | |||||
if (!$this->isFailed()) { | |||||
throw new HarbormasterRestartException( | |||||
pht('Only Restartable if Failed'), | |||||
pht( | |||||
'This build can not be restarted because the build plan is '. | |||||
'configured to prevent the build from restarting unless it '. | |||||
'has failed, and it has not failed.')); | |||||
} | |||||
} | |||||
} | |||||
protected function newCanSendMessageAssertion( | |||||
PhabricatorUser $viewer, | |||||
HarbormasterBuild $build) { | |||||
if ($build->isRestarting()) { | |||||
throw new HarbormasterRestartException( | |||||
pht('Already Restarting'), | |||||
pht( | |||||
'This build is already restarting. You can not reissue a restart '. | |||||
'command to a restarting build.')); | |||||
} | |||||
} | |||||
} | } |