1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 04:20:55 +01:00
phorge-phorge/src/applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php
epriestley f5580c7a08 Make buildWhereClause() a method of AphrontCursorPagedPolicyAwareQuery
Summary:
Ref T4100. Ref T5595.

To support a unified "Projects:" query across all applications, a future diff is going to add a set of "Edge Logic" capabilities to `PolicyAwareQuery` which write the required SELECT, JOIN, WHERE, HAVING and GROUP clauses for you.

With the addition of "Edge Logic", we'll have three systems which may need to build components of query claues: ordering/paging, customfields/applicationsearch, and edge logic.

For most clauses, queries don't currently call into the parent explicitly to get default components. I want to move more query construction logic up the class tree so it can be shared.

For most methods, this isn't a problem, but many subclasses define a `buildWhereClause()`. Make all such definitions protected and consistent.

This causes no behavioral changes.

Test Plan: Ran `arc unit --everything`, which does a pretty through job of verifying this statically.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: yelirekim, hach-que, epriestley

Maniphest Tasks: T4100, T5595

Differential Revision: https://secure.phabricator.com/D12453
2015-04-20 10:06:09 -07:00

125 lines
2.8 KiB
PHP

<?php
abstract class PhabricatorApplicationTransactionCommentQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $authorPHIDs;
private $phids;
private $transactionPHIDs;
private $isDeleted;
private $hasTransaction;
abstract protected function getTemplate();
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withTransactionPHIDs(array $transaction_phids) {
$this->transactionPHIDs = $transaction_phids;
return $this;
}
public function withAuthorPHIDs(array $phids) {
$this->authorPHIDs = $phids;
return $this;
}
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');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T xcomment %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data);
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
return $this->formatWhereClause($this->buildWhereClauseComponents($conn_r));
}
protected function buildWhereClauseComponents(
AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->ids !== null) {
$where[] = qsprintf(
$conn_r,
'xcomment.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn_r,
'xcomment.phid IN (%Ls)',
$this->phids);
}
if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
'xcomment.authorPHID IN (%Ls)',
$this->authorPHIDs);
}
if ($this->transactionPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
'xcomment.transactionPHID IN (%Ls)',
$this->transactionPHIDs);
}
if ($this->isDeleted !== null) {
$where[] = qsprintf(
$conn_r,
'xcomment.isDeleted = %d',
(int)$this->isDeleted);
}
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() {
// TODO: Figure out the app via the template?
return null;
}
}