Path: blob/master/src/applications/differential/conduit/DifferentialCreateCommentConduitAPIMethod.php
12256 views
<?php12final class DifferentialCreateCommentConduitAPIMethod3extends DifferentialConduitAPIMethod {45public function getAPIMethodName() {6return 'differential.createcomment';7}89public function getMethodDescription() {10return pht('Add a comment to a Differential revision.');11}1213public function getMethodStatus() {14return self::METHOD_STATUS_FROZEN;15}1617public function getMethodStatusDescription() {18return pht(19'This method is frozen and will eventually be deprecated. New code '.20'should use "differential.revision.edit" instead.');21}2223protected function defineParamTypes() {24return array(25'revision_id' => 'required revisionid',26'message' => 'optional string',27'action' => 'optional string',28'silent' => 'optional bool',29'attach_inlines' => 'optional bool',30);31}3233protected function defineReturnType() {34return 'nonempty dict';35}3637protected function defineErrorTypes() {38return array(39'ERR_BAD_REVISION' => pht('Bad revision ID.'),40);41}4243protected function execute(ConduitAPIRequest $request) {44$viewer = $request->getUser();4546$revision = id(new DifferentialRevisionQuery())47->setViewer($viewer)48->withIDs(array($request->getValue('revision_id')))49->needReviewers(true)50->needReviewerAuthority(true)51->needActiveDiffs(true)52->executeOne();53if (!$revision) {54throw new ConduitException('ERR_BAD_REVISION');55}5657$xactions = array();5859$modular_map = array(60'accept' => DifferentialRevisionAcceptTransaction::TRANSACTIONTYPE,61'reject' => DifferentialRevisionRejectTransaction::TRANSACTIONTYPE,62'resign' => DifferentialRevisionResignTransaction::TRANSACTIONTYPE,63'request_review' =>64DifferentialRevisionRequestReviewTransaction::TRANSACTIONTYPE,65'rethink' => DifferentialRevisionPlanChangesTransaction::TRANSACTIONTYPE,66);6768$action = $request->getValue('action');69if (isset($modular_map[$action])) {70$xactions[] = id(new DifferentialTransaction())71->setTransactionType($modular_map[$action])72->setNewValue(true);73} else if ($action) {74switch ($action) {75case 'comment':76case 'none':77break;78default:79throw new Exception(80pht(81'Unsupported action "%s".',82$action));83break;84}85}8687$content = $request->getValue('message');88if (strlen($content)) {89$xactions[] = id(new DifferentialTransaction())90->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)91->attachComment(92id(new DifferentialTransactionComment())93->setContent($content));94}9596// NOTE: The legacy "attach_inlines" flag is now ignored and has no97// effect. See T13513.9899// NOTE: The legacy "silent" flag is now ignored and has no effect. See100// T13042.101102$editor = id(new DifferentialTransactionEditor())103->setActor($viewer)104->setContentSource($request->newContentSource())105->setContinueOnNoEffect(true)106->setContinueOnMissingFields(true);107108$editor->applyTransactions($revision, $xactions);109110return array(111'revisionid' => $revision->getID(),112'uri' => PhabricatorEnv::getURI('/D'.$revision->getID()),113);114}115116}117118119