mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Provide more buildXClause() and buildXClauseParts() on PolicyAwareQuery
Summary: Ref T4100. Ref T5595. These functions are trivial for now, but move us toward being able to define more default query behavior by default. Future changes will give these methods meaningful, nontrivial behaviors. Test Plan: `arc unit --everything` Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5595, T4100 Differential Revision: https://secure.phabricator.com/D12454
This commit is contained in:
parent
f5580c7a08
commit
55e49d7e31
14 changed files with 194 additions and 16 deletions
|
@ -75,7 +75,7 @@ final class AlmanacServiceQuery
|
|||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
protected function buildJoinClause($conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
$joins = array();
|
||||
|
||||
if ($this->devicePHIDs !== null) {
|
||||
|
|
|
@ -129,7 +129,7 @@ final class ConpherenceThreadQuery
|
|||
}
|
||||
}
|
||||
|
||||
private function buildJoinClause($conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
$joins = array();
|
||||
|
||||
if ($this->participantPHIDs !== null) {
|
||||
|
|
|
@ -511,7 +511,7 @@ final class DiffusionCommitQuery
|
|||
}
|
||||
}
|
||||
|
||||
private function buildJoinClause($conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
$joins = array();
|
||||
$audit_request = new PhabricatorRepositoryAuditRequest();
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ final class PhabricatorFeedQuery
|
|||
return PhabricatorFeedStory::loadAllFromRows($data, $this->getViewer());
|
||||
}
|
||||
|
||||
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
// NOTE: We perform this join unconditionally (even if we have no filter
|
||||
// PHIDs) to omit rows which have no story references. These story data
|
||||
// rows are notifications or realtime alerts.
|
||||
|
|
|
@ -215,7 +215,7 @@ final class PhabricatorFileQuery
|
|||
return $files;
|
||||
}
|
||||
|
||||
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
$joins = array();
|
||||
|
||||
if ($this->transforms) {
|
||||
|
|
|
@ -134,7 +134,7 @@ final class LegalpadDocumentQuery
|
|||
return $documents;
|
||||
}
|
||||
|
||||
private function buildJoinClause($conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
$joins = array();
|
||||
|
||||
if ($this->contributorPHIDs !== null) {
|
||||
|
|
|
@ -35,7 +35,7 @@ final class PhabricatorOwnersPackageQuery
|
|||
return $table->loadAllFromArray($data);
|
||||
}
|
||||
|
||||
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
$joins = array();
|
||||
|
||||
if ($this->ownerPHIDs) {
|
||||
|
|
|
@ -102,7 +102,7 @@ final class PhortuneAccountQuery
|
|||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
private function buildJoinClause(AphrontDatabaseConnection $conn) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
|
||||
$joins = array();
|
||||
|
||||
if ($this->memberPHIDs) {
|
||||
|
|
|
@ -82,7 +82,7 @@ final class PhortuneMerchantQuery
|
|||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
private function buildJoinClause(AphrontDatabaseConnection $conn) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
|
||||
$joins = array();
|
||||
|
||||
if ($this->memberPHIDs !== null) {
|
||||
|
|
|
@ -190,7 +190,7 @@ final class PhrictionDocumentQuery
|
|||
return $documents;
|
||||
}
|
||||
|
||||
private function buildJoinClause(AphrontDatabaseConnection $conn) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
|
||||
$join = '';
|
||||
|
||||
if ($this->getOrderVector()->containsKey('updated')) {
|
||||
|
|
|
@ -336,7 +336,7 @@ final class PhabricatorProjectQuery
|
|||
}
|
||||
}
|
||||
|
||||
private function buildJoinClause($conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
$joins = array();
|
||||
|
||||
if (!$this->needMembers !== null) {
|
||||
|
|
|
@ -145,7 +145,7 @@ final class PhabricatorWorkerTriggerQuery
|
|||
return $triggers;
|
||||
}
|
||||
|
||||
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
||||
$joins = array();
|
||||
|
||||
if (($this->nextEpochMin !== null) ||
|
||||
|
|
|
@ -1,17 +1,122 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @task format Formatting Query Clauses
|
||||
*/
|
||||
abstract class PhabricatorQuery {
|
||||
|
||||
|
||||
abstract public function execute();
|
||||
|
||||
final protected function formatWhereClause(array $parts) {
|
||||
$parts = array_filter($parts);
|
||||
|
||||
/* -( Formatting Query Clauses )------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatWhereClause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return 'WHERE ('.implode(') AND (', $parts).')';
|
||||
return 'WHERE '.$this->formatWhereSubclause($parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatWhereSubclause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return '('.implode(') AND (', $parts).')';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatSelectClause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
throw new Exception(pht('Can not build empty select clause!'));
|
||||
}
|
||||
|
||||
return 'SELECT '.$this->formatSelectSubclause($parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatSelectSubclause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return null;
|
||||
}
|
||||
return implode(', ', $parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatJoinClause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return implode(' ', $parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatHavingClause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return 'HAVING '.$this->formatHavingSubclause($parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
protected function formatHavingSubclause(array $parts) {
|
||||
$parts = $this->flattenSubclause($parts);
|
||||
if (!$parts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return '('.implode(') AND (', $parts).')';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task format
|
||||
*/
|
||||
private function flattenSubclause(array $parts) {
|
||||
$result = array();
|
||||
foreach ($parts as $part) {
|
||||
if (is_array($part)) {
|
||||
foreach ($this->flattenSubclause($part) as $subpart) {
|
||||
$result[] = $subpart;
|
||||
}
|
||||
} else if (strlen($part)) {
|
||||
$result[] = $part;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -180,11 +180,84 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
|
|||
/* -( Building Query Clauses )--------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
* @task clauses
|
||||
*/
|
||||
protected function buildSelectClause(AphrontDatabaseConnection $conn) {
|
||||
$parts = $this->buildSelectClauseParts($conn);
|
||||
return $this->formatSelectClause($parts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task clauses
|
||||
*/
|
||||
protected function buildSelectClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$select = array();
|
||||
|
||||
$alias = $this->getPrimaryTableAlias();
|
||||
if ($alias) {
|
||||
$select[] = qsprintf($conn, '%T.*', $alias);
|
||||
} else {
|
||||
$select[] = '*';
|
||||
}
|
||||
|
||||
return $select;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task clauses
|
||||
*/
|
||||
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
|
||||
$joins = $this->buildJoinClauseParts($conn);
|
||||
return $this->formatJoinClause($joins);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task clauses
|
||||
*/
|
||||
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$joins = array();
|
||||
return $joins;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task clauses
|
||||
*/
|
||||
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
|
||||
throw new PhutilMethodNotImplementedException();
|
||||
$where = $this->buildWhereClauseParts($conn);
|
||||
return $this->formatWhereClause($where);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task clauses
|
||||
*/
|
||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$where = array();
|
||||
$where[] = $this->buildPagingClause($conn);
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task clauses
|
||||
*/
|
||||
protected function buildHavingClause(AphrontDatabaseConnection $conn) {
|
||||
$having = $this->buildHavingClauseParts($conn);
|
||||
return $this->formatHavingClause($having);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task clauses
|
||||
*/
|
||||
protected function buildHavingClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$having = array();
|
||||
return $having;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue