[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/controller/request/ -> ReleephRequestDifferentialCreateController.php (source)

   1  <?php
   2  
   3  // TODO: After T2222, this is likely unreachable?
   4  
   5  final class ReleephRequestDifferentialCreateController
   6    extends ReleephController {
   7  
   8    private $revisionID;
   9    private $revision;
  10  
  11    public function willProcessRequest(array $data) {
  12      $this->revisionID = $data['diffRevID'];
  13    }
  14  
  15    public function processRequest() {
  16      $request = $this->getRequest();
  17      $user = $request->getUser();
  18  
  19      $diff_rev = id(new DifferentialRevisionQuery())
  20        ->setViewer($user)
  21        ->withIDs(array($this->revisionID))
  22        ->executeOne();
  23      if (!$diff_rev) {
  24        return new Aphront404Response();
  25      }
  26      $this->revision = $diff_rev;
  27  
  28      $arc_project = id(new PhabricatorRepositoryArcanistProject())
  29        ->loadOneWhere('phid = %s', $this->revision->getArcanistProjectPHID());
  30  
  31      $projects = id(new ReleephProject())->loadAllWhere(
  32        'arcanistProjectID = %d AND isActive = 1',
  33        $arc_project->getID());
  34      if (!$projects) {
  35        throw new Exception(sprintf(
  36          "D%d belongs to the '%s' Arcanist project, ".
  37          "which is not part of any Releeph project!",
  38          $this->revision->getID(),
  39          $arc_project->getName()));
  40      }
  41  
  42      $branches = id(new ReleephBranch())->loadAllWhere(
  43        'releephProjectID IN (%Ld) AND isActive = 1',
  44        mpull($projects, 'getID'));
  45      if (!$branches) {
  46        throw new Exception(sprintf(
  47          'D%d could be in the Releeph project(s) %s, '.
  48          'but this project / none of these projects have open branches.',
  49          $this->revision->getID(),
  50          implode(', ', mpull($projects, 'getName'))));
  51      }
  52  
  53      if (count($branches) === 1) {
  54        return id(new AphrontRedirectResponse())
  55          ->setURI($this->buildReleephRequestURI(head($branches)));
  56      }
  57  
  58      $projects = msort(
  59        mpull($projects, null, 'getID'),
  60        'getName');
  61  
  62      $branch_groups = mgroup($branches, 'getReleephProjectID');
  63  
  64      require_celerity_resource('releeph-request-differential-create-dialog');
  65      $dialog = id(new AphrontDialogView())
  66        ->setUser($user)
  67        ->setTitle(pht('Choose Releeph Branch'))
  68        ->setClass('releeph-request-differential-create-dialog')
  69        ->addCancelButton('/D'.$request->getStr('D'));
  70  
  71      $dialog->appendChild(
  72        pht('This differential revision changes code that is associated '.
  73        'with multiple Releeph branches. '.
  74        'Please select the branch where you would like this code to be picked.'));
  75  
  76      foreach ($branch_groups as $project_id => $branches) {
  77        $project = idx($projects, $project_id);
  78        $dialog->appendChild(
  79          phutil_tag(
  80            'h1',
  81            array(),
  82            $project->getName()));
  83        $branches = msort($branches, 'getBasename');
  84        foreach ($branches as $branch) {
  85          $uri = $this->buildReleephRequestURI($branch);
  86          $dialog->appendChild(
  87            phutil_tag(
  88              'a',
  89              array(
  90                'href' => $uri,
  91              ),
  92              $branch->getDisplayNameWithDetail()));
  93        }
  94      }
  95  
  96      return id(new AphrontDialogResponse())
  97        ->setDialog($dialog);
  98    }
  99  
 100    private function buildReleephRequestURI(ReleephBranch $branch) {
 101      $uri = $branch->getURI('request/');
 102      return id(new PhutilURI($uri))
 103        ->setQueryParam('D', $this->revision->getID());
 104    }
 105  
 106  }


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