@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.

Remove "DifferentialInlineCommentQuery"

Summary: Ref T13513. Replaces "DifferentialInlineCommentQuery" with the similar but more modern "DifferentialDiffInlineCommentQuery".

Test Plan: Viewed comments in timeline, changesets. Created, edited, and submitted comments. Hid and un-hid comments, reloading (saw state preserved).

Maniphest Tasks: T13513

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

+133 -175
+2 -2
src/__phutil_library_map__.php
··· 561 561 'DifferentialInlineComment' => 'applications/differential/storage/DifferentialInlineComment.php', 562 562 'DifferentialInlineCommentEditController' => 'applications/differential/controller/DifferentialInlineCommentEditController.php', 563 563 'DifferentialInlineCommentMailView' => 'applications/differential/mail/DifferentialInlineCommentMailView.php', 564 - 'DifferentialInlineCommentQuery' => 'applications/differential/query/DifferentialInlineCommentQuery.php', 565 564 'DifferentialJIRAIssuesCommitMessageField' => 'applications/differential/field/DifferentialJIRAIssuesCommitMessageField.php', 566 565 'DifferentialJIRAIssuesField' => 'applications/differential/customfield/DifferentialJIRAIssuesField.php', 567 566 'DifferentialLegacyQuery' => 'applications/differential/constants/DifferentialLegacyQuery.php', ··· 3592 3591 'PhabricatorIndexableInterface' => 'applications/search/interface/PhabricatorIndexableInterface.php', 3593 3592 'PhabricatorInfrastructureTestCase' => '__tests__/PhabricatorInfrastructureTestCase.php', 3594 3593 'PhabricatorInlineComment' => 'infrastructure/diff/interface/PhabricatorInlineComment.php', 3594 + 'PhabricatorInlineCommentAdjustmentEngine' => 'infrastructure/diff/engine/PhabricatorInlineCommentAdjustmentEngine.php', 3595 3595 'PhabricatorInlineCommentController' => 'infrastructure/diff/PhabricatorInlineCommentController.php', 3596 3596 'PhabricatorInlineCommentInterface' => 'applications/transactions/interface/PhabricatorInlineCommentInterface.php', 3597 3597 'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php', ··· 6626 6626 'DifferentialInlineComment' => 'PhabricatorInlineComment', 6627 6627 'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController', 6628 6628 'DifferentialInlineCommentMailView' => 'DifferentialMailView', 6629 - 'DifferentialInlineCommentQuery' => 'PhabricatorOffsetPagedQuery', 6630 6629 'DifferentialJIRAIssuesCommitMessageField' => 'DifferentialCommitMessageCustomField', 6631 6630 'DifferentialJIRAIssuesField' => 'DifferentialStoredCustomField', 6632 6631 'DifferentialLegacyQuery' => 'Phobject', ··· 10118 10117 'Phobject', 10119 10118 'PhabricatorMarkupInterface', 10120 10119 ), 10120 + 'PhabricatorInlineCommentAdjustmentEngine' => 'Phobject', 10121 10121 'PhabricatorInlineCommentController' => 'PhabricatorController', 10122 10122 'PhabricatorInlineSummaryView' => 'AphrontView', 10123 10123 'PhabricatorInstructionsEditField' => 'PhabricatorEditField',
+15 -8
src/applications/differential/controller/DifferentialChangesetViewController.php
··· 194 194 195 195 // Load both left-side and right-side inline comments. 196 196 if ($revision) { 197 - $query = id(new DifferentialInlineCommentQuery()) 197 + $inlines = id(new DifferentialDiffInlineCommentQuery()) 198 198 ->setViewer($viewer) 199 + ->withRevisionPHIDs(array($revision->getPHID())) 200 + ->withPublishableComments(true) 201 + ->withPublishedComments(true) 199 202 ->needHidden(true) 200 - ->withRevisionPHIDs(array($revision->getPHID())); 201 - $inlines = $query->execute(); 202 - $inlines = $query->adjustInlinesForChangesets( 203 - $inlines, 204 - $old, 205 - $new, 206 - $revision); 203 + ->execute(); 204 + 205 + $inlines = mpull($inlines, 'newInlineCommentObject'); 206 + 207 + $inlines = id(new PhabricatorInlineCommentAdjustmentEngine()) 208 + ->setViewer($viewer) 209 + ->setRevision($revision) 210 + ->setOldChangesets($old) 211 + ->setNewChangesets($new) 212 + ->setInlines($inlines) 213 + ->execute(); 207 214 } else { 208 215 $inlines = array(); 209 216 }
+13 -9
src/applications/differential/controller/DifferentialRevisionViewController.php
··· 227 227 $old = array_select_keys($changesets, $old_ids); 228 228 $new = array_select_keys($changesets, $new_ids); 229 229 230 - $query = id(new DifferentialInlineCommentQuery()) 230 + $inlines = id(new DifferentialDiffInlineCommentQuery()) 231 231 ->setViewer($viewer) 232 - ->needHidden(true) 233 - ->withRevisionPHIDs(array($revision->getPHID())); 234 - $inlines = $query->execute(); 235 - $inlines = $query->adjustInlinesForChangesets( 236 - $inlines, 237 - $old, 238 - $new, 239 - $revision); 232 + ->withRevisionPHIDs(array($revision->getPHID())) 233 + ->withPublishableComments(true) 234 + ->withPublishedComments(true) 235 + ->execute(); 236 + 237 + $inlines = id(new PhabricatorInlineCommentAdjustmentEngine()) 238 + ->setViewer($viewer) 239 + ->setRevision($revision) 240 + ->setOldChangesets($old) 241 + ->setNewChangesets($new) 242 + ->setInlines($inlines) 243 + ->execute(); 240 244 241 245 foreach ($inlines as $inline) { 242 246 $changeset_id = $inline->getChangesetID();
+11 -11
src/applications/differential/engine/DifferentialRevisionTimelineEngine.php
··· 50 50 } 51 51 52 52 foreach ($inlines as $key => $inline) { 53 - $inlines[$key] = DifferentialInlineComment::newFromModernComment( 54 - $inline); 53 + $inlines[$key] = $inline->newInlineCommentObject(); 55 54 } 56 55 57 - $query = id(new DifferentialInlineCommentQuery()) 58 - ->needHidden(true) 59 - ->setViewer($viewer); 60 - 61 56 // NOTE: This is a bit sketchy: this method adjusts the inlines as a 62 57 // side effect, which means it will ultimately adjust the transaction 63 58 // comments and affect timeline rendering. 64 - $query->adjustInlinesForChangesets( 65 - $inlines, 66 - array_select_keys($changesets, $old_ids), 67 - array_select_keys($changesets, $new_ids), 68 - $revision); 59 + 60 + $old = array_select_keys($changesets, $old_ids); 61 + $new = array_select_keys($changesets, $new_ids); 62 + id(new PhabricatorInlineCommentAdjustmentEngine()) 63 + ->setViewer($viewer) 64 + ->setRevision($revision) 65 + ->setOldChangesets($old) 66 + ->setNewChangesets($new) 67 + ->setInlines($inlines) 68 + ->execute(); 69 69 70 70 return id(new DifferentialTransactionView()) 71 71 ->setViewData($view_data)
+22
src/applications/differential/query/DifferentialDiffInlineCommentQuery.php
··· 45 45 return $where; 46 46 } 47 47 48 + protected function loadHiddenCommentIDs( 49 + $viewer_phid, 50 + array $comments) { 51 + 52 + $table = new DifferentialHiddenComment(); 53 + $conn = $table->establishConnection('r'); 54 + 55 + $rows = queryfx_all( 56 + $conn, 57 + 'SELECT commentID FROM %R 58 + WHERE userPHID = %s 59 + AND commentID IN (%Ld)', 60 + $table, 61 + $viewer_phid, 62 + mpull($comments, 'getID')); 63 + 64 + $id_map = ipull($rows, 'commentID'); 65 + $id_map = array_fuse($id_map); 66 + 67 + return $id_map; 68 + } 69 + 48 70 }
+30 -141
src/applications/differential/query/DifferentialInlineCommentQuery.php src/infrastructure/diff/engine/PhabricatorInlineCommentAdjustmentEngine.php
··· 1 1 <?php 2 2 3 - /** 4 - * Temporary wrapper for transitioning Differential to ApplicationTransactions. 5 - */ 6 - final class DifferentialInlineCommentQuery 7 - extends PhabricatorOffsetPagedQuery { 3 + final class PhabricatorInlineCommentAdjustmentEngine 4 + extends Phobject { 8 5 9 - // TODO: Remove this when this query eventually moves to PolicyAware. 10 6 private $viewer; 11 - 12 - private $ids; 13 - private $phids; 14 - private $drafts; 15 - private $authorPHIDs; 16 - private $revisionPHIDs; 17 - private $deletedDrafts; 18 - private $needHidden; 7 + private $inlines; 8 + private $revision; 9 + private $oldChangesets; 10 + private $newChangesets; 19 11 20 12 public function setViewer(PhabricatorUser $viewer) { 21 13 $this->viewer = $viewer; ··· 26 18 return $this->viewer; 27 19 } 28 20 29 - public function withIDs(array $ids) { 30 - $this->ids = $ids; 21 + public function setInlines(array $inlines) { 22 + assert_instances_of($inlines, 'DifferentialInlineComment'); 23 + $this->inlines = $inlines; 31 24 return $this; 32 25 } 33 26 34 - public function withPHIDs(array $phids) { 35 - $this->phids = $phids; 36 - return $this; 27 + public function getInlines() { 28 + return $this->inlines; 37 29 } 38 30 39 - public function withDrafts($drafts) { 40 - $this->drafts = $drafts; 31 + public function setOldChangesets(array $old_changesets) { 32 + assert_instances_of($old_changesets, 'DifferentialChangeset'); 33 + $this->oldChangesets = $old_changesets; 41 34 return $this; 42 35 } 43 36 44 - public function withAuthorPHIDs(array $author_phids) { 45 - $this->authorPHIDs = $author_phids; 46 - return $this; 37 + public function getOldChangesets() { 38 + return $this->oldChangesets; 47 39 } 48 40 49 - public function withRevisionPHIDs(array $revision_phids) { 50 - $this->revisionPHIDs = $revision_phids; 41 + public function setNewChangesets(array $new_changesets) { 42 + assert_instances_of($new_changesets, 'DifferentialChangeset'); 43 + $this->newChangesets = $new_changesets; 51 44 return $this; 52 45 } 53 46 54 - public function withDeletedDrafts($deleted_drafts) { 55 - $this->deletedDrafts = $deleted_drafts; 56 - return $this; 47 + public function getNewChangesets() { 48 + return $this->newChangesets; 57 49 } 58 50 59 - public function needHidden($need) { 60 - $this->needHidden = $need; 51 + public function setRevision(DifferentialRevision $revision) { 52 + $this->revision = $revision; 61 53 return $this; 62 54 } 63 55 64 - public function execute() { 65 - $table = new DifferentialTransactionComment(); 66 - $conn_r = $table->establishConnection('r'); 67 - 68 - $data = queryfx_all( 69 - $conn_r, 70 - 'SELECT * FROM %T %Q %Q', 71 - $table->getTableName(), 72 - $this->buildWhereClause($conn_r), 73 - $this->buildLimitClause($conn_r)); 74 - 75 - $comments = $table->loadAllFromArray($data); 76 - 77 - if ($this->needHidden) { 78 - $viewer_phid = $this->getViewer()->getPHID(); 79 - if ($viewer_phid && $comments) { 80 - $hidden = queryfx_all( 81 - $conn_r, 82 - 'SELECT commentID FROM %T WHERE userPHID = %s 83 - AND commentID IN (%Ls)', 84 - id(new DifferentialHiddenComment())->getTableName(), 85 - $viewer_phid, 86 - mpull($comments, 'getID')); 87 - $hidden = array_fuse(ipull($hidden, 'commentID')); 88 - } else { 89 - $hidden = array(); 90 - } 91 - 92 - foreach ($comments as $inline) { 93 - $inline->attachIsHidden(isset($hidden[$inline->getID()])); 94 - } 95 - } 96 - 97 - foreach ($comments as $key => $value) { 98 - $comments[$key] = DifferentialInlineComment::newFromModernComment( 99 - $value); 100 - } 101 - 102 - return $comments; 56 + public function getRevision() { 57 + return $this->revision; 103 58 } 104 59 105 - public function executeOne() { 106 - // TODO: Remove when this query moves to PolicyAware. 107 - return head($this->execute()); 108 - } 109 - 110 - protected function buildWhereClause(AphrontDatabaseConnection $conn) { 111 - $where = array(); 112 - 113 - // Only find inline comments. 114 - $where[] = qsprintf( 115 - $conn, 116 - 'changesetID IS NOT NULL'); 117 - 118 - if ($this->ids !== null) { 119 - $where[] = qsprintf( 120 - $conn, 121 - 'id IN (%Ld)', 122 - $this->ids); 123 - } 124 - 125 - if ($this->phids !== null) { 126 - $where[] = qsprintf( 127 - $conn, 128 - 'phid IN (%Ls)', 129 - $this->phids); 130 - } 131 - 132 - if ($this->revisionPHIDs !== null) { 133 - $where[] = qsprintf( 134 - $conn, 135 - 'revisionPHID IN (%Ls)', 136 - $this->revisionPHIDs); 137 - } 138 - 139 - if ($this->drafts === null) { 140 - if ($this->deletedDrafts) { 141 - $where[] = qsprintf( 142 - $conn, 143 - '(authorPHID = %s) OR (transactionPHID IS NOT NULL)', 144 - $this->getViewer()->getPHID()); 145 - } else { 146 - $where[] = qsprintf( 147 - $conn, 148 - '(authorPHID = %s AND isDeleted = 0) 149 - OR (transactionPHID IS NOT NULL)', 150 - $this->getViewer()->getPHID()); 151 - } 152 - } else if ($this->drafts) { 153 - $where[] = qsprintf( 154 - $conn, 155 - '(authorPHID = %s AND isDeleted = 0) AND (transactionPHID IS NULL)', 156 - $this->getViewer()->getPHID()); 157 - } else { 158 - $where[] = qsprintf( 159 - $conn, 160 - 'transactionPHID IS NOT NULL'); 161 - } 162 - 163 - return $this->formatWhereClause($conn, $where); 164 - } 165 - 166 - public function adjustInlinesForChangesets( 167 - array $inlines, 168 - array $old, 169 - array $new, 170 - DifferentialRevision $revision) { 171 - 172 - assert_instances_of($inlines, 'DifferentialInlineComment'); 173 - assert_instances_of($old, 'DifferentialChangeset'); 174 - assert_instances_of($new, 'DifferentialChangeset'); 175 - 60 + public function execute() { 176 61 $viewer = $this->getViewer(); 62 + $inlines = $this->getInlines(); 63 + $revision = $this->getRevision(); 64 + $old = $this->getOldChangesets(); 65 + $new = $this->getNewChangesets(); 177 66 178 67 $no_ghosts = $viewer->compareUserSetting( 179 68 PhabricatorOlderInlinesSetting::SETTINGKEY,
+6
src/applications/diffusion/query/DiffusionDiffInlineCommentQuery.php
··· 60 60 return $where; 61 61 } 62 62 63 + protected function loadHiddenCommentIDs( 64 + $viewer_phid, 65 + array $comments) { 66 + return array(); 67 + } 68 + 63 69 }
+34 -4
src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php
··· 7 7 private $needReplyToComments; 8 8 private $publishedComments; 9 9 private $publishableComments; 10 + private $needHidden; 10 11 11 12 abstract protected function buildInlineCommentWhereClauseParts( 12 13 AphrontDatabaseConnection $conn); 13 14 abstract public function withObjectPHIDs(array $phids); 15 + abstract protected function loadHiddenCommentIDs( 16 + $viewer_phid, 17 + array $comments); 14 18 15 - public function withFixedStates(array $states) { 19 + final public function withFixedStates(array $states) { 16 20 $this->fixedStates = $states; 17 21 return $this; 18 22 } 19 23 20 - public function needReplyToComments($need_reply_to) { 24 + final public function needReplyToComments($need_reply_to) { 21 25 $this->needReplyToComments = $need_reply_to; 22 26 return $this; 23 27 } 24 28 25 - public function withPublishableComments($with_publishable) { 29 + final public function withPublishableComments($with_publishable) { 26 30 $this->publishableComments = $with_publishable; 27 31 return $this; 28 32 } 29 33 30 - public function withPublishedComments($with_published) { 34 + final public function withPublishedComments($with_published) { 31 35 $this->publishedComments = $with_published; 36 + return $this; 37 + } 38 + 39 + final public function needHidden($need_hidden) { 40 + $this->needHidden = $need_hidden; 32 41 return $this; 33 42 } 34 43 ··· 149 158 continue; 150 159 } 151 160 $comment->attachReplyToComment($reply); 161 + } 162 + } 163 + 164 + if (!$comments) { 165 + return $comments; 166 + } 167 + 168 + if ($this->needHidden) { 169 + $viewer = $this->getViewer(); 170 + $viewer_phid = $viewer->getPHID(); 171 + 172 + if ($viewer_phid) { 173 + $hidden = $this->loadHiddenCommentIDs( 174 + $viewer_phid, 175 + $comments); 176 + } else { 177 + $hidden = array(); 178 + } 179 + 180 + foreach ($comments as $inline) { 181 + $inline->attachIsHidden(isset($hidden[$inline->getID()])); 152 182 } 153 183 } 154 184