[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/conduit/ -> DiffusionCreateCommentConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class DiffusionCreateCommentConduitAPIMethod
   4    extends DiffusionConduitAPIMethod {
   5  
   6    public function getAPIMethodName() {
   7      return 'diffusion.createcomment';
   8    }
   9  
  10    public function getMethodStatus() {
  11      return self::METHOD_STATUS_DEPRECATED;
  12    }
  13  
  14    public function getMethodDescription() {
  15      return 'Add a comment to a Diffusion commit. By specifying an action of '.
  16             '"concern", "accept", "resign", or "close", auditing actions can '.
  17             'be triggered. Defaults to "comment".';
  18    }
  19  
  20    public function defineParamTypes() {
  21      return array(
  22        'phid'    => 'required string',
  23        'action'  => 'optional string',
  24        'message' => 'required string',
  25        'silent'  => 'optional bool',
  26      );
  27    }
  28  
  29    public function defineReturnType() {
  30      return 'bool';
  31    }
  32  
  33    public function defineErrorTypes() {
  34      return array(
  35        'ERR_BAD_COMMIT' => 'No commit found with that PHID',
  36        'ERR_BAD_ACTION' => 'Invalid action type',
  37        'ERR_MISSING_MESSAGE' => 'Message is required',
  38      );
  39    }
  40  
  41    protected function execute(ConduitAPIRequest $request) {
  42      $commit_phid = $request->getValue('phid');
  43      $commit = id(new DiffusionCommitQuery())
  44        ->setViewer($request->getUser())
  45        ->withPHIDs(array($commit_phid))
  46        ->needAuditRequests(true)
  47        ->executeOne();
  48      if (!$commit) {
  49        throw new ConduitException('ERR_BAD_COMMIT');
  50      }
  51  
  52      $message = trim($request->getValue('message'));
  53      if (!$message) {
  54        throw new ConduitException('ERR_MISSING_MESSAGE');
  55      }
  56  
  57      $action = $request->getValue('action');
  58      if (!$action) {
  59        $action = PhabricatorAuditActionConstants::COMMENT;
  60      }
  61  
  62      // Disallow ADD_CCS, ADD_AUDITORS forever.
  63      if (!in_array($action, array(
  64        PhabricatorAuditActionConstants::CONCERN,
  65        PhabricatorAuditActionConstants::ACCEPT,
  66        PhabricatorAuditActionConstants::COMMENT,
  67        PhabricatorAuditActionConstants::RESIGN,
  68        PhabricatorAuditActionConstants::CLOSE,
  69      ))) {
  70        throw new ConduitException('ERR_BAD_ACTION');
  71      }
  72  
  73      $xactions = array();
  74  
  75      if ($action != PhabricatorAuditActionConstants::COMMENT) {
  76        $xactions[] = id(new PhabricatorAuditTransaction())
  77          ->setTransactionType(PhabricatorAuditActionConstants::ACTION)
  78          ->setNewValue($action);
  79      }
  80  
  81      if (strlen($message)) {
  82        $xactions[] = id(new PhabricatorAuditTransaction())
  83          ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
  84          ->attachComment(
  85            id(new PhabricatorAuditTransactionComment())
  86              ->setCommitPHID($commit->getPHID())
  87              ->setContent($message));
  88      }
  89  
  90      id(new PhabricatorAuditEditor())
  91        ->setActor($request->getUser())
  92        ->setContentSourceFromConduitRequest($request)
  93        ->setDisableEmail($request->getValue('silent'))
  94        ->setContinueOnMissingFields(true)
  95        ->applyTransactions($commit, $xactions);
  96  
  97      return true;
  98    }
  99  
 100  }


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