Differential D20679 Diff 49321 src/applications/harbormaster/controller/HarbormasterBuildableActionController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/controller/HarbormasterBuildableActionController.php
| Show All 18 Lines | $buildable = id(new HarbormasterBuildableQuery()) | ||||
| )) | )) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$buildable) { | if (!$buildable) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $issuable = array(); | $issuable = array(); | ||||
| foreach ($buildable->getBuilds() as $build) { | $builds = $buildable->getBuilds(); | ||||
| foreach ($builds as $key => $build) { | |||||
| switch ($action) { | switch ($action) { | ||||
| case HarbormasterBuildCommand::COMMAND_RESTART: | case HarbormasterBuildCommand::COMMAND_RESTART: | ||||
| if ($build->canRestartBuild()) { | if ($build->canRestartBuild()) { | ||||
| $issuable[] = $build; | $issuable[$key] = $build; | ||||
| } | } | ||||
| break; | break; | ||||
| case HarbormasterBuildCommand::COMMAND_PAUSE: | case HarbormasterBuildCommand::COMMAND_PAUSE: | ||||
| if ($build->canPauseBuild()) { | if ($build->canPauseBuild()) { | ||||
| $issuable[] = $build; | $issuable[$key] = $build; | ||||
| } | } | ||||
| break; | break; | ||||
| case HarbormasterBuildCommand::COMMAND_RESUME: | case HarbormasterBuildCommand::COMMAND_RESUME: | ||||
| if ($build->canResumeBuild()) { | if ($build->canResumeBuild()) { | ||||
| $issuable[] = $build; | $issuable[$key] = $build; | ||||
| } | } | ||||
| break; | break; | ||||
| case HarbormasterBuildCommand::COMMAND_ABORT: | case HarbormasterBuildCommand::COMMAND_ABORT: | ||||
| if ($build->canAbortBuild()) { | if ($build->canAbortBuild()) { | ||||
| $issuable[] = $build; | $issuable[$key] = $build; | ||||
| } | } | ||||
| break; | break; | ||||
| default: | default: | ||||
| return new Aphront400Response(); | return new Aphront400Response(); | ||||
| } | } | ||||
| } | } | ||||
| $restricted = false; | $restricted = false; | ||||
| foreach ($issuable as $key => $build) { | foreach ($issuable as $key => $build) { | ||||
| if (!$build->canIssueCommand($viewer, $action)) { | if (!$build->canIssueCommand($viewer, $action)) { | ||||
| $restricted = true; | $restricted = true; | ||||
| unset($issuable[$key]); | unset($issuable[$key]); | ||||
| } | } | ||||
| } | } | ||||
| $building = false; | |||||
| foreach ($issuable as $key => $build) { | |||||
| if ($build->isBuilding()) { | |||||
| $building = true; | |||||
| break; | |||||
| } | |||||
| } | |||||
| $return_uri = '/'.$buildable->getMonogram(); | $return_uri = '/'.$buildable->getMonogram(); | ||||
| if ($request->isDialogFormPost() && $issuable) { | if ($request->isDialogFormPost() && $issuable) { | ||||
| $editor = id(new HarbormasterBuildableTransactionEditor()) | $editor = id(new HarbormasterBuildableTransactionEditor()) | ||||
| ->setActor($viewer) | ->setActor($viewer) | ||||
| ->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
| ->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
| ->setContinueOnMissingFields(true); | ->setContinueOnMissingFields(true); | ||||
| Show All 14 Lines | if ($request->isDialogFormPost() && $issuable) { | ||||
| ->setTransactionType(HarbormasterBuildTransaction::TYPE_COMMAND) | ->setTransactionType(HarbormasterBuildTransaction::TYPE_COMMAND) | ||||
| ->setNewValue($action); | ->setNewValue($action); | ||||
| $build_editor->applyTransactions($build, array($xaction)); | $build_editor->applyTransactions($build, array($xaction)); | ||||
| } | } | ||||
| return id(new AphrontRedirectResponse())->setURI($return_uri); | return id(new AphrontRedirectResponse())->setURI($return_uri); | ||||
| } | } | ||||
| $width = AphrontDialogView::WIDTH_DEFAULT; | |||||
| switch ($action) { | switch ($action) { | ||||
| case HarbormasterBuildCommand::COMMAND_RESTART: | case HarbormasterBuildCommand::COMMAND_RESTART: | ||||
| if ($issuable) { | // See T13348. The "Restart Builds" action may restart only a subset | ||||
| $title = pht('Really restart builds?'); | // of builds, so show the user a preview of which builds will actually | ||||
| // restart. | |||||
| if ($restricted) { | $body = array(); | ||||
| $body = pht( | |||||
| 'You only have permission to restart some builds. Progress '. | |||||
| 'on builds you have permission to restart will be discarded '. | |||||
| 'and they will restart. Side effects of these builds will '. | |||||
| 'occur again. Really restart all builds?'); | |||||
| } else { | |||||
| $body = pht( | |||||
| 'Progress on all builds will be discarded, and all builds will '. | |||||
| 'restart. Side effects of the builds will occur again. Really '. | |||||
| 'restart all builds?'); | |||||
| } | |||||
| if ($issuable) { | |||||
| $title = pht('Restart Builds'); | |||||
| $submit = pht('Restart Builds'); | $submit = pht('Restart Builds'); | ||||
| } else { | } else { | ||||
| $title = pht('Unable to Restart Builds'); | $title = pht('Unable to Restart Builds'); | ||||
| } | |||||
| if ($builds) { | |||||
| $width = AphrontDialogView::WIDTH_FORM; | |||||
| $body[] = pht('Builds for this buildable:'); | |||||
| $rows = array(); | |||||
| foreach ($builds as $key => $build) { | |||||
| if (isset($issuable[$key])) { | |||||
| $icon = id(new PHUIIconView()) | |||||
| ->setIcon('fa-repeat green'); | |||||
| $build_note = pht('Will Restart'); | |||||
| } else { | |||||
| $icon = null; | |||||
| try { | |||||
| $build->assertCanRestartBuild(); | |||||
| } catch (HarbormasterRestartException $ex) { | |||||
| $icon = id(new PHUIIconView()) | |||||
| ->setIcon('fa-times red'); | |||||
| $build_note = pht( | |||||
| '%s: %s', | |||||
| phutil_tag('strong', array(), pht('Not Restartable')), | |||||
| $ex->getTitle()); | |||||
| } | |||||
| if (!$icon) { | |||||
| try { | |||||
| $build->assertCanIssueCommand($viewer, $action); | |||||
| } catch (PhabricatorPolicyException $ex) { | |||||
| $icon = id(new PHUIIconView()) | |||||
| ->setIcon('fa-lock red'); | |||||
| $build_note = pht( | |||||
| '%s: %s', | |||||
| phutil_tag('strong', array(), pht('Not Restartable')), | |||||
| pht('You do not have permission to restart this build.')); | |||||
| } | |||||
| } | |||||
| if (!$icon) { | |||||
| $icon = id(new PHUIIconView()) | |||||
| ->setIcon('fa-times red'); | |||||
| $build_note = pht('Will Not Restart'); | |||||
| } | |||||
| } | |||||
| $build_name = phutil_tag( | |||||
| 'a', | |||||
| array( | |||||
| 'href' => $build->getURI(), | |||||
| 'target' => '_blank', | |||||
| ), | |||||
| pht('%s %s', $build->getObjectName(), $build->getName())); | |||||
| $rows[] = array( | |||||
| $icon, | |||||
| $build_name, | |||||
| $build_note, | |||||
| ); | |||||
| } | |||||
| $table = id(new AphrontTableView($rows)) | |||||
| ->setHeaders( | |||||
| array( | |||||
| null, | |||||
| pht('Build'), | |||||
| pht('Action'), | |||||
| )) | |||||
| ->setColumnClasses( | |||||
| array( | |||||
| null, | |||||
| 'pri', | |||||
| 'wide', | |||||
| )); | |||||
| $table = phutil_tag( | |||||
| 'div', | |||||
| array( | |||||
| 'class' => 'mlt mlb', | |||||
| ), | |||||
| $table); | |||||
| $body[] = $table; | |||||
| } | |||||
| if ($issuable) { | |||||
| $warnings = array(); | |||||
| if ($restricted) { | |||||
| $warnings[] = pht( | |||||
| 'You only have permission to restart some builds.'); | |||||
| } | |||||
| if ($building) { | |||||
| $warnings[] = pht( | |||||
| 'Progress on running builds will be discarded.'); | |||||
| } | |||||
| $warnings[] = pht( | |||||
| 'When a build is restarted, side effects associated with '. | |||||
| 'the build may occur again.'); | |||||
| $body[] = id(new PHUIInfoView()) | |||||
| ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | |||||
| ->setErrors($warnings); | |||||
| $body[] = pht('Really restart builds?'); | |||||
| } else { | |||||
| if ($restricted) { | if ($restricted) { | ||||
| $body = pht('You do not have permission to restart any builds.'); | $body[] = pht('You do not have permission to restart any builds.'); | ||||
| } else { | } else { | ||||
| $body = pht('No builds can be restarted.'); | $body[] = pht('No builds can be restarted.'); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| case HarbormasterBuildCommand::COMMAND_PAUSE: | case HarbormasterBuildCommand::COMMAND_PAUSE: | ||||
| if ($issuable) { | if ($issuable) { | ||||
| $title = pht('Really pause builds?'); | $title = pht('Really pause builds?'); | ||||
| if ($restricted) { | if ($restricted) { | ||||
| $body = pht( | $body = pht( | ||||
| 'You only have permission to pause some builds. Once the '. | 'You only have permission to pause some builds. Once the '. | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | switch ($action) { | ||||
| $body = pht('No builds can be resumed.'); | $body = pht('No builds can be resumed.'); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| $dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setWidth($width) | |||||
| ->setTitle($title) | ->setTitle($title) | ||||
| ->appendChild($body) | ->appendChild($body) | ||||
| ->addCancelButton($return_uri); | ->addCancelButton($return_uri); | ||||
| if ($issuable) { | if ($issuable) { | ||||
| $dialog->addSubmitButton($submit); | $dialog->addSubmitButton($submit); | ||||
| } | } | ||||
| return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
| } | } | ||||
| } | } | ||||