@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Lift most "InlineController" querying to the base class

Summary: Ref T13513. Move querying to "DiffInlineCommentQuery" classes and lift them into the base Controller.

Test Plan: In Differential and Diffusion, created, edited, and submitted inline comments.

Maniphest Tasks: T13513

Differential Revision: https://secure.phabricator.com/D21231

+70 -83
+6 -36
src/applications/differential/controller/DifferentialInlineCommentEditController.php
··· 3 3 final class DifferentialInlineCommentEditController 4 4 extends PhabricatorInlineCommentController { 5 5 6 + protected function newInlineCommentQuery() { 7 + return new DifferentialDiffInlineCommentQuery(); 8 + } 9 + 6 10 private function getRevisionID() { 7 11 return $this->getRequest()->getURIData('id'); 8 12 } ··· 58 62 ->setChangesetID($changeset_id); 59 63 } 60 64 61 - protected function loadComment($id) { 62 - return id(new DifferentialInlineCommentQuery()) 63 - ->setViewer($this->getViewer()) 64 - ->withIDs(array($id)) 65 - ->withDeletedDrafts(true) 66 - ->needHidden(true) 67 - ->executeOne(); 68 - } 69 - 70 - protected function loadCommentByPHID($phid) { 71 - return id(new DifferentialInlineCommentQuery()) 72 - ->setViewer($this->getViewer()) 73 - ->withPHIDs(array($phid)) 74 - ->withDeletedDrafts(true) 75 - ->needHidden(true) 76 - ->executeOne(); 77 - } 78 - 79 - protected function loadCommentForEdit($id) { 80 - $viewer = $this->getViewer(); 81 - 82 - $inline = $this->loadComment($id); 83 - if (!$inline) { 84 - throw new Exception( 85 - pht('Unable to load inline "%s".', $id)); 86 - } 87 - 88 - if (!$this->canEditInlineComment($viewer, $inline)) { 89 - throw new Exception(pht('That comment is not editable!')); 90 - } 91 - 92 - return $inline; 93 - } 94 - 95 65 protected function loadCommentForDone($id) { 96 66 $viewer = $this->getViewer(); 97 67 98 - $inline = $this->loadComment($id); 68 + $inline = $this->loadCommentByID($id); 99 69 if (!$inline) { 100 70 throw new Exception(pht('Unable to load inline "%d".', $id)); 101 71 } ··· 144 114 return $inline; 145 115 } 146 116 147 - private function canEditInlineComment( 117 + protected function canEditInlineComment( 148 118 PhabricatorUser $viewer, 149 119 DifferentialInlineComment $inline) { 150 120
+6 -40
src/applications/diffusion/controller/DiffusionInlineCommentController.php
··· 3 3 final class DiffusionInlineCommentController 4 4 extends PhabricatorInlineCommentController { 5 5 6 + protected function newInlineCommentQuery() { 7 + return new DiffusionDiffInlineCommentQuery(); 8 + } 9 + 6 10 private function getCommitPHID() { 7 11 return $this->getRequest()->getURIData('phid'); 8 12 } ··· 41 45 ->setPathID($path_id); 42 46 } 43 47 44 - protected function loadComment($id) { 45 - $viewer = $this->getViewer(); 46 - $inline = id(new DiffusionDiffInlineCommentQuery()) 47 - ->setViewer($viewer) 48 - ->withIDs(array($id)) 49 - ->executeOne(); 50 - 51 - if ($inline) { 52 - $inline = $inline->newInlineCommentObject(); 53 - } 54 - 55 - return $inline; 56 - } 57 - 58 - protected function loadCommentByPHID($phid) { 59 - $viewer = $this->getViewer(); 60 - $inline = id(new DiffusionDiffInlineCommentQuery()) 61 - ->setViewer($viewer) 62 - ->withPHIDs(array($phid)) 63 - ->executeOne(); 64 - 65 - if ($inline) { 66 - $inline = $inline->newInlineCommentObject(); 67 - } 68 - 69 - return $inline; 70 - } 71 - 72 - protected function loadCommentForEdit($id) { 73 - $viewer = $this->getViewer(); 74 - 75 - $inline = $this->loadComment($id); 76 - if (!$this->canEditInlineComment($viewer, $inline)) { 77 - throw new Exception(pht('That comment is not editable!')); 78 - } 79 - return $inline; 80 - } 81 - 82 48 protected function loadCommentForDone($id) { 83 49 $viewer = $this->getViewer(); 84 50 85 - $inline = $this->loadComment($id); 51 + $inline = $this->loadCommentByID($id); 86 52 if (!$inline) { 87 53 throw new Exception(pht('Failed to load comment "%d".', $id)); 88 54 } ··· 115 81 return $inline; 116 82 } 117 83 118 - private function canEditInlineComment( 84 + protected function canEditInlineComment( 119 85 PhabricatorUser $viewer, 120 86 PhabricatorAuditInlineComment $inline) { 121 87
+58 -7
src/infrastructure/diff/PhabricatorInlineCommentController.php
··· 4 4 extends PhabricatorController { 5 5 6 6 abstract protected function createComment(); 7 - abstract protected function loadComment($id); 8 - abstract protected function loadCommentForEdit($id); 7 + abstract protected function newInlineCommentQuery(); 9 8 abstract protected function loadCommentForDone($id); 10 - abstract protected function loadCommentByPHID($phid); 11 9 abstract protected function loadObjectOwnerPHID( 12 10 PhabricatorInlineComment $inline); 13 11 abstract protected function deleteComment( ··· 172 170 173 171 $is_delete = ($op == 'delete' || $op == 'refdelete'); 174 172 175 - $inline = $this->loadCommentForEdit($this->getCommentID()); 173 + $inline = $this->loadCommentByIDForEdit($this->getCommentID()); 176 174 177 175 if ($is_delete) { 178 176 $this->deleteComment($inline); ··· 182 180 183 181 return $this->buildEmptyResponse(); 184 182 case 'edit': 185 - $inline = $this->loadCommentForEdit($this->getCommentID()); 183 + $inline = $this->loadCommentByIDForEdit($this->getCommentID()); 186 184 $text = $this->getCommentText(); 187 185 188 186 if ($request->isFormPost()) { ··· 228 226 229 227 return $this->newInlineResponse($inline, $view); 230 228 case 'cancel': 231 - $inline = $this->loadCommentForEdit($this->getCommentID()); 229 + $inline = $this->loadCommentByIDForEdit($this->getCommentID()); 232 230 233 231 $inline->setIsEditing(false); 234 232 ··· 251 249 252 250 return $this->buildEmptyResponse(); 253 251 case 'draft': 254 - $inline = $this->loadCommentForEdit($this->getCommentID()); 252 + $inline = $this->loadCommentByIDForEdit($this->getCommentID()); 255 253 256 254 $versioned_draft = PhabricatorVersionedDraft::loadOrCreateDraft( 257 255 $inline->getPHID(), ··· 442 440 $viewer->getPHID()); 443 441 } 444 442 443 + final protected function loadCommentByID($id) { 444 + $query = $this->newInlineCommentQuery() 445 + ->withIDs(array($id)); 446 + 447 + return $this->loadCommentByQuery($query); 448 + } 449 + 450 + final protected function loadCommentByPHID($phid) { 451 + $query = $this->newInlineCommentQuery() 452 + ->withPHIDs(array($phid)); 453 + 454 + return $this->loadCommentByQuery($query); 455 + } 456 + 457 + final protected function loadCommentByIDForEdit($id) { 458 + $viewer = $this->getViewer(); 459 + 460 + $query = $this->newInlineCommentQuery() 461 + ->withIDs(array($id)); 462 + 463 + $inline = $this->loadCommentByQuery($query); 464 + 465 + if (!$inline) { 466 + throw new Exception( 467 + pht( 468 + 'Unable to load inline "%s".', 469 + $id)); 470 + } 471 + 472 + if (!$this->canEditInlineComment($viewer, $inline)) { 473 + throw new Exception( 474 + pht( 475 + 'Inline comment "%s" is not editable.', 476 + $id)); 477 + } 478 + 479 + return $inline; 480 + } 481 + 482 + private function loadCommentByQuery( 483 + PhabricatorDiffInlineCommentQuery $query) { 484 + $viewer = $this->getViewer(); 485 + 486 + $inline = $query 487 + ->setViewer($viewer) 488 + ->executeOne(); 489 + 490 + if ($inline) { 491 + $inline = $inline->newInlineCommentObject(); 492 + } 493 + 494 + return $inline; 495 + } 445 496 446 497 }