Differential D21699 Diff 51675 src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | public function applyInternalEffects($object, $value) { | ||||
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING); | $build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING); | ||||
} | } | ||||
protected function newCanApplyMessageAssertion( | protected function newCanApplyMessageAssertion( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
HarbormasterBuild $build) { | HarbormasterBuild $build) { | ||||
if ($build->isAutobuild()) { | if ($build->isAutobuild()) { | ||||
throw new HarbormasterRestartException( | throw new HarbormasterMessageException( | ||||
pht('Can Not Restart Autobuild'), | pht('Can Not Restart Autobuild'), | ||||
pht( | pht( | ||||
'This build can not be restarted because it is an automatic '. | 'This build can not be restarted because it is an automatic '. | ||||
'build.')); | 'build.')); | ||||
} | } | ||||
$restartable = HarbormasterBuildPlanBehavior::BEHAVIOR_RESTARTABLE; | $restartable = HarbormasterBuildPlanBehavior::BEHAVIOR_RESTARTABLE; | ||||
$plan = $build->getBuildPlan(); | $plan = $build->getBuildPlan(); | ||||
// See T13526. Users who can't see the "BuildPlan" can end up here with | // See T13526. Users who can't see the "BuildPlan" can end up here with | ||||
// no object. This is highly questionable. | // no object. This is highly questionable. | ||||
if (!$plan) { | if (!$plan) { | ||||
throw new HarbormasterRestartException( | throw new HarbormasterMessageException( | ||||
pht('No Build Plan Permission'), | pht('No Build Plan Permission'), | ||||
pht( | pht( | ||||
'You can not restart this build because you do not have '. | 'You can not restart this build because you do not have '. | ||||
'permission to access the build plan.')); | 'permission to access the build plan.')); | ||||
} | } | ||||
$option = HarbormasterBuildPlanBehavior::getBehavior($restartable) | $option = HarbormasterBuildPlanBehavior::getBehavior($restartable) | ||||
->getPlanOption($plan); | ->getPlanOption($plan); | ||||
$option_key = $option->getKey(); | $option_key = $option->getKey(); | ||||
$never_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_NEVER; | $never_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_NEVER; | ||||
$is_never = ($option_key === $never_restartable); | $is_never = ($option_key === $never_restartable); | ||||
if ($is_never) { | if ($is_never) { | ||||
throw new HarbormasterRestartException( | throw new HarbormasterMessageException( | ||||
pht('Build Plan Prevents Restart'), | pht('Build Plan Prevents Restart'), | ||||
pht( | pht( | ||||
'This build can not be restarted because the build plan is '. | 'This build can not be restarted because the build plan is '. | ||||
'configured to prevent the build from restarting.')); | 'configured to prevent the build from restarting.')); | ||||
} | } | ||||
$failed_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_IF_FAILED; | $failed_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_IF_FAILED; | ||||
$is_failed = ($option_key === $failed_restartable); | $is_failed = ($option_key === $failed_restartable); | ||||
if ($is_failed) { | if ($is_failed) { | ||||
if (!$this->isFailed()) { | if (!$this->isFailed()) { | ||||
throw new HarbormasterRestartException( | throw new HarbormasterMessageException( | ||||
pht('Only Restartable if Failed'), | pht('Only Restartable if Failed'), | ||||
pht( | pht( | ||||
'This build can not be restarted because the build plan is '. | 'This build can not be restarted because the build plan is '. | ||||
'configured to prevent the build from restarting unless it '. | 'configured to prevent the build from restarting unless it '. | ||||
'has failed, and it has not failed.')); | 'has failed, and it has not failed.')); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
protected function newCanSendMessageAssertion( | protected function newCanSendMessageAssertion( | ||||
PhabricatorUser $viewer, | PhabricatorUser $viewer, | ||||
HarbormasterBuild $build) { | HarbormasterBuild $build) { | ||||
if ($build->isRestarting()) { | if ($build->isRestarting()) { | ||||
throw new HarbormasterRestartException( | throw new HarbormasterMessageException( | ||||
pht('Already Restarting'), | pht('Already Restarting'), | ||||
pht( | pht( | ||||
'This build is already restarting. You can not reissue a restart '. | 'This build is already restarting. You can not reissue a restart '. | ||||
'command to a restarting build.')); | 'command to a restarting build.')); | ||||
} | } | ||||
} | } | ||||
} | } |