Extend TransactionCommentQuery for Differential
Summary: Ref T2009. Ref T1460. Replace hard-coded garbage with a real Query-layer query. Test Plan: Submitted inline comments in Differential. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2009, T1460 Differential Revision: https://secure.phabricator.com/D12027
This commit is contained in:
@@ -339,6 +339,7 @@ phutil_register_library_map(array(
|
|||||||
'DifferentialDiff' => 'applications/differential/storage/DifferentialDiff.php',
|
'DifferentialDiff' => 'applications/differential/storage/DifferentialDiff.php',
|
||||||
'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php',
|
'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php',
|
||||||
'DifferentialDiffEditor' => 'applications/differential/editor/DifferentialDiffEditor.php',
|
'DifferentialDiffEditor' => 'applications/differential/editor/DifferentialDiffEditor.php',
|
||||||
|
'DifferentialDiffInlineCommentQuery' => 'applications/differential/query/DifferentialDiffInlineCommentQuery.php',
|
||||||
'DifferentialDiffPHIDType' => 'applications/differential/phid/DifferentialDiffPHIDType.php',
|
'DifferentialDiffPHIDType' => 'applications/differential/phid/DifferentialDiffPHIDType.php',
|
||||||
'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php',
|
'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php',
|
||||||
'DifferentialDiffQuery' => 'applications/differential/query/DifferentialDiffQuery.php',
|
'DifferentialDiffQuery' => 'applications/differential/query/DifferentialDiffQuery.php',
|
||||||
@@ -1692,6 +1693,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php',
|
'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php',
|
||||||
'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php',
|
'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php',
|
||||||
'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php',
|
'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php',
|
||||||
|
'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php',
|
||||||
'PhabricatorDiffPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDiffPreferencesSettingsPanel.php',
|
'PhabricatorDiffPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDiffPreferencesSettingsPanel.php',
|
||||||
'PhabricatorDifferenceEngine' => 'infrastructure/diff/PhabricatorDifferenceEngine.php',
|
'PhabricatorDifferenceEngine' => 'infrastructure/diff/PhabricatorDifferenceEngine.php',
|
||||||
'PhabricatorDifferentialApplication' => 'applications/differential/application/PhabricatorDifferentialApplication.php',
|
'PhabricatorDifferentialApplication' => 'applications/differential/application/PhabricatorDifferentialApplication.php',
|
||||||
@@ -3487,6 +3489,7 @@ phutil_register_library_map(array(
|
|||||||
),
|
),
|
||||||
'DifferentialDiffCreateController' => 'DifferentialController',
|
'DifferentialDiffCreateController' => 'DifferentialController',
|
||||||
'DifferentialDiffEditor' => 'PhabricatorApplicationTransactionEditor',
|
'DifferentialDiffEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
|
'DifferentialDiffInlineCommentQuery' => 'PhabricatorDiffInlineCommentQuery',
|
||||||
'DifferentialDiffPHIDType' => 'PhabricatorPHIDType',
|
'DifferentialDiffPHIDType' => 'PhabricatorPHIDType',
|
||||||
'DifferentialDiffProperty' => 'DifferentialDAO',
|
'DifferentialDiffProperty' => 'DifferentialDAO',
|
||||||
'DifferentialDiffQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'DifferentialDiffQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
@@ -4974,6 +4977,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorDestructionEngine' => 'Phobject',
|
'PhabricatorDestructionEngine' => 'Phobject',
|
||||||
'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
|
'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||||
|
'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery',
|
||||||
'PhabricatorDiffPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
|
'PhabricatorDiffPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||||
'PhabricatorDifferentialApplication' => 'PhabricatorApplication',
|
'PhabricatorDifferentialApplication' => 'PhabricatorApplication',
|
||||||
'PhabricatorDifferentialConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorDifferentialConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
final class DifferentialDiffInlineCommentQuery
|
||||||
|
extends PhabricatorDiffInlineCommentQuery {
|
||||||
|
|
||||||
|
private $revisionPHIDs;
|
||||||
|
|
||||||
|
public function withRevisionPHIDs(array $phids) {
|
||||||
|
$this->revisionPHIDs = $phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTemplate() {
|
||||||
|
return new DifferentialTransactionComment();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildWhereClauseComponents(
|
||||||
|
AphrontDatabaseConnection $conn_r) {
|
||||||
|
$where = parent::buildWhereClauseComponents($conn_r);
|
||||||
|
|
||||||
|
if ($this->revisionPHIDs !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'revisionPHID IN (%Ls)',
|
||||||
|
$this->revisionPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $where;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,38 +11,14 @@ final class DifferentialTransactionQuery
|
|||||||
PhabricatorUser $viewer,
|
PhabricatorUser $viewer,
|
||||||
DifferentialRevision $revision) {
|
DifferentialRevision $revision) {
|
||||||
|
|
||||||
// TODO: Subclass ApplicationTransactionCommentQuery to do this for real.
|
return id(new DifferentialDiffInlineCommentQuery())
|
||||||
|
|
||||||
$table = new DifferentialTransactionComment();
|
|
||||||
$conn_r = $table->establishConnection('r');
|
|
||||||
|
|
||||||
$phids = queryfx_all(
|
|
||||||
$conn_r,
|
|
||||||
'SELECT phid FROM %T
|
|
||||||
WHERE revisionPHID = %s
|
|
||||||
AND authorPHID = %s
|
|
||||||
AND transactionPHID IS NULL
|
|
||||||
AND isDeleted = 0',
|
|
||||||
$table->getTableName(),
|
|
||||||
$revision->getPHID(),
|
|
||||||
$viewer->getPHID());
|
|
||||||
|
|
||||||
$phids = ipull($phids, 'phid');
|
|
||||||
if (!$phids) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery())
|
|
||||||
->setTemplate(new DifferentialTransactionComment())
|
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withPHIDs($phids)
|
->withRevisionPHIDs(array($revision->getPHID()))
|
||||||
|
->withAuthorPHIDs(array($viewer->getPHID()))
|
||||||
|
->withHasTransaction(false)
|
||||||
|
->withIsDeleted(false)
|
||||||
|
->needReplyToComments(true)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$comments = PhabricatorInlineCommentController::loadAndAttachReplies(
|
|
||||||
$viewer,
|
|
||||||
$comments);
|
|
||||||
|
|
||||||
return $comments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ abstract class PhabricatorApplicationTransactionCommentQuery
|
|||||||
private $phids;
|
private $phids;
|
||||||
private $transactionPHIDs;
|
private $transactionPHIDs;
|
||||||
private $isDeleted;
|
private $isDeleted;
|
||||||
|
private $hasTransaction;
|
||||||
|
|
||||||
abstract protected function getTemplate();
|
abstract protected function getTemplate();
|
||||||
|
|
||||||
@@ -31,11 +32,16 @@ abstract class PhabricatorApplicationTransactionCommentQuery
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withDeleted($deleted) {
|
public function withIsDeleted($deleted) {
|
||||||
$this->isDeleted = $deleted;
|
$this->isDeleted = $deleted;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withHasTransaction($has_transaction) {
|
||||||
|
$this->hasTransaction = $has_transaction;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
$table = $this->getTemplate();
|
$table = $this->getTemplate();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
@@ -51,7 +57,13 @@ abstract class PhabricatorApplicationTransactionCommentQuery
|
|||||||
return $table->loadAllFromArray($data);
|
return $table->loadAllFromArray($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||||
|
return $this->formatWhereClause($this->buildWhereClauseComponents($conn_r));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildWhereClauseComponents(
|
||||||
|
AphrontDatabaseConnection $conn_r) {
|
||||||
|
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
if ($this->ids !== null) {
|
if ($this->ids !== null) {
|
||||||
@@ -89,7 +101,19 @@ abstract class PhabricatorApplicationTransactionCommentQuery
|
|||||||
(int)$this->isDeleted);
|
(int)$this->isDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
if ($this->hasTransaction !== null) {
|
||||||
|
if ($this->hasTransaction) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'xcomment.transactionPHID IS NOT NULL');
|
||||||
|
} else {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'xcomment.transactionPHID IS NULL');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $where;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryApplicationClass() {
|
public function getQueryApplicationClass() {
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorDiffInlineCommentQuery
|
||||||
|
extends PhabricatorApplicationTransactionCommentQuery {
|
||||||
|
|
||||||
|
private $needReplyToComments;
|
||||||
|
|
||||||
|
public function needReplyToComments($need_reply_to) {
|
||||||
|
$this->needReplyToComments = $need_reply_to;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function willFilterPage(array $comments) {
|
||||||
|
if ($this->needReplyToComments) {
|
||||||
|
$reply_phids = array();
|
||||||
|
foreach ($comments as $comment) {
|
||||||
|
$reply_phid = $comment->getReplyToCommentPHID();
|
||||||
|
if ($reply_phid) {
|
||||||
|
$reply_phids[] = $reply_phid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reply_phids) {
|
||||||
|
$reply_comments = newv(get_class($this), array())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->setParentQuery($this)
|
||||||
|
->withPHIDs($reply_phids)
|
||||||
|
->execute();
|
||||||
|
$reply_comments = mpull($reply_comments, null, 'getPHID');
|
||||||
|
} else {
|
||||||
|
$reply_comments = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($comments as $key => $comment) {
|
||||||
|
$reply_phid = $comment->getReplyToCommentPHID();
|
||||||
|
if (!$reply_phid) {
|
||||||
|
$comment->attachReplyToComment(null);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$reply = idx($reply_comments, $reply_phid);
|
||||||
|
if (!$reply) {
|
||||||
|
$this->didRejectResult($comment);
|
||||||
|
unset($comments[$key]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$comment->attachReplyToComment($reply);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user