Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/PhabricatorInlineCommentController.php
<?php | <?php | ||||
abstract class PhabricatorInlineCommentController | abstract class PhabricatorInlineCommentController | ||||
extends PhabricatorController { | extends PhabricatorController { | ||||
abstract protected function createComment(); | abstract protected function createComment(); | ||||
abstract protected function loadComment($id); | abstract protected function newInlineCommentQuery(); | ||||
abstract protected function loadCommentForEdit($id); | |||||
abstract protected function loadCommentForDone($id); | abstract protected function loadCommentForDone($id); | ||||
abstract protected function loadCommentByPHID($phid); | |||||
abstract protected function loadObjectOwnerPHID( | abstract protected function loadObjectOwnerPHID( | ||||
PhabricatorInlineComment $inline); | PhabricatorInlineComment $inline); | ||||
abstract protected function deleteComment( | abstract protected function deleteComment( | ||||
PhabricatorInlineComment $inline); | PhabricatorInlineComment $inline); | ||||
abstract protected function undeleteComment( | abstract protected function undeleteComment( | ||||
PhabricatorInlineComment $inline); | PhabricatorInlineComment $inline); | ||||
abstract protected function saveComment( | abstract protected function saveComment( | ||||
PhabricatorInlineComment $inline); | PhabricatorInlineComment $inline); | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | switch ($op) { | ||||
->appendParagraph(pht('Delete this inline comment?')) | ->appendParagraph(pht('Delete this inline comment?')) | ||||
->addCancelButton('#') | ->addCancelButton('#') | ||||
->addSubmitButton(pht('Delete')); | ->addSubmitButton(pht('Delete')); | ||||
} | } | ||||
} | } | ||||
$is_delete = ($op == 'delete' || $op == 'refdelete'); | $is_delete = ($op == 'delete' || $op == 'refdelete'); | ||||
$inline = $this->loadCommentForEdit($this->getCommentID()); | $inline = $this->loadCommentByIDForEdit($this->getCommentID()); | ||||
if ($is_delete) { | if ($is_delete) { | ||||
$this->deleteComment($inline); | $this->deleteComment($inline); | ||||
} else { | } else { | ||||
$this->undeleteComment($inline); | $this->undeleteComment($inline); | ||||
} | } | ||||
return $this->buildEmptyResponse(); | return $this->buildEmptyResponse(); | ||||
case 'edit': | case 'edit': | ||||
$inline = $this->loadCommentForEdit($this->getCommentID()); | $inline = $this->loadCommentByIDForEdit($this->getCommentID()); | ||||
$text = $this->getCommentText(); | $text = $this->getCommentText(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
if (strlen($text)) { | if (strlen($text)) { | ||||
$inline | $inline | ||||
->setContent($text) | ->setContent($text) | ||||
->setIsEditing(false); | ->setIsEditing(false); | ||||
Show All 29 Lines | switch ($op) { | ||||
$edit_dialog = $this->buildEditDialog($inline) | $edit_dialog = $this->buildEditDialog($inline) | ||||
->setTitle(pht('Edit Inline Comment')); | ->setTitle(pht('Edit Inline Comment')); | ||||
$view = $this->buildScaffoldForView($edit_dialog); | $view = $this->buildScaffoldForView($edit_dialog); | ||||
return $this->newInlineResponse($inline, $view); | return $this->newInlineResponse($inline, $view); | ||||
case 'cancel': | case 'cancel': | ||||
$inline = $this->loadCommentForEdit($this->getCommentID()); | $inline = $this->loadCommentByIDForEdit($this->getCommentID()); | ||||
$inline->setIsEditing(false); | $inline->setIsEditing(false); | ||||
// If the user uses "Undo" to get into an edited state ("AB"), then | // If the user uses "Undo" to get into an edited state ("AB"), then | ||||
// clicks cancel to return to the previous state ("A"), we also want | // clicks cancel to return to the previous state ("A"), we also want | ||||
// to set the stored state back to "A". | // to set the stored state back to "A". | ||||
$text = $this->getCommentText(); | $text = $this->getCommentText(); | ||||
if (strlen($text)) { | if (strlen($text)) { | ||||
$inline->setContent($text); | $inline->setContent($text); | ||||
} | } | ||||
$content = $inline->getContent(); | $content = $inline->getContent(); | ||||
if (!strlen($content)) { | if (!strlen($content)) { | ||||
$this->deleteComment($inline); | $this->deleteComment($inline); | ||||
} else { | } else { | ||||
$this->saveComment($inline); | $this->saveComment($inline); | ||||
} | } | ||||
$this->purgeVersionedDrafts($inline); | $this->purgeVersionedDrafts($inline); | ||||
return $this->buildEmptyResponse(); | return $this->buildEmptyResponse(); | ||||
case 'draft': | case 'draft': | ||||
$inline = $this->loadCommentForEdit($this->getCommentID()); | $inline = $this->loadCommentByIDForEdit($this->getCommentID()); | ||||
$versioned_draft = PhabricatorVersionedDraft::loadOrCreateDraft( | $versioned_draft = PhabricatorVersionedDraft::loadOrCreateDraft( | ||||
$inline->getPHID(), | $inline->getPHID(), | ||||
$viewer->getPHID(), | $viewer->getPHID(), | ||||
$inline->getID()); | $inline->getID()); | ||||
$text = $this->getCommentText(); | $text = $this->getCommentText(); | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | abstract class PhabricatorInlineCommentController | ||||
private function purgeVersionedDrafts( | private function purgeVersionedDrafts( | ||||
PhabricatorInlineComment $inline) { | PhabricatorInlineComment $inline) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
PhabricatorVersionedDraft::purgeDrafts( | PhabricatorVersionedDraft::purgeDrafts( | ||||
$inline->getPHID(), | $inline->getPHID(), | ||||
$viewer->getPHID()); | $viewer->getPHID()); | ||||
} | } | ||||
final protected function loadCommentByID($id) { | |||||
$query = $this->newInlineCommentQuery() | |||||
->withIDs(array($id)); | |||||
return $this->loadCommentByQuery($query); | |||||
} | |||||
final protected function loadCommentByPHID($phid) { | |||||
$query = $this->newInlineCommentQuery() | |||||
->withPHIDs(array($phid)); | |||||
return $this->loadCommentByQuery($query); | |||||
} | |||||
final protected function loadCommentByIDForEdit($id) { | |||||
$viewer = $this->getViewer(); | |||||
$query = $this->newInlineCommentQuery() | |||||
->withIDs(array($id)); | |||||
$inline = $this->loadCommentByQuery($query); | |||||
if (!$inline) { | |||||
throw new Exception( | |||||
pht( | |||||
'Unable to load inline "%s".', | |||||
$id)); | |||||
} | |||||
if (!$this->canEditInlineComment($viewer, $inline)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Inline comment "%s" is not editable.', | |||||
$id)); | |||||
} | |||||
return $inline; | |||||
} | |||||
private function loadCommentByQuery( | |||||
PhabricatorDiffInlineCommentQuery $query) { | |||||
$viewer = $this->getViewer(); | |||||
$inline = $query | |||||
->setViewer($viewer) | |||||
->executeOne(); | |||||
if ($inline) { | |||||
$inline = $inline->newInlineCommentObject(); | |||||
} | |||||
return $inline; | |||||
} | |||||
} | } |