1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

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:
epriestley 2015-03-09 12:40:29 -07:00
parent 4d86d51125
commit 7427a6e648
5 changed files with 121 additions and 33 deletions

View file

@ -339,6 +339,7 @@ phutil_register_library_map(array(
'DifferentialDiff' => 'applications/differential/storage/DifferentialDiff.php',
'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php',
'DifferentialDiffEditor' => 'applications/differential/editor/DifferentialDiffEditor.php',
'DifferentialDiffInlineCommentQuery' => 'applications/differential/query/DifferentialDiffInlineCommentQuery.php',
'DifferentialDiffPHIDType' => 'applications/differential/phid/DifferentialDiffPHIDType.php',
'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php',
'DifferentialDiffQuery' => 'applications/differential/query/DifferentialDiffQuery.php',
@ -1692,6 +1693,7 @@ phutil_register_library_map(array(
'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php',
'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php',
'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php',
'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php',
'PhabricatorDiffPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDiffPreferencesSettingsPanel.php',
'PhabricatorDifferenceEngine' => 'infrastructure/diff/PhabricatorDifferenceEngine.php',
'PhabricatorDifferentialApplication' => 'applications/differential/application/PhabricatorDifferentialApplication.php',
@ -3487,6 +3489,7 @@ phutil_register_library_map(array(
),
'DifferentialDiffCreateController' => 'DifferentialController',
'DifferentialDiffEditor' => 'PhabricatorApplicationTransactionEditor',
'DifferentialDiffInlineCommentQuery' => 'PhabricatorDiffInlineCommentQuery',
'DifferentialDiffPHIDType' => 'PhabricatorPHIDType',
'DifferentialDiffProperty' => 'DifferentialDAO',
'DifferentialDiffQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
@ -4974,6 +4977,7 @@ phutil_register_library_map(array(
'PhabricatorDestructionEngine' => 'Phobject',
'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery',
'PhabricatorDiffPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorDifferentialApplication' => 'PhabricatorApplication',
'PhabricatorDifferentialConfigOptions' => 'PhabricatorApplicationConfigOptions',

View file

@ -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;
}
}

View file

@ -11,38 +11,14 @@ final class DifferentialTransactionQuery
PhabricatorUser $viewer,
DifferentialRevision $revision) {
// TODO: Subclass ApplicationTransactionCommentQuery to do this for real.
$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())
return id(new DifferentialDiffInlineCommentQuery())
->setViewer($viewer)
->withPHIDs($phids)
->withRevisionPHIDs(array($revision->getPHID()))
->withAuthorPHIDs(array($viewer->getPHID()))
->withHasTransaction(false)
->withIsDeleted(false)
->needReplyToComments(true)
->execute();
$comments = PhabricatorInlineCommentController::loadAndAttachReplies(
$viewer,
$comments);
return $comments;
}
}

View file

@ -8,6 +8,7 @@ abstract class PhabricatorApplicationTransactionCommentQuery
private $phids;
private $transactionPHIDs;
private $isDeleted;
private $hasTransaction;
abstract protected function getTemplate();
@ -31,11 +32,16 @@ abstract class PhabricatorApplicationTransactionCommentQuery
return $this;
}
public function withDeleted($deleted) {
public function withIsDeleted($deleted) {
$this->isDeleted = $deleted;
return $this;
}
public function withHasTransaction($has_transaction) {
$this->hasTransaction = $has_transaction;
return $this;
}
protected function loadPage() {
$table = $this->getTemplate();
$conn_r = $table->establishConnection('r');
@ -51,7 +57,13 @@ abstract class PhabricatorApplicationTransactionCommentQuery
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();
if ($this->ids !== null) {
@ -89,7 +101,19 @@ abstract class PhabricatorApplicationTransactionCommentQuery
(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() {

View file

@ -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;
}
}