[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/conduit/ -> DifferentialCreateCommentConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class DifferentialCreateCommentConduitAPIMethod
   4    extends DifferentialConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'differential.createcomment';
   8    }
   9  
  10    public function getMethodDescription() {
  11      return pht('Add a comment to a Differential revision.');
  12    }
  13  
  14    public function defineParamTypes() {
  15      return array(
  16        'revision_id'    => 'required revisionid',
  17        'message'        => 'optional string',
  18        'action'         => 'optional string',
  19        'silent'         => 'optional bool',
  20        'attach_inlines' => 'optional bool',
  21      );
  22    }
  23  
  24    public function defineReturnType() {
  25      return 'nonempty dict';
  26    }
  27  
  28    public function defineErrorTypes() {
  29      return array(
  30        'ERR_BAD_REVISION' => 'Bad revision ID.',
  31      );
  32    }
  33  
  34    protected function execute(ConduitAPIRequest $request) {
  35      $viewer = $request->getUser();
  36  
  37      $revision = id(new DifferentialRevisionQuery())
  38        ->setViewer($viewer)
  39        ->withIDs(array($request->getValue('revision_id')))
  40        ->needReviewerStatus(true)
  41        ->needReviewerAuthority(true)
  42        ->executeOne();
  43      if (!$revision) {
  44        throw new ConduitException('ERR_BAD_REVISION');
  45      }
  46  
  47      $xactions = array();
  48  
  49      $action = $request->getValue('action');
  50      if ($action && ($action != 'comment') && ($action != 'none')) {
  51        $xactions[] = id(new DifferentialTransaction())
  52          ->setTransactionType(DifferentialTransaction::TYPE_ACTION)
  53          ->setNewValue($action);
  54      }
  55  
  56      $content = $request->getValue('message');
  57      if (strlen($content)) {
  58        $xactions[] = id(new DifferentialTransaction())
  59          ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
  60          ->attachComment(
  61            id(new DifferentialTransactionComment())
  62              ->setContent($content));
  63      }
  64  
  65      if ($request->getValue('attach_inlines')) {
  66        $type_inline = DifferentialTransaction::TYPE_INLINE;
  67        $inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments(
  68          $viewer,
  69          $revision);
  70        foreach ($inlines as $inline) {
  71          $xactions[] = id(new DifferentialTransaction())
  72            ->setTransactionType($type_inline)
  73            ->attachComment($inline);
  74        }
  75      }
  76  
  77      $editor = id(new DifferentialTransactionEditor())
  78        ->setActor($viewer)
  79        ->setDisableEmail($request->getValue('silent'))
  80        ->setContentSourceFromConduitRequest($request)
  81        ->setContinueOnNoEffect(true)
  82        ->setContinueOnMissingFields(true);
  83  
  84      $editor->applyTransactions($revision, $xactions);
  85  
  86      return array(
  87        'revisionid'  => $revision->getID(),
  88        'uri'         => PhabricatorEnv::getURI('/D'.$revision->getID()),
  89      );
  90    }
  91  
  92  }


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