[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/harbormaster/controller/ -> HarbormasterBuildActionController.php (source)

   1  <?php
   2  
   3  final class HarbormasterBuildActionController
   4    extends HarbormasterController {
   5  
   6    private $id;
   7    private $action;
   8    private $via;
   9  
  10    public function willProcessRequest(array $data) {
  11      $this->id = $data['id'];
  12      $this->action = $data['action'];
  13      $this->via = idx($data, 'via');
  14    }
  15  
  16    public function processRequest() {
  17      $request = $this->getRequest();
  18      $viewer = $request->getUser();
  19      $command = $this->action;
  20  
  21      $build = id(new HarbormasterBuildQuery())
  22        ->setViewer($viewer)
  23        ->withIDs(array($this->id))
  24        ->requireCapabilities(
  25          array(
  26            PhabricatorPolicyCapability::CAN_VIEW,
  27            PhabricatorPolicyCapability::CAN_EDIT,
  28          ))
  29        ->executeOne();
  30      if (!$build) {
  31        return new Aphront404Response();
  32      }
  33  
  34      switch ($command) {
  35        case HarbormasterBuildCommand::COMMAND_RESTART:
  36          $can_issue = $build->canRestartBuild();
  37          break;
  38        case HarbormasterBuildCommand::COMMAND_STOP:
  39          $can_issue = $build->canStopBuild();
  40          break;
  41        case HarbormasterBuildCommand::COMMAND_RESUME:
  42          $can_issue = $build->canResumeBuild();
  43          break;
  44        default:
  45          return new Aphront400Response();
  46      }
  47  
  48      switch ($this->via) {
  49        case 'buildable':
  50          $return_uri = '/'.$build->getBuildable()->getMonogram();
  51          break;
  52        default:
  53          $return_uri = $this->getApplicationURI('/build/'.$build->getID().'/');
  54          break;
  55      }
  56  
  57      if ($request->isDialogFormPost() && $can_issue) {
  58        $editor = id(new HarbormasterBuildTransactionEditor())
  59          ->setActor($viewer)
  60          ->setContentSourceFromRequest($request)
  61          ->setContinueOnNoEffect(true)
  62          ->setContinueOnMissingFields(true);
  63  
  64        $xaction = id(new HarbormasterBuildTransaction())
  65          ->setTransactionType(HarbormasterBuildTransaction::TYPE_COMMAND)
  66          ->setNewValue($command);
  67  
  68        $editor->applyTransactions($build, array($xaction));
  69  
  70        return id(new AphrontRedirectResponse())->setURI($return_uri);
  71      }
  72  
  73      switch ($command) {
  74        case HarbormasterBuildCommand::COMMAND_RESTART:
  75          if ($can_issue) {
  76            $title = pht('Really restart build?');
  77            $body = pht(
  78              'Progress on this build will be discarded and the build will '.
  79              'restart. Side effects of the build will occur again. Really '.
  80              'restart build?');
  81            $submit = pht('Restart Build');
  82          } else {
  83            $title = pht('Unable to Restart Build');
  84            if ($build->isRestarting()) {
  85              $body = pht(
  86                'This build is already restarting. You can not reissue a '.
  87                'restart command to a restarting build.');
  88            } else {
  89              $body = pht(
  90                'You can not restart this build.');
  91            }
  92          }
  93          break;
  94        case HarbormasterBuildCommand::COMMAND_STOP:
  95          if ($can_issue) {
  96            $title = pht('Really pause build?');
  97            $body = pht(
  98              'If you pause this build, work will halt once the current steps '.
  99              'complete. You can resume the build later.');
 100            $submit = pht('Pause Build');
 101          } else {
 102            $title = pht('Unable to Pause Build');
 103            if ($build->isComplete()) {
 104              $body = pht(
 105                'This build is already complete. You can not pause a completed '.
 106                'build.');
 107            } else if ($build->isStopped()) {
 108              $body = pht(
 109                'This build is already paused. You can not pause a build which '.
 110                'has already been paused.');
 111            } else if ($build->isStopping()) {
 112              $body = pht(
 113                'This build is already pausing. You can not reissue a pause '.
 114                'command to a pausing build.');
 115            } else {
 116              $body = pht(
 117                'This build can not be paused.');
 118            }
 119          }
 120          break;
 121        case HarbormasterBuildCommand::COMMAND_RESUME:
 122          if ($can_issue) {
 123            $title = pht('Really resume build?');
 124            $body = pht(
 125              'Work will continue on the build. Really resume?');
 126            $submit = pht('Resume Build');
 127          } else {
 128            $title = pht('Unable to Resume Build');
 129            if ($build->isResuming()) {
 130              $body = pht(
 131                'This build is already resuming. You can not reissue a resume '.
 132                'command to a resuming build.');
 133            } else if (!$build->isStopped()) {
 134              $body = pht(
 135                'This build is not stopped. You can only resume a stopped '.
 136                'build.');
 137            }
 138          }
 139          break;
 140      }
 141  
 142      $dialog = id(new AphrontDialogView())
 143        ->setUser($viewer)
 144        ->setTitle($title)
 145        ->appendChild($body)
 146        ->addCancelButton($return_uri);
 147  
 148      if ($can_issue) {
 149        $dialog->addSubmitButton($submit);
 150      }
 151  
 152      return id(new AphrontDialogResponse())->setDialog($dialog);
 153    }
 154  
 155  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1