diff --git a/src/applications/harbormaster/controller/HarbormasterBuildActionController.php b/src/applications/harbormaster/controller/HarbormasterBuildActionController.php index 843ffd4702..b56c7de7f7 100644 --- a/src/applications/harbormaster/controller/HarbormasterBuildActionController.php +++ b/src/applications/harbormaster/controller/HarbormasterBuildActionController.php @@ -64,6 +64,11 @@ final class HarbormasterBuildActionController 'restart. Side effects of the build will occur again. Really '. 'restart build?'); $submit = pht('Restart Build'); + } else if (!$build->getBuildPlan()->canRestartBuildPlan()) { + $title = pht('Not Restartable'); + $body = pht( + 'The build plan for this build is not restartable, so you '. + 'can not restart the build.'); } else { $title = pht('Unable to Restart Build'); if ($build->isRestarting()) { @@ -135,8 +140,7 @@ final class HarbormasterBuildActionController break; } - $dialog = id(new AphrontDialogView()) - ->setUser($viewer) + $dialog = $this->newDialog() ->setTitle($title) ->appendChild($body) ->addCancelButton($return_uri); @@ -145,7 +149,7 @@ final class HarbormasterBuildActionController $dialog->addSubmitButton($submit); } - return id(new AphrontDialogResponse())->setDialog($dialog); + return $dialog; } } diff --git a/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php b/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php index 893d351065..66c186a0d1 100644 --- a/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php +++ b/src/applications/harbormaster/plan/HarbormasterBuildPlanBehavior.php @@ -13,6 +13,10 @@ final class HarbormasterBuildPlanBehavior const RUNNABLE_IF_VIEWABLE = 'view'; const RUNNABLE_IF_EDITABLE = 'edit'; + const BEHAVIOR_RESTARTABLE = 'restartable'; + const RESTARTABLE_ALWAYS = 'always'; + const RESTARTABLE_NEVER = 'never'; + public function setKey($key) { $this->key = $key; return $this; @@ -225,14 +229,14 @@ final class HarbormasterBuildPlanBehavior $restart_options = array( id(new HarbormasterBuildPlanBehaviorOption()) - ->setKey('always') + ->setKey(self::RESTARTABLE_ALWAYS) ->setIcon('fa-repeat green') ->setName(pht('Always')) ->setIsDefault(true) ->setDescription( pht('The build may be restarted.')), id(new HarbormasterBuildPlanBehaviorOption()) - ->setKey('never') + ->setKey(self::RESTARTABLE_NEVER) ->setIcon('fa-times red') ->setName(pht('Never')) ->setDescription( @@ -317,7 +321,7 @@ final class HarbormasterBuildPlanBehavior ->setName(pht('Affects Buildable')) ->setOptions($aggregate_options), id(new self()) - ->setKey('restartable') + ->setKey(self::BEHAVIOR_RESTARTABLE) ->setEditInstructions( pht( 'Usually, builds may be restarted. This may be useful if you '. diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php index 9b7b64d06b..063f81ff1e 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -215,6 +215,11 @@ final class HarbormasterBuild extends HarbormasterDAO return false; } + $plan = $this->getBuildPlan(); + if (!$plan->canRestartBuildPlan()) { + return false; + } + return !$this->isRestarting(); } diff --git a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php index 798201f490..efe62a6f84 100644 --- a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php +++ b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php @@ -175,6 +175,16 @@ final class HarbormasterBuildPlan extends HarbormasterDAO $capability); } + public function canRestartBuildPlan() { + $restartable = HarbormasterBuildPlanBehavior::BEHAVIOR_RESTARTABLE; + $is_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_ALWAYS; + + $option = HarbormasterBuildPlanBehavior::getBehavior($restartable) + ->getPlanOption($this); + + return ($option->getKey() === $is_restartable); + } + /* -( PhabricatorSubscribableInterface )----------------------------------- */