[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class ReleephRequestActionController
   4    extends ReleephRequestController {
   5  
   6    private $action;
   7    private $requestID;
   8  
   9    public function willProcessRequest(array $data) {
  10      $this->action = $data['action'];
  11      $this->requestID = $data['requestID'];
  12    }
  13  
  14    public function processRequest() {
  15      $request = $this->getRequest();
  16      $viewer = $request->getUser();
  17  
  18      $request->validateCSRF();
  19  
  20      $pull = id(new ReleephRequestQuery())
  21        ->setViewer($viewer)
  22        ->withIDs(array($this->requestID))
  23        ->executeOne();
  24      if (!$pull) {
  25        return new Aphront404Response();
  26      }
  27  
  28      $branch = $pull->getBranch();
  29      $product = $branch->getProduct();
  30  
  31      $action = $this->action;
  32  
  33      $origin_uri = '/'.$pull->getMonogram();
  34  
  35      $editor = id(new ReleephRequestTransactionalEditor())
  36        ->setActor($viewer)
  37        ->setContinueOnNoEffect(true)
  38        ->setContentSourceFromRequest($request);
  39  
  40      $xactions = array();
  41  
  42      switch ($action) {
  43        case 'want':
  44        case 'pass':
  45          static $action_map = array(
  46            'want' => ReleephRequest::INTENT_WANT,
  47            'pass' => ReleephRequest::INTENT_PASS,
  48          );
  49          $intent = $action_map[$action];
  50          $xactions[] = id(new ReleephRequestTransaction())
  51            ->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
  52            ->setMetadataValue(
  53              'isAuthoritative',
  54              $product->isAuthoritative($viewer))
  55            ->setNewValue($intent);
  56          break;
  57  
  58        case 'mark-manually-picked':
  59        case 'mark-manually-reverted':
  60          if (
  61            $pull->getRequestUserPHID() === $viewer->getPHID() ||
  62            $product->isAuthoritative($viewer)) {
  63  
  64            // We're all good!
  65          } else {
  66            throw new Exception(
  67              "Bug!  Only pushers or the requestor can manually change a ".
  68              "request's in-branch status!");
  69          }
  70  
  71          if ($action === 'mark-manually-picked') {
  72            $in_branch = 1;
  73            $intent = ReleephRequest::INTENT_WANT;
  74          } else {
  75            $in_branch = 0;
  76            $intent = ReleephRequest::INTENT_PASS;
  77          }
  78  
  79          $xactions[] = id(new ReleephRequestTransaction())
  80            ->setTransactionType(ReleephRequestTransaction::TYPE_USER_INTENT)
  81            ->setMetadataValue('isManual', true)
  82            ->setMetadataValue('isAuthoritative', true)
  83            ->setNewValue($intent);
  84  
  85          $xactions[] = id(new ReleephRequestTransaction())
  86            ->setTransactionType(ReleephRequestTransaction::TYPE_MANUAL_IN_BRANCH)
  87            ->setNewValue($in_branch);
  88  
  89          break;
  90  
  91        default:
  92          throw new Exception("unknown or unimplemented action {$action}");
  93      }
  94  
  95      $editor->applyTransactions($pull, $xactions);
  96  
  97      if ($request->getBool('render')) {
  98        $field_list = PhabricatorCustomField::getObjectFields(
  99          $pull,
 100          PhabricatorCustomField::ROLE_VIEW);
 101  
 102        $field_list
 103          ->setViewer($viewer)
 104          ->readFieldsFromStorage($pull);
 105  
 106        // TODO: This should be more modern and general.
 107        $engine = id(new PhabricatorMarkupEngine())
 108          ->setViewer($viewer);
 109        foreach ($field_list->getFields() as $field) {
 110          if ($field->shouldMarkup()) {
 111            $field->setMarkupEngine($engine);
 112          }
 113        }
 114        $engine->process();
 115  
 116        $pull_box = id(new ReleephRequestView())
 117          ->setUser($viewer)
 118          ->setCustomFields($field_list)
 119          ->setPullRequest($pull)
 120          ->setIsListView(true);
 121  
 122        return id(new AphrontAjaxResponse())->setContent(
 123          array(
 124            'markup' => hsprintf('%s', $pull_box),
 125          ));
 126      }
 127  
 128      return id(new AphrontRedirectResponse())->setURI($origin_uri);
 129    }
 130  }


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