mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 07:12:41 +01:00
Lightly modernize LegalpadDocumentQuery
Summary: Ref T13024. Updates LegalpadDocumentQuery to use slightly more modern constructions. Test Plan: Queried for Legalpad documents, got the same results. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13024 Differential Revision: https://secure.phabricator.com/D18785
This commit is contained in:
parent
00baa3c1dd
commit
3d742eb50b
1 changed files with 33 additions and 38 deletions
|
@ -77,23 +77,12 @@ final class LegalpadDocumentQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function newResultObject() {
|
||||||
|
return new LegalpadDocument();
|
||||||
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
$table = new LegalpadDocument();
|
return $this->loadStandardPage($this->newResultObject());
|
||||||
$conn_r = $table->establishConnection('r');
|
|
||||||
|
|
||||||
$data = queryfx_all(
|
|
||||||
$conn_r,
|
|
||||||
'SELECT d.* FROM %T d %Q %Q %Q %Q %Q',
|
|
||||||
$table->getTableName(),
|
|
||||||
$this->buildJoinClause($conn_r),
|
|
||||||
$this->buildWhereClause($conn_r),
|
|
||||||
$this->buildGroupClause($conn_r),
|
|
||||||
$this->buildOrderClause($conn_r),
|
|
||||||
$this->buildLimitClause($conn_r));
|
|
||||||
|
|
||||||
$documents = $table->loadAllFromArray($data);
|
|
||||||
|
|
||||||
return $documents;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function willFilterPage(array $documents) {
|
protected function willFilterPage(array $documents) {
|
||||||
|
@ -134,12 +123,12 @@ final class LegalpadDocumentQuery
|
||||||
return $documents;
|
return $documents;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$joins = array();
|
$joins = parent::buildJoinClauseParts($conn);
|
||||||
|
|
||||||
if ($this->contributorPHIDs !== null) {
|
if ($this->contributorPHIDs !== null) {
|
||||||
$joins[] = qsprintf(
|
$joins[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'JOIN edge contributor ON contributor.src = d.phid
|
'JOIN edge contributor ON contributor.src = d.phid
|
||||||
AND contributor.type = %d',
|
AND contributor.type = %d',
|
||||||
PhabricatorObjectHasContributorEdgeType::EDGECONST);
|
PhabricatorObjectHasContributorEdgeType::EDGECONST);
|
||||||
|
@ -147,79 +136,81 @@ final class LegalpadDocumentQuery
|
||||||
|
|
||||||
if ($this->signerPHIDs !== null) {
|
if ($this->signerPHIDs !== null) {
|
||||||
$joins[] = qsprintf(
|
$joins[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'JOIN %T signer ON signer.documentPHID = d.phid
|
'JOIN %T signer ON signer.documentPHID = d.phid
|
||||||
AND signer.signerPHID IN (%Ls)',
|
AND signer.signerPHID IN (%Ls)',
|
||||||
id(new LegalpadDocumentSignature())->getTableName(),
|
id(new LegalpadDocumentSignature())->getTableName(),
|
||||||
$this->signerPHIDs);
|
$this->signerPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode(' ', $joins);
|
return $joins;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildGroupClause(AphrontDatabaseConnection $conn_r) {
|
protected function shouldGroupQueryResultRows() {
|
||||||
if ($this->contributorPHIDs || $this->signerPHIDs) {
|
if ($this->contributorPHIDs) {
|
||||||
return 'GROUP BY d.id';
|
return true;
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->signerPHIDs) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::shouldGroupQueryResultRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$where = array();
|
$where = parent::buildWhereClauseParts($conn);
|
||||||
|
|
||||||
if ($this->ids !== null) {
|
if ($this->ids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'd.id IN (%Ld)',
|
'd.id IN (%Ld)',
|
||||||
$this->ids);
|
$this->ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->phids !== null) {
|
if ($this->phids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'd.phid IN (%Ls)',
|
'd.phid IN (%Ls)',
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->creatorPHIDs !== null) {
|
if ($this->creatorPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'd.creatorPHID IN (%Ls)',
|
'd.creatorPHID IN (%Ls)',
|
||||||
$this->creatorPHIDs);
|
$this->creatorPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->dateCreatedAfter !== null) {
|
if ($this->dateCreatedAfter !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'd.dateCreated >= %d',
|
'd.dateCreated >= %d',
|
||||||
$this->dateCreatedAfter);
|
$this->dateCreatedAfter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->dateCreatedBefore !== null) {
|
if ($this->dateCreatedBefore !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'd.dateCreated <= %d',
|
'd.dateCreated <= %d',
|
||||||
$this->dateCreatedBefore);
|
$this->dateCreatedBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->contributorPHIDs !== null) {
|
if ($this->contributorPHIDs !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'contributor.dst IN (%Ls)',
|
'contributor.dst IN (%Ls)',
|
||||||
$this->contributorPHIDs);
|
$this->contributorPHIDs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->signatureRequired !== null) {
|
if ($this->signatureRequired !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'd.requireSignature = %d',
|
'd.requireSignature = %d',
|
||||||
$this->signatureRequired);
|
$this->signatureRequired);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = $this->buildPagingClause($conn_r);
|
return $where;
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadDocumentBodies(array $documents) {
|
private function loadDocumentBodies(array $documents) {
|
||||||
|
@ -275,4 +266,8 @@ final class LegalpadDocumentQuery
|
||||||
return 'PhabricatorLegalpadApplication';
|
return 'PhabricatorLegalpadApplication';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getPrimaryTableAlias() {
|
||||||
|
return 'd';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue