Differential D12186 Diff 29293 src/applications/diffusion/controller/DiffusionInlineCommentController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionInlineCommentController.php
| <?php | <?php | ||||
| final class DiffusionInlineCommentController | final class DiffusionInlineCommentController | ||||
| extends PhabricatorInlineCommentController { | extends PhabricatorInlineCommentController { | ||||
| private $commitPHID; | private function getCommitPHID() { | ||||
| return $this->getRequest()->getURIData('phid'); | |||||
| public function willProcessRequest(array $data) { | |||||
| $this->commitPHID = $data['phid']; | |||||
| } | } | ||||
| protected function createComment() { | private function loadCommit() { | ||||
| $viewer = $this->getViewer(); | |||||
| $commit_phid = $this->getCommitPHID(); | |||||
| // Verify commit and path correspond to actual objects. | $commit = id(new DiffusionCommitQuery()) | ||||
| $commit_phid = $this->commitPHID; | ->setViewer($viewer) | ||||
| $path_id = $this->getChangesetID(); | ->withPHIDs(array($commit_phid)) | ||||
| ->executeOne(); | |||||
| $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( | |||||
| 'phid = %s', | |||||
| $commit_phid); | |||||
| if (!$commit) { | if (!$commit) { | ||||
| throw new Exception('Invalid commit ID!'); | throw new Exception(pht('Invalid commit PHID "%s"!', $commit_phid)); | ||||
| } | } | ||||
| // TODO: Write a real PathQuery object? | return $commit; | ||||
| } | |||||
| protected function createComment() { | |||||
| $commit = $this->loadCommit(); | |||||
| // TODO: Write a real PathQuery object? | |||||
| $path_id = $this->getChangesetID(); | |||||
| $path = queryfx_one( | $path = queryfx_one( | ||||
| id(new PhabricatorRepository())->establishConnection('r'), | id(new PhabricatorRepository())->establishConnection('r'), | ||||
| 'SELECT path FROM %T WHERE id = %d', | 'SELECT path FROM %T WHERE id = %d', | ||||
| PhabricatorRepository::TABLE_PATH, | PhabricatorRepository::TABLE_PATH, | ||||
| $path_id); | $path_id); | ||||
| if (!$path) { | if (!$path) { | ||||
| throw new Exception('Invalid path ID!'); | throw new Exception('Invalid path ID!'); | ||||
| } | } | ||||
| return id(new PhabricatorAuditInlineComment()) | return id(new PhabricatorAuditInlineComment()) | ||||
| ->setCommitPHID($commit_phid) | ->setCommitPHID($commit->getPHID()) | ||||
| ->setPathID($path_id); | ->setPathID($path_id); | ||||
| } | } | ||||
| protected function loadComment($id) { | protected function loadComment($id) { | ||||
| return PhabricatorAuditInlineComment::loadID($id); | return PhabricatorAuditInlineComment::loadID($id); | ||||
| } | } | ||||
| protected function loadCommentByPHID($phid) { | protected function loadCommentByPHID($phid) { | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | private function canEditInlineComment( | ||||
| } | } | ||||
| // Saved comments may not be edited. | // Saved comments may not be edited. | ||||
| if ($inline->getAuditCommentID()) { | if ($inline->getAuditCommentID()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| // Inline must be attached to the active revision. | // Inline must be attached to the active revision. | ||||
| if ($inline->getCommitPHID() != $this->commitPHID) { | if ($inline->getCommitPHID() != $this->getCommitPHID()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| protected function deleteComment(PhabricatorInlineCommentInterface $inline) { | protected function deleteComment(PhabricatorInlineCommentInterface $inline) { | ||||
| return $inline->delete(); | return $inline->delete(); | ||||
| } | } | ||||
| protected function saveComment(PhabricatorInlineCommentInterface $inline) { | protected function saveComment(PhabricatorInlineCommentInterface $inline) { | ||||
| return $inline->save(); | return $inline->save(); | ||||
| } | } | ||||
| protected function loadObjectOwnerPHID( | |||||
| PhabricatorInlineCommentInterface $inline) { | |||||
| return $this->loadCommit()->getAuthorPHID(); | |||||
| } | |||||
| } | } | ||||