mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Prepare TransactionCommentQuery for extension
Summary: Ref T2009. Ref T1460. The way Diffusion and Differential load inlines is horrible garbage right now: - Differential does an ad-hoc query to get the PHIDs, then does a real load to policy check. - Diffusion completely fakes things. In practice this is not a policy violation, but it's dangerous. Make TransactionCommentQuery extensible so we can subclass it and get the query building correctly in the right Query layer. Specifically, the Diffusion and Differential subclasses of this Query will add appropriate `withX()` methods to let us express the query in SQL. Test Plan: Loaded, previewed, edited, and submitted inlines in Differential and Diffusion Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2009, T1460 Differential Revision: https://secure.phabricator.com/D12026
This commit is contained in:
parent
2972894a4d
commit
4d86d51125
7 changed files with 81 additions and 30 deletions
|
@ -1298,6 +1298,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorApplicationTransactionResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionResponse.php',
|
'PhabricatorApplicationTransactionResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionResponse.php',
|
||||||
'PhabricatorApplicationTransactionShowOlderController' => 'applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php',
|
'PhabricatorApplicationTransactionShowOlderController' => 'applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php',
|
||||||
'PhabricatorApplicationTransactionStructureException' => 'applications/transactions/exception/PhabricatorApplicationTransactionStructureException.php',
|
'PhabricatorApplicationTransactionStructureException' => 'applications/transactions/exception/PhabricatorApplicationTransactionStructureException.php',
|
||||||
|
'PhabricatorApplicationTransactionTemplatedCommentQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionTemplatedCommentQuery.php',
|
||||||
'PhabricatorApplicationTransactionTextDiffDetailView' => 'applications/transactions/view/PhabricatorApplicationTransactionTextDiffDetailView.php',
|
'PhabricatorApplicationTransactionTextDiffDetailView' => 'applications/transactions/view/PhabricatorApplicationTransactionTextDiffDetailView.php',
|
||||||
'PhabricatorApplicationTransactionTransactionPHIDType' => 'applications/transactions/phid/PhabricatorApplicationTransactionTransactionPHIDType.php',
|
'PhabricatorApplicationTransactionTransactionPHIDType' => 'applications/transactions/phid/PhabricatorApplicationTransactionTransactionPHIDType.php',
|
||||||
'PhabricatorApplicationTransactionValidationError' => 'applications/transactions/error/PhabricatorApplicationTransactionValidationError.php',
|
'PhabricatorApplicationTransactionValidationError' => 'applications/transactions/error/PhabricatorApplicationTransactionValidationError.php',
|
||||||
|
@ -4541,6 +4542,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorApplicationTransactionResponse' => 'AphrontProxyResponse',
|
'PhabricatorApplicationTransactionResponse' => 'AphrontProxyResponse',
|
||||||
'PhabricatorApplicationTransactionShowOlderController' => 'PhabricatorApplicationTransactionController',
|
'PhabricatorApplicationTransactionShowOlderController' => 'PhabricatorApplicationTransactionController',
|
||||||
'PhabricatorApplicationTransactionStructureException' => 'Exception',
|
'PhabricatorApplicationTransactionStructureException' => 'Exception',
|
||||||
|
'PhabricatorApplicationTransactionTemplatedCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery',
|
||||||
'PhabricatorApplicationTransactionTextDiffDetailView' => 'AphrontView',
|
'PhabricatorApplicationTransactionTextDiffDetailView' => 'AphrontView',
|
||||||
'PhabricatorApplicationTransactionTransactionPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorApplicationTransactionTransactionPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorApplicationTransactionValidationError' => 'Phobject',
|
'PhabricatorApplicationTransactionValidationError' => 'Phobject',
|
||||||
|
|
|
@ -11,11 +11,7 @@ final class DifferentialTransactionQuery
|
||||||
PhabricatorUser $viewer,
|
PhabricatorUser $viewer,
|
||||||
DifferentialRevision $revision) {
|
DifferentialRevision $revision) {
|
||||||
|
|
||||||
// TODO: This probably needs to move somewhere more central as we move
|
// TODO: Subclass ApplicationTransactionCommentQuery to do this for real.
|
||||||
// away from DifferentialInlineCommentQuery, but
|
|
||||||
// PhabricatorApplicationTransactionCommentQuery is currently `final` and
|
|
||||||
// I'm not yet decided on how to approach that. For now, just get the PHIDs
|
|
||||||
// and then execute a PHID-based query through the standard stack.
|
|
||||||
|
|
||||||
$table = new DifferentialTransactionComment();
|
$table = new DifferentialTransactionComment();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
@ -36,7 +32,7 @@ final class DifferentialTransactionQuery
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$comments = id(new PhabricatorApplicationTransactionCommentQuery())
|
$comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery())
|
||||||
->setTemplate(new DifferentialTransactionComment())
|
->setTemplate(new DifferentialTransactionComment())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withPHIDs($phids)
|
->withPHIDs($phids)
|
||||||
|
|
|
@ -36,7 +36,7 @@ final class PhabricatorApplicationTransactionCommentHistoryController
|
||||||
return new Aphront400Response();
|
return new Aphront400Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
$comments = id(new PhabricatorApplicationTransactionCommentQuery())
|
$comments = id(new PhabricatorApplicationTransactionTemplatedCommentQuery())
|
||||||
->setViewer($user)
|
->setViewer($user)
|
||||||
->setTemplate($xaction->getApplicationTransactionCommentObject())
|
->setTemplate($xaction->getApplicationTransactionCommentObject())
|
||||||
->withTransactionPHIDs(array($xaction->getPHID()))
|
->withTransactionPHIDs(array($xaction->getPHID()))
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class PhabricatorApplicationTransactionCommentQuery
|
abstract class PhabricatorApplicationTransactionCommentQuery
|
||||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
private $template;
|
private $ids;
|
||||||
|
private $authorPHIDs;
|
||||||
private $phids;
|
private $phids;
|
||||||
private $transactionPHIDs;
|
private $transactionPHIDs;
|
||||||
|
private $isDeleted;
|
||||||
|
|
||||||
public function setTemplate(
|
abstract protected function getTemplate();
|
||||||
PhabricatorApplicationTransactionComment $template) {
|
|
||||||
$this->template = $template;
|
public function withIDs(array $ids) {
|
||||||
|
$this->ids = $ids;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,13 +26,23 @@ final class PhabricatorApplicationTransactionCommentQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withAuthorPHIDs(array $phids) {
|
||||||
|
$this->authorPHIDs = $phids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withDeleted($deleted) {
|
||||||
|
$this->isDeleted = $deleted;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
$table = $this->template;
|
$table = $this->getTemplate();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
$data = queryfx_all(
|
$data = queryfx_all(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'SELECT * FROM %T xc %Q %Q %Q',
|
'SELECT * FROM %T xcomment %Q %Q %Q',
|
||||||
$table->getTableName(),
|
$table->getTableName(),
|
||||||
$this->buildWhereClause($conn_r),
|
$this->buildWhereClause($conn_r),
|
||||||
$this->buildOrderClause($conn_r),
|
$this->buildOrderClause($conn_r),
|
||||||
|
@ -39,23 +51,44 @@ final class PhabricatorApplicationTransactionCommentQuery
|
||||||
return $table->loadAllFromArray($data);
|
return $table->loadAllFromArray($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||||
$where = array();
|
$where = array();
|
||||||
|
|
||||||
if ($this->phids) {
|
if ($this->ids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'phid IN (%Ls)',
|
'xcomment.id IN (%Ld)',
|
||||||
|
$this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->phids !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'xcomment.phid IN (%Ls)',
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->transactionPHIDs) {
|
if ($this->authorPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'transactionPHID IN (%Ls)',
|
'xcomment.authorPHID IN (%Ls)',
|
||||||
|
$this->authorPHIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->transactionPHIDs !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'xcomment.transactionPHID IN (%Ls)',
|
||||||
$this->transactionPHIDs);
|
$this->transactionPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->isDeleted !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'xcomment.isDeleted = %d',
|
||||||
|
(int)$this->isDeleted);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
return $this->formatWhereClause($where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,8 @@ abstract class PhabricatorApplicationTransactionQuery
|
||||||
|
|
||||||
$comments = array();
|
$comments = array();
|
||||||
if ($comment_phids) {
|
if ($comment_phids) {
|
||||||
$comments = id(new PhabricatorApplicationTransactionCommentQuery())
|
$comments =
|
||||||
|
id(new PhabricatorApplicationTransactionTemplatedCommentQuery())
|
||||||
->setTemplate($table->getApplicationTransactionCommentObject())
|
->setTemplate($table->getApplicationTransactionCommentObject())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->withPHIDs($comment_phids)
|
->withPHIDs($comment_phids)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorApplicationTransactionTemplatedCommentQuery
|
||||||
|
extends PhabricatorApplicationTransactionCommentQuery {
|
||||||
|
|
||||||
|
private $template;
|
||||||
|
|
||||||
|
public function setTemplate(
|
||||||
|
PhabricatorApplicationTransactionComment $template) {
|
||||||
|
$this->template = $template;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTemplate() {
|
||||||
|
return $this->template;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -330,7 +330,8 @@ abstract class PhabricatorInlineCommentController
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($reply_phids) {
|
if ($reply_phids) {
|
||||||
$reply_comments = id(new PhabricatorApplicationTransactionCommentQuery())
|
$reply_comments =
|
||||||
|
id(new PhabricatorApplicationTransactionTemplatedCommentQuery())
|
||||||
->setTemplate($template)
|
->setTemplate($template)
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withPHIDs($reply_phids)
|
->withPHIDs($reply_phids)
|
||||||
|
|
Loading…
Reference in a new issue