[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/audit/controller/ -> PhabricatorAuditAddCommentController.php (source)

   1  <?php
   2  
   3  final class PhabricatorAuditAddCommentController
   4    extends PhabricatorAuditController {
   5  
   6    public function processRequest() {
   7      $request = $this->getRequest();
   8      $user = $request->getUser();
   9  
  10      if (!$request->isFormPost()) {
  11        return new Aphront403Response();
  12      }
  13  
  14      $commit_phid = $request->getStr('commit');
  15      $commit = id(new DiffusionCommitQuery())
  16        ->setViewer($user)
  17        ->withPHIDs(array($commit_phid))
  18        ->needAuditRequests(true)
  19        ->executeOne();
  20      if (!$commit) {
  21        return new Aphront404Response();
  22      }
  23  
  24      $xactions = array();
  25  
  26      // make sure we only add auditors or ccs if the action matches
  27      $action = $request->getStr('action');
  28      switch ($action) {
  29        case PhabricatorAuditActionConstants::ADD_AUDITORS:
  30          $auditors = $request->getArr('auditors');
  31          $xactions[] = id(new PhabricatorAuditTransaction())
  32            ->setTransactionType(PhabricatorAuditActionConstants::ADD_AUDITORS)
  33            ->setNewValue(array_fuse($auditors));
  34          break;
  35        case PhabricatorAuditActionConstants::ADD_CCS:
  36          $xactions[] = id(new PhabricatorAuditTransaction())
  37            ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
  38            ->setNewValue(
  39              array(
  40                '+' => $request->getArr('ccs'),
  41              ));
  42          break;
  43        case PhabricatorAuditActionConstants::COMMENT:
  44          // We'll deal with this below.
  45          break;
  46        default:
  47          $xactions[] = id(new PhabricatorAuditTransaction())
  48            ->setTransactionType(PhabricatorAuditActionConstants::ACTION)
  49            ->setNewValue($action);
  50          break;
  51      }
  52  
  53      $content = $request->getStr('content');
  54      if (strlen($content)) {
  55        $xactions[] = id(new PhabricatorAuditTransaction())
  56          ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
  57          ->attachComment(
  58            id(new PhabricatorAuditTransactionComment())
  59              ->setCommitPHID($commit->getPHID())
  60              ->setContent($content));
  61      }
  62  
  63      $inlines = PhabricatorAuditInlineComment::loadDraftComments(
  64        $user,
  65        $commit->getPHID());
  66      foreach ($inlines as $inline) {
  67        $xactions[] = id(new PhabricatorAuditTransaction())
  68          ->setTransactionType(PhabricatorAuditActionConstants::INLINE)
  69          ->attachComment($inline->getTransactionComment());
  70      }
  71  
  72      id(new PhabricatorAuditEditor())
  73        ->setActor($user)
  74        ->setContentSourceFromRequest($request)
  75        ->setContinueOnMissingFields(true)
  76        ->applyTransactions($commit, $xactions);
  77  
  78      $draft = id(new PhabricatorDraft())->loadOneWhere(
  79        'authorPHID = %s AND draftKey = %s',
  80        $user->getPHID(),
  81        'diffusion-audit-'.$commit->getID());
  82      if ($draft) {
  83        $draft->delete();
  84      }
  85  
  86      $monogram = $commit->getRepository()->getMonogram();
  87      $identifier = $commit->getCommitIdentifier();
  88      $uri = '/'.$monogram.$identifier;
  89  
  90      return id(new AphrontRedirectResponse())->setURI($uri);
  91    }
  92  
  93  }


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