[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/transactions/controller/ -> PhabricatorApplicationTransactionCommentEditController.php (source)

   1  <?php
   2  
   3  final class PhabricatorApplicationTransactionCommentEditController
   4    extends PhabricatorApplicationTransactionController {
   5  
   6    private $phid;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->phid = $data['phid'];
  10    }
  11  
  12    public function processRequest() {
  13      $request = $this->getRequest();
  14      $user = $request->getUser();
  15  
  16      $xaction = id(new PhabricatorObjectQuery())
  17        ->withPHIDs(array($this->phid))
  18        ->setViewer($user)
  19        ->executeOne();
  20  
  21      if (!$xaction) {
  22        return new Aphront404Response();
  23      }
  24  
  25      if (!$xaction->getComment()) {
  26        // You can't currently edit a transaction which doesn't have a comment.
  27        // Some day you may be able to edit the visibility.
  28        return new Aphront404Response();
  29      }
  30  
  31      if ($xaction->getComment()->getIsRemoved()) {
  32        // You can't edit history of a transaction with a removed comment.
  33        return new Aphront400Response();
  34      }
  35  
  36      $obj_phid = $xaction->getObjectPHID();
  37      $obj_handle = id(new PhabricatorHandleQuery())
  38        ->setViewer($user)
  39        ->withPHIDs(array($obj_phid))
  40        ->executeOne();
  41  
  42      if ($request->isDialogFormPost()) {
  43        $text = $request->getStr('text');
  44  
  45        $comment = $xaction->getApplicationTransactionCommentObject();
  46        $comment->setContent($text);
  47        if (!strlen($text)) {
  48          $comment->setIsDeleted(true);
  49        }
  50  
  51        $editor = id(new PhabricatorApplicationTransactionCommentEditor())
  52          ->setActor($user)
  53          ->setContentSource(PhabricatorContentSource::newFromRequest($request))
  54          ->applyEdit($xaction, $comment);
  55  
  56        if ($request->isAjax()) {
  57          return id(new AphrontAjaxResponse())->setContent(array());
  58        } else {
  59          return id(new AphrontReloadResponse())->setURI($obj_handle->getURI());
  60        }
  61      }
  62  
  63      $dialog = id(new AphrontDialogView())
  64        ->setUser($user)
  65        ->setSubmitURI(
  66          $this->getApplicationURI('/transactions/edit/'.$xaction->getPHID().'/'))
  67        ->setTitle(pht('Edit Comment'));
  68  
  69      $dialog
  70        ->addHiddenInput('anchor', $request->getStr('anchor'))
  71        ->appendChild(
  72          id(new PHUIFormLayoutView())
  73          ->setFullWidth(true)
  74          ->appendChild(
  75            id(new PhabricatorRemarkupControl())
  76            ->setUser($user)
  77            ->setName('text')
  78            ->setValue($xaction->getComment()->getContent())));
  79  
  80      $dialog
  81        ->addSubmitButton(pht('Save Changes'))
  82        ->addCancelButton($obj_handle->getURI());
  83  
  84      return id(new AphrontDialogResponse())->setDialog($dialog);
  85    }
  86  
  87  }


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