[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/pholio/controller/ -> PholioMockCommentController.php (source)

   1  <?php
   2  
   3  final class PholioMockCommentController extends PholioController {
   4  
   5    private $id;
   6  
   7    public function willProcessRequest(array $data) {
   8      $this->id = $data['id'];
   9    }
  10  
  11    public function processRequest() {
  12      $request = $this->getRequest();
  13      $user = $request->getUser();
  14  
  15      if (!$request->isFormPost()) {
  16        return new Aphront400Response();
  17      }
  18  
  19      $mock = id(new PholioMockQuery())
  20        ->setViewer($user)
  21        ->withIDs(array($this->id))
  22        ->needImages(true)
  23        ->executeOne();
  24  
  25      if (!$mock) {
  26        return new Aphront404Response();
  27      }
  28  
  29      $is_preview = $request->isPreviewRequest();
  30  
  31      $draft = PhabricatorDraft::buildFromRequest($request);
  32  
  33      $mock_uri = '/M'.$mock->getID();
  34  
  35      $comment = $request->getStr('comment');
  36  
  37      $xactions = array();
  38  
  39      $inline_comments = id(new PholioTransactionComment())->loadAllWhere(
  40        'authorphid = %s AND transactionphid IS NULL AND imageid IN (%Ld)',
  41        $user->getPHID(),
  42        mpull($mock->getImages(), 'getID'));
  43  
  44      if (!$inline_comments || strlen($comment)) {
  45        $xactions[] = id(new PholioTransaction())
  46          ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
  47          ->attachComment(
  48            id(new PholioTransactionComment())
  49              ->setContent($comment));
  50      }
  51  
  52      foreach ($inline_comments as $inline_comment) {
  53        $xactions[] = id(new PholioTransaction())
  54          ->setTransactionType(PholioTransactionType::TYPE_INLINE)
  55          ->attachComment($inline_comment);
  56      }
  57  
  58      $editor = id(new PholioMockEditor())
  59        ->setActor($user)
  60        ->setContentSourceFromRequest($request)
  61        ->setContinueOnNoEffect($request->isContinueRequest())
  62        ->setIsPreview($is_preview);
  63  
  64      try {
  65        $xactions = $editor->applyTransactions($mock, $xactions);
  66      } catch (PhabricatorApplicationTransactionNoEffectException $ex) {
  67        return id(new PhabricatorApplicationTransactionNoEffectResponse())
  68          ->setCancelURI($mock_uri)
  69          ->setException($ex);
  70      }
  71  
  72      if ($draft) {
  73        $draft->replaceOrDelete();
  74      }
  75  
  76      if ($request->isAjax() && $is_preview) {
  77        $xaction_view = id(new PholioTransactionView())
  78          ->setMock($mock);
  79  
  80        return id(new PhabricatorApplicationTransactionResponse())
  81          ->setViewer($user)
  82          ->setTransactions($xactions)
  83          ->setTransactionView($xaction_view)
  84          ->setIsPreview($is_preview);
  85      } else {
  86        return id(new AphrontRedirectResponse())->setURI($mock_uri);
  87      }
  88    }
  89  
  90  }


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