Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/query/PhabricatorFileQuery.php
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | final class PhabricatorFileQuery | ||||
} | } | ||||
public function showOnlyExplicitUploads($explicit_uploads) { | public function showOnlyExplicitUploads($explicit_uploads) { | ||||
$this->explicitUploads = $explicit_uploads; | $this->explicitUploads = $explicit_uploads; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
$table = new PhabricatorFile(); | $files = $this->loadStandardPage(new PhabricatorFile()); | ||||
$conn_r = $table->establishConnection('r'); | |||||
$data = queryfx_all( | |||||
$conn_r, | |||||
'SELECT f.* FROM %T f %Q %Q %Q %Q', | |||||
$table->getTableName(), | |||||
$this->buildJoinClause($conn_r), | |||||
$this->buildWhereClause($conn_r), | |||||
$this->buildOrderClause($conn_r), | |||||
$this->buildLimitClause($conn_r)); | |||||
$files = $table->loadAllFromArray($data); | |||||
if (!$files) { | if (!$files) { | ||||
return $files; | return $files; | ||||
} | } | ||||
// We need to load attached objects to perform policy checks for files. | // We need to load attached objects to perform policy checks for files. | ||||
// First, load the edges. | // First, load the edges. | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | foreach ($files as $key => $file) { | ||||
$original = null; | $original = null; | ||||
} | } | ||||
$file->attachOriginalFile($original); | $file->attachOriginalFile($original); | ||||
} | } | ||||
return $files; | return $files; | ||||
} | } | ||||
protected function buildJoinClause(AphrontDatabaseConnection $conn_r) { | protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | ||||
$joins = array(); | $joins = parent::buildJoinClauseParts($conn); | ||||
if ($this->transforms) { | if ($this->transforms) { | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'JOIN %T t ON t.transformedPHID = f.phid', | 'JOIN %T t ON t.transformedPHID = f.phid', | ||||
id(new PhabricatorTransformedFile())->getTableName()); | id(new PhabricatorTransformedFile())->getTableName()); | ||||
} | } | ||||
return implode(' ', $joins); | return $joins; | ||||
} | } | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
$where[] = $this->buildPagingClause($conn_r); | |||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'f.id IN (%Ld)', | 'f.id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'f.phid IN (%Ls)', | 'f.phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->authorPHIDs !== null) { | if ($this->authorPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'f.authorPHID IN (%Ls)', | 'f.authorPHID IN (%Ls)', | ||||
$this->authorPHIDs); | $this->authorPHIDs); | ||||
} | } | ||||
if ($this->explicitUploads !== null) { | if ($this->explicitUploads !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'f.isExplicitUpload = true'); | 'f.isExplicitUpload = %d', | ||||
(int)$this->explicitUploads); | |||||
} | } | ||||
if ($this->transforms !== null) { | if ($this->transforms !== null) { | ||||
$clauses = array(); | $clauses = array(); | ||||
foreach ($this->transforms as $transform) { | foreach ($this->transforms as $transform) { | ||||
if ($transform['transform'] === true) { | if ($transform['transform'] === true) { | ||||
$clauses[] = qsprintf( | $clauses[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'(t.originalPHID = %s)', | '(t.originalPHID = %s)', | ||||
$transform['originalPHID']); | $transform['originalPHID']); | ||||
} else { | } else { | ||||
$clauses[] = qsprintf( | $clauses[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'(t.originalPHID = %s AND t.transform = %s)', | '(t.originalPHID = %s AND t.transform = %s)', | ||||
$transform['originalPHID'], | $transform['originalPHID'], | ||||
$transform['transform']); | $transform['transform']); | ||||
} | } | ||||
} | } | ||||
$where[] = qsprintf($conn_r, '(%Q)', implode(') OR (', $clauses)); | $where[] = qsprintf($conn, '(%Q)', implode(') OR (', $clauses)); | ||||
} | } | ||||
if ($this->dateCreatedAfter !== null) { | if ($this->dateCreatedAfter !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'f.dateCreated >= %d', | 'f.dateCreated >= %d', | ||||
$this->dateCreatedAfter); | $this->dateCreatedAfter); | ||||
} | } | ||||
if ($this->dateCreatedBefore !== null) { | if ($this->dateCreatedBefore !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'f.dateCreated <= %d', | 'f.dateCreated <= %d', | ||||
$this->dateCreatedBefore); | $this->dateCreatedBefore); | ||||
} | } | ||||
if ($this->contentHashes !== null) { | if ($this->contentHashes !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'f.contentHash IN (%Ls)', | 'f.contentHash IN (%Ls)', | ||||
$this->contentHashes); | $this->contentHashes); | ||||
} | } | ||||
if ($this->minLength !== null) { | if ($this->minLength !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'byteSize >= %d', | 'byteSize >= %d', | ||||
$this->minLength); | $this->minLength); | ||||
} | } | ||||
if ($this->maxLength !== null) { | if ($this->maxLength !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'byteSize <= %d', | 'byteSize <= %d', | ||||
$this->maxLength); | $this->maxLength); | ||||
} | } | ||||
if ($this->names !== null) { | if ($this->names !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'name in (%Ls)', | 'name in (%Ls)', | ||||
$this->names); | $this->names); | ||||
} | } | ||||
if ($this->isPartial !== null) { | if ($this->isPartial !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'isPartial = %d', | 'isPartial = %d', | ||||
(int)$this->isPartial); | (int)$this->isPartial); | ||||
} | } | ||||
return $this->formatWhereClause($where); | return $where; | ||||
} | } | ||||
protected function getPrimaryTableAlias() { | protected function getPrimaryTableAlias() { | ||||
return 'f'; | return 'f'; | ||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorFilesApplication'; | return 'PhabricatorFilesApplication'; | ||||
} | } | ||||
} | } |