Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit af5b94b

Browse files
author
epriestley
committed
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
1 parent 949b916 commit af5b94b

File tree

3 files changed

+70
-83
lines changed

3 files changed

+70
-83
lines changed

src/applications/differential/controller/DifferentialInlineCommentEditController.php

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
final class DifferentialInlineCommentEditController
44
extends PhabricatorInlineCommentController {
55

6+
protected function newInlineCommentQuery() {
7+
return new DifferentialDiffInlineCommentQuery();
8+
}
9+
610
private function getRevisionID() {
711
return $this->getRequest()->getURIData('id');
812
}
@@ -58,44 +62,10 @@ protected function createComment() {
5862
->setChangesetID($changeset_id);
5963
}
6064

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-
9565
protected function loadCommentForDone($id) {
9666
$viewer = $this->getViewer();
9767

98-
$inline = $this->loadComment($id);
68+
$inline = $this->loadCommentByID($id);
9969
if (!$inline) {
10070
throw new Exception(pht('Unable to load inline "%d".', $id));
10171
}
@@ -144,7 +114,7 @@ protected function loadCommentForDone($id) {
144114
return $inline;
145115
}
146116

147-
private function canEditInlineComment(
117+
protected function canEditInlineComment(
148118
PhabricatorUser $viewer,
149119
DifferentialInlineComment $inline) {
150120

src/applications/diffusion/controller/DiffusionInlineCommentController.php

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
final class DiffusionInlineCommentController
44
extends PhabricatorInlineCommentController {
55

6+
protected function newInlineCommentQuery() {
7+
return new DiffusionDiffInlineCommentQuery();
8+
}
9+
610
private function getCommitPHID() {
711
return $this->getRequest()->getURIData('phid');
812
}
@@ -41,48 +45,10 @@ protected function createComment() {
4145
->setPathID($path_id);
4246
}
4347

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-
8248
protected function loadCommentForDone($id) {
8349
$viewer = $this->getViewer();
8450

85-
$inline = $this->loadComment($id);
51+
$inline = $this->loadCommentByID($id);
8652
if (!$inline) {
8753
throw new Exception(pht('Failed to load comment "%d".', $id));
8854
}
@@ -115,7 +81,7 @@ protected function loadCommentForDone($id) {
11581
return $inline;
11682
}
11783

118-
private function canEditInlineComment(
84+
protected function canEditInlineComment(
11985
PhabricatorUser $viewer,
12086
PhabricatorAuditInlineComment $inline) {
12187

src/infrastructure/diff/PhabricatorInlineCommentController.php

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ abstract class PhabricatorInlineCommentController
44
extends PhabricatorController {
55

66
abstract protected function createComment();
7-
abstract protected function loadComment($id);
8-
abstract protected function loadCommentForEdit($id);
7+
abstract protected function newInlineCommentQuery();
98
abstract protected function loadCommentForDone($id);
10-
abstract protected function loadCommentByPHID($phid);
119
abstract protected function loadObjectOwnerPHID(
1210
PhabricatorInlineComment $inline);
1311
abstract protected function deleteComment(
@@ -172,7 +170,7 @@ public function processRequest() {
172170

173171
$is_delete = ($op == 'delete' || $op == 'refdelete');
174172

175-
$inline = $this->loadCommentForEdit($this->getCommentID());
173+
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
176174

177175
if ($is_delete) {
178176
$this->deleteComment($inline);
@@ -182,7 +180,7 @@ public function processRequest() {
182180

183181
return $this->buildEmptyResponse();
184182
case 'edit':
185-
$inline = $this->loadCommentForEdit($this->getCommentID());
183+
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
186184
$text = $this->getCommentText();
187185

188186
if ($request->isFormPost()) {
@@ -228,7 +226,7 @@ public function processRequest() {
228226

229227
return $this->newInlineResponse($inline, $view);
230228
case 'cancel':
231-
$inline = $this->loadCommentForEdit($this->getCommentID());
229+
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
232230

233231
$inline->setIsEditing(false);
234232

@@ -251,7 +249,7 @@ public function processRequest() {
251249

252250
return $this->buildEmptyResponse();
253251
case 'draft':
254-
$inline = $this->loadCommentForEdit($this->getCommentID());
252+
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
255253

256254
$versioned_draft = PhabricatorVersionedDraft::loadOrCreateDraft(
257255
$inline->getPHID(),
@@ -442,5 +440,58 @@ private function purgeVersionedDrafts(
442440
$viewer->getPHID());
443441
}
444442

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+
}
445496

446497
}

0 commit comments

Comments
 (0)