Path: blob/master/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php
12264 views
<?php12final class HarbormasterBuildMessageRestartTransaction3extends HarbormasterBuildMessageTransaction {45const TRANSACTIONTYPE = 'message/restart';6const MESSAGETYPE = 'restart';78public function getHarbormasterBuildMessageName() {9return pht('Restart Build');10}1112public function getHarbormasterBuildableMessageName() {13return pht('Restart Builds');14}1516public function getHarbormasterBuildableMessageEffect() {17return pht('Build will restart.');18}1920public function newConfirmPromptTitle() {21return pht('Really restart build?');22}2324public function newConfirmPromptBody() {25return pht(26'Progress on this build will be discarded and the build will restart. '.27'Side effects of the build will occur again. Really restart build?');28}293031public function getHarbormasterBuildMessageDescription() {32return pht('Restart the build, discarding all progress.');33}3435public function newBuildableConfirmPromptTitle(36array $builds,37array $sendable) {38return pht(39'Really restart %s build(s)?',40phutil_count($builds));41}4243public function newBuildableConfirmPromptBody(44array $builds,45array $sendable) {4647if (count($sendable) === count($builds)) {48return pht(49'All builds will restart.');50} else {51return pht(52'You can only restart some builds.');53}54}5556public function newBuildableConfirmPromptWarnings(57array $builds,58array $sendable) {5960$building = false;61foreach ($sendable as $build) {62if ($build->isBuilding()) {63$building = true;64break;65}66}6768$warnings = array();6970if ($building) {71$warnings[] = pht(72'Progress on running builds will be discarded.');73}7475if ($sendable) {76$warnings[] = pht(77'When a build is restarted, side effects associated with '.78'the build may occur again.');79}8081return $warnings;82}8384public function getTitle() {85return pht(86'%s restarted this build.',87$this->renderAuthor());88}8990public function getIcon() {91return 'fa-repeat';92}9394public function applyInternalEffects($object, $value) {95$actor = $this->getActor();96$build = $object;9798$build->restartBuild($actor);99$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING);100}101102protected function newCanApplyMessageAssertion(103PhabricatorUser $viewer,104HarbormasterBuild $build) {105106if ($build->isAutobuild()) {107throw new HarbormasterMessageException(108pht('Can Not Restart Autobuild'),109pht(110'This build can not be restarted because it is an automatic '.111'build.'));112}113114$restartable = HarbormasterBuildPlanBehavior::BEHAVIOR_RESTARTABLE;115$plan = $build->getBuildPlan();116117// See T13526. Users who can't see the "BuildPlan" can end up here with118// no object. This is highly questionable.119if (!$plan) {120throw new HarbormasterMessageException(121pht('No Build Plan Permission'),122pht(123'You can not restart this build because you do not have '.124'permission to access the build plan.'));125}126127$option = HarbormasterBuildPlanBehavior::getBehavior($restartable)128->getPlanOption($plan);129$option_key = $option->getKey();130131$never_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_NEVER;132$is_never = ($option_key === $never_restartable);133if ($is_never) {134throw new HarbormasterMessageException(135pht('Build Plan Prevents Restart'),136pht(137'This build can not be restarted because the build plan is '.138'configured to prevent the build from restarting.'));139}140141$failed_restartable = HarbormasterBuildPlanBehavior::RESTARTABLE_IF_FAILED;142$is_failed = ($option_key === $failed_restartable);143if ($is_failed) {144if (!$this->isFailed()) {145throw new HarbormasterMessageException(146pht('Only Restartable if Failed'),147pht(148'This build can not be restarted because the build plan is '.149'configured to prevent the build from restarting unless it '.150'has failed, and it has not failed.'));151}152}153154}155156protected function newCanSendMessageAssertion(157PhabricatorUser $viewer,158HarbormasterBuild $build) {159160if ($build->isRestarting()) {161throw new HarbormasterMessageException(162pht('Already Restarting'),163pht(164'This build is already restarting. You can not reissue a restart '.165'command to a restarting build.'));166}167168}169170}171172173