[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionCommitEditController.php (source)

   1  <?php
   2  
   3  final class DiffusionCommitEditController extends DiffusionController {
   4  
   5    public function willProcessRequest(array $data) {
   6      $data['user'] = $this->getRequest()->getUser();
   7      $this->diffusionRequest = DiffusionRequest::newFromDictionary($data);
   8    }
   9  
  10    public function processRequest() {
  11      $request    = $this->getRequest();
  12      $user       = $request->getUser();
  13      $drequest   = $this->getDiffusionRequest();
  14      $callsign   = $drequest->getRepository()->getCallsign();
  15      $repository = $drequest->getRepository();
  16      $commit     = $drequest->loadCommit();
  17      $data = $commit->loadCommitData();
  18      $page_title = pht('Edit Diffusion Commit');
  19  
  20      if (!$commit) {
  21        return new Aphront404Response();
  22      }
  23  
  24      $commit_phid        = $commit->getPHID();
  25      $edge_type          = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
  26      $current_proj_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
  27        $commit_phid,
  28        $edge_type);
  29      $handles = $this->loadViewerHandles($current_proj_phids);
  30      $proj_t_values = $handles;
  31  
  32      if ($request->isFormPost()) {
  33        $xactions = array();
  34        $proj_phids = $request->getArr('projects');
  35        $xactions[] = id(new PhabricatorAuditTransaction())
  36          ->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
  37          ->setMetadataValue('edge:type', $edge_type)
  38          ->setNewValue(array('=' => array_fuse($proj_phids)));
  39        $editor = id(new PhabricatorAuditEditor())
  40          ->setActor($user)
  41          ->setContinueOnNoEffect(true)
  42          ->setContentSourceFromRequest($request);
  43        $xactions = $editor->applyTransactions($commit, $xactions);
  44        return id(new AphrontRedirectResponse())
  45        ->setURI('/r'.$callsign.$commit->getCommitIdentifier());
  46      }
  47  
  48      $tokenizer_id = celerity_generate_unique_node_id();
  49      $form = id(new AphrontFormView())
  50        ->setUser($user)
  51        ->setAction($request->getRequestURI()->getPath())
  52        ->appendChild(
  53          id(new AphrontFormTokenizerControl())
  54          ->setLabel(pht('Projects'))
  55          ->setName('projects')
  56          ->setValue($proj_t_values)
  57          ->setID($tokenizer_id)
  58          ->setCaption(
  59            javelin_tag(
  60              'a',
  61              array(
  62                'href'        => '/project/create/',
  63                'mustcapture' => true,
  64                'sigil'       => 'project-create',
  65              ),
  66              pht('Create New Project')))
  67          ->setDatasource(new PhabricatorProjectDatasource()));
  68  
  69      $reason = $data->getCommitDetail('autocloseReason', false);
  70      if ($reason !== false) {
  71        switch ($reason) {
  72          case PhabricatorRepository::BECAUSE_REPOSITORY_IMPORTING:
  73            $desc = pht('No, Repository Importing');
  74            break;
  75          case PhabricatorRepository::BECAUSE_AUTOCLOSE_DISABLED:
  76            $desc = pht('No, Autoclose Disabled');
  77            break;
  78          case PhabricatorRepository::BECAUSE_NOT_ON_AUTOCLOSE_BRANCH:
  79            $desc = pht('No, Not On Autoclose Branch');
  80            break;
  81          case null:
  82            $desc = pht('Yes');
  83            break;
  84          default:
  85            $desc = pht('Unknown');
  86            break;
  87        }
  88  
  89        $doc_href = PhabricatorEnv::getDoclink('Diffusion User Guide: Autoclose');
  90        $doc_link = phutil_tag(
  91          'a',
  92          array(
  93            'href' => $doc_href,
  94            'target' => '_blank',
  95          ),
  96          pht('Learn More'));
  97  
  98        $form->appendChild(
  99          id(new AphrontFormMarkupControl())
 100            ->setLabel(pht('Autoclose?'))
 101            ->setValue(array($desc, " \xC2\xB7 ", $doc_link)));
 102      }
 103  
 104  
 105      Javelin::initBehavior('project-create', array(
 106        'tokenizerID' => $tokenizer_id,
 107      ));
 108  
 109      $submit = id(new AphrontFormSubmitControl())
 110        ->setValue(pht('Save'))
 111        ->addCancelButton('/r'.$callsign.$commit->getCommitIdentifier());
 112      $form->appendChild($submit);
 113  
 114      $crumbs = $this->buildCrumbs(array(
 115        'commit' => true,
 116      ));
 117      $crumbs->addTextCrumb(pht('Edit'));
 118  
 119      $form_box = id(new PHUIObjectBoxView())
 120        ->setHeaderText($page_title)
 121        ->setForm($form);
 122  
 123      return $this->buildApplicationPage(
 124        array(
 125          $crumbs,
 126          $form_box,
 127        ),
 128        array(
 129          'title' => $page_title,
 130        ));
 131    }
 132  
 133  }


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