Differential D12186 Diff 29293 src/applications/differential/controller/DifferentialInlineCommentEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/controller/DifferentialInlineCommentEditController.php
| <?php | <?php | ||||
| final class DifferentialInlineCommentEditController | final class DifferentialInlineCommentEditController | ||||
| extends PhabricatorInlineCommentController { | extends PhabricatorInlineCommentController { | ||||
| private $revisionID; | private function getRevisionID() { | ||||
| return $this->getRequest()->getURIData('id'); | |||||
| public function willProcessRequest(array $data) { | |||||
| $this->revisionID = $data['id']; | |||||
| } | } | ||||
| protected function createComment() { | private function loadRevision() { | ||||
| $viewer = $this->getViewer(); | |||||
| // Verify revision and changeset correspond to actual objects. | $revision_id = $this->getRevisionID(); | ||||
| $revision_id = $this->revisionID; | |||||
| $changeset_id = $this->getChangesetID(); | |||||
| $viewer = $this->getRequest()->getUser(); | |||||
| $revision = id(new DifferentialRevisionQuery()) | $revision = id(new DifferentialRevisionQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withIDs(array($revision_id)) | ->withIDs(array($revision_id)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$revision) { | if (!$revision) { | ||||
| throw new Exception('Invalid revision ID!'); | throw new Exception(pht('Invalid revision ID "%s".', $revision_id)); | ||||
| } | |||||
| return $revision; | |||||
| } | } | ||||
| protected function createComment() { | |||||
| // Verify revision and changeset correspond to actual objects. | |||||
| $changeset_id = $this->getChangesetID(); | |||||
| $revision = $this->loadRevision(); | |||||
| if (!id(new DifferentialChangeset())->load($changeset_id)) { | if (!id(new DifferentialChangeset())->load($changeset_id)) { | ||||
| throw new Exception('Invalid changeset ID!'); | throw new Exception('Invalid changeset ID!'); | ||||
| } | } | ||||
| return id(new DifferentialInlineComment()) | return id(new DifferentialInlineComment()) | ||||
| ->setRevision($revision) | ->setRevision($revision) | ||||
| ->setChangesetID($changeset_id); | ->setChangesetID($changeset_id); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | private function canEditInlineComment( | ||||
| // Saved comments may not be edited, for now, although the schema now | // Saved comments may not be edited, for now, although the schema now | ||||
| // supports it. | // supports it. | ||||
| if (!$inline->isDraft()) { | if (!$inline->isDraft()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| // Inline must be attached to the active revision. | // Inline must be attached to the active revision. | ||||
| if ($inline->getRevisionID() != $this->revisionID) { | if ($inline->getRevisionID() != $this->getRevisionID()) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| protected function deleteComment(PhabricatorInlineCommentInterface $inline) { | protected function deleteComment(PhabricatorInlineCommentInterface $inline) { | ||||
| $inline->openTransaction(); | $inline->openTransaction(); | ||||
| Show All 9 Lines | protected function saveComment(PhabricatorInlineCommentInterface $inline) { | ||||
| $inline->openTransaction(); | $inline->openTransaction(); | ||||
| $inline->save(); | $inline->save(); | ||||
| DifferentialDraft::markHasDraft( | DifferentialDraft::markHasDraft( | ||||
| $inline->getAuthorPHID(), | $inline->getAuthorPHID(), | ||||
| $inline->getRevisionPHID(), | $inline->getRevisionPHID(), | ||||
| $inline->getPHID()); | $inline->getPHID()); | ||||
| $inline->saveTransaction(); | $inline->saveTransaction(); | ||||
| } | } | ||||
| protected function loadObjectOwnerPHID( | |||||
| PhabricatorInlineCommentInterface $inline) { | |||||
| return $this->loadRevision()->getAuthorPHID(); | |||||
| } | |||||
| } | } | ||||