[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/controller/ -> DifferentialInlineCommentEditController.php (source)

   1  <?php
   2  
   3  final class DifferentialInlineCommentEditController
   4    extends PhabricatorInlineCommentController {
   5  
   6    private $revisionID;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->revisionID = $data['id'];
  10    }
  11  
  12    protected function createComment() {
  13  
  14      // Verify revision and changeset correspond to actual objects.
  15      $revision_id = $this->revisionID;
  16      $changeset_id = $this->getChangesetID();
  17  
  18      $viewer = $this->getRequest()->getUser();
  19      $revision = id(new DifferentialRevisionQuery())
  20        ->setViewer($viewer)
  21        ->withIDs(array($revision_id))
  22        ->executeOne();
  23  
  24      if (!$revision) {
  25        throw new Exception('Invalid revision ID!');
  26      }
  27  
  28      if (!id(new DifferentialChangeset())->load($changeset_id)) {
  29        throw new Exception('Invalid changeset ID!');
  30      }
  31  
  32      return id(new DifferentialInlineComment())
  33        ->setRevision($revision)
  34        ->setChangesetID($changeset_id);
  35    }
  36  
  37    protected function loadComment($id) {
  38      return id(new DifferentialInlineCommentQuery())
  39        ->withIDs(array($id))
  40        ->executeOne();
  41    }
  42  
  43    protected function loadCommentForEdit($id) {
  44      $request = $this->getRequest();
  45      $user = $request->getUser();
  46  
  47      $inline = $this->loadComment($id);
  48      if (!$this->canEditInlineComment($user, $inline)) {
  49        throw new Exception('That comment is not editable!');
  50      }
  51      return $inline;
  52    }
  53  
  54    private function canEditInlineComment(
  55      PhabricatorUser $user,
  56      DifferentialInlineComment $inline) {
  57  
  58      // Only the author may edit a comment.
  59      if ($inline->getAuthorPHID() != $user->getPHID()) {
  60        return false;
  61      }
  62  
  63      // Saved comments may not be edited, for now, although the schema now
  64      // supports it.
  65      if (!$inline->isDraft()) {
  66        return false;
  67      }
  68  
  69      // Inline must be attached to the active revision.
  70      if ($inline->getRevisionID() != $this->revisionID) {
  71        return false;
  72      }
  73  
  74      return true;
  75    }
  76  
  77    protected function deleteComment(PhabricatorInlineCommentInterface $inline) {
  78      $inline->openTransaction();
  79        DifferentialDraft::deleteHasDraft(
  80          $inline->getAuthorPHID(),
  81          $inline->getRevisionPHID(),
  82          $inline->getPHID());
  83        $inline->delete();
  84      $inline->saveTransaction();
  85    }
  86  
  87    protected function saveComment(PhabricatorInlineCommentInterface $inline) {
  88      $inline->openTransaction();
  89        $inline->save();
  90        DifferentialDraft::markHasDraft(
  91          $inline->getAuthorPHID(),
  92          $inline->getRevisionPHID(),
  93          $inline->getPHID());
  94      $inline->saveTransaction();
  95    }
  96  }


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