3 final class DifferentialDiffInlineCommentQuery
4 extends PhabricatorDiffInlineCommentQuery
{
6 private $revisionPHIDs;
8 protected function newApplicationTransactionCommentTemplate() {
9 return new DifferentialTransactionComment();
12 public function withRevisionPHIDs(array $phids) {
13 $this->revisionPHIDs
= $phids;
17 public function withObjectPHIDs(array $phids) {
18 return $this->withRevisionPHIDs($phids);
21 protected function buildInlineCommentWhereClauseParts(
22 AphrontDatabaseConnection
$conn) {
24 $alias = $this->getPrimaryTableAlias();
28 'changesetID IS NOT NULL');
33 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
34 $where = parent
::buildWhereClauseParts($conn);
35 $alias = $this->getPrimaryTableAlias();
37 if ($this->revisionPHIDs
!== null) {
40 '%T.revisionPHID IN (%Ls)',
42 $this->revisionPHIDs
);
48 protected function loadHiddenCommentIDs(
52 $table = new DifferentialHiddenComment();
53 $conn = $table->establishConnection('r');
57 'SELECT commentID FROM %R
59 AND commentID IN (%Ld)',
62 mpull($comments, 'getID'));
64 $id_map = ipull($rows, 'commentID');
65 $id_map = array_fuse($id_map);
70 protected function newInlineContextFromCacheData(array $map) {
71 return PhabricatorDiffInlineCommentContext
::newFromCacheData($map);
74 protected function newInlineContextMap(array $inlines) {
75 $viewer = $this->getViewer();
78 $changeset_ids = mpull($inlines, 'getChangesetID');
80 $changesets = id(new DifferentialChangesetQuery())
82 ->withIDs($changeset_ids)
85 $changesets = mpull($changesets, null, 'getID');
87 foreach ($inlines as $key => $inline) {
88 $changeset = idx($changesets, $inline->getChangesetID());
94 $hunks = $changeset->getHunks();
97 (count($hunks) === 1) &&
98 ((int)head($hunks)->getOldOffset() <= 1) &&
99 ((int)head($hunks)->getNewOffset() <= 1);
105 if ($inline->getIsNewFile()) {
106 $vector = $changeset->getNewStatePathVector();
107 $filename = last($vector);
108 $corpus = $changeset->makeNewFile();
110 $vector = $changeset->getOldStatePathVector();
111 $filename = last($vector);
112 $corpus = $changeset->makeOldFile();
115 $corpus = phutil_split_lines($corpus);
117 // Adjust the line number into a 0-based offset.
118 $offset = $inline->getLineNumber();
119 $offset = $offset - 1;
121 // Adjust the inclusive range length into a row count.
122 $length = $inline->getLineLength();
123 $length = $length +
1;
125 $head_min = max(0, $offset - 3);
127 $head_len = $head_max - $head_min;
130 $head = array_slice($corpus, $head_min, $head_len, true);
131 $head = $this->simplifyContext($head, true);
136 $body = array_slice($corpus, $offset, $length, true);
138 $tail = array_slice($corpus, $offset +
$length, 3, true);
139 $tail = $this->simplifyContext($tail, false);
141 $context = id(new PhabricatorDiffInlineCommentContext())
142 ->setFilename($filename)
143 ->setHeadLines($head)
144 ->setBodyLines($body)
145 ->setTailLines($tail);
147 $map[$key] = $context;