[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/controller/branch/ -> ReleephBranchCreateController.php (source)

   1  <?php
   2  
   3  final class ReleephBranchCreateController extends ReleephProductController {
   4  
   5    private $productID;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->productID = $data['projectID'];
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $viewer = $request->getUser();
  14  
  15      $product = id(new ReleephProductQuery())
  16        ->setViewer($viewer)
  17        ->withIDs(array($this->productID))
  18        ->requireCapabilities(
  19          array(
  20            PhabricatorPolicyCapability::CAN_VIEW,
  21            PhabricatorPolicyCapability::CAN_EDIT,
  22          ))
  23        ->executeOne();
  24      if (!$product) {
  25        return new Aphront404Response();
  26      }
  27      $this->setProduct($product);
  28  
  29  
  30      $cut_point = $request->getStr('cutPoint');
  31      $symbolic_name = $request->getStr('symbolicName');
  32  
  33      if (!$cut_point) {
  34        $repository = $product->getRepository();
  35        switch ($repository->getVersionControlSystem()) {
  36          case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN:
  37            break;
  38          case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:
  39            $cut_point = $product->getTrunkBranch();
  40            break;
  41        }
  42      }
  43  
  44      $e_cut = true;
  45      $errors = array();
  46  
  47      $branch_date_control = id(new AphrontFormDateControl())
  48        ->setUser($request->getUser())
  49        ->setName('templateDate')
  50        ->setLabel(pht('Date'))
  51        ->setCaption(pht('The date used for filling out the branch template.'))
  52        ->setInitialTime(AphrontFormDateControl::TIME_START_OF_DAY);
  53      $branch_date = $branch_date_control->readValueFromRequest($request);
  54  
  55      if ($request->isFormPost()) {
  56        $cut_commit = null;
  57        if (!$cut_point) {
  58          $e_cut = pht('Required');
  59          $errors[] = pht('You must give a branch cut point');
  60        } else {
  61          try {
  62            $finder = id(new ReleephCommitFinder())
  63              ->setUser($request->getUser())
  64              ->setReleephProject($product);
  65            $cut_commit = $finder->fromPartial($cut_point);
  66          } catch (Exception $e) {
  67            $e_cut = pht('Invalid');
  68            $errors[] = $e->getMessage();
  69          }
  70        }
  71  
  72        if (!$errors) {
  73          $branch = id(new ReleephBranchEditor())
  74            ->setReleephProject($product)
  75            ->setActor($request->getUser())
  76            ->newBranchFromCommit(
  77              $cut_commit,
  78              $branch_date,
  79              $symbolic_name);
  80  
  81          $branch_uri = $this->getApplicationURI('branch/'.$branch->getID());
  82  
  83          return id(new AphrontRedirectResponse())
  84            ->setURI($branch_uri);
  85        }
  86      }
  87  
  88      $product_uri = $this->getProductViewURI($product);
  89  
  90      $form = id(new AphrontFormView())
  91        ->setUser($request->getUser())
  92        ->appendChild(
  93          id(new AphrontFormTextControl())
  94            ->setLabel(pht('Symbolic Name'))
  95            ->setName('symbolicName')
  96            ->setValue($symbolic_name)
  97            ->setCaption(pht('Mutable alternate name, for easy reference, '.
  98                '(e.g. "LATEST")')))
  99        ->appendChild(
 100          id(new AphrontFormTextControl())
 101            ->setLabel(pht('Cut point'))
 102            ->setName('cutPoint')
 103            ->setValue($cut_point)
 104            ->setError($e_cut)
 105            ->setCaption(
 106                pht('A commit ID for your repo type, or a '.
 107                'Diffusion ID like "rE123"')))
 108        ->appendChild($branch_date_control)
 109        ->appendChild(
 110          id(new AphrontFormSubmitControl())
 111            ->setValue(pht('Cut Branch'))
 112            ->addCancelButton($product_uri));
 113  
 114      $box = id(new PHUIObjectBoxView())
 115        ->setHeaderText(pht('New Branch'))
 116        ->setFormErrors($errors)
 117        ->appendChild($form);
 118  
 119      $crumbs = $this->buildApplicationCrumbs();
 120      $crumbs->addTextCrumb(pht('New Branch'));
 121  
 122      return $this->buildApplicationPage(
 123        array(
 124          $crumbs,
 125          $box,
 126        ),
 127        array(
 128          'title' => pht('New Branch'),
 129        ));
 130    }
 131  }


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