Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/query/PhabricatorFileQuery.php
| Show All 9 Lines | final class PhabricatorFileQuery | ||||
| private $transforms; | private $transforms; | ||||
| private $dateCreatedAfter; | private $dateCreatedAfter; | ||||
| private $dateCreatedBefore; | private $dateCreatedBefore; | ||||
| private $contentHashes; | private $contentHashes; | ||||
| private $minLength; | private $minLength; | ||||
| private $maxLength; | private $maxLength; | ||||
| private $names; | private $names; | ||||
| private $isPartial; | private $isPartial; | ||||
| private $needTransforms; | |||||
| public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
| $this->phids = $phids; | $this->phids = $phids; | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | public function withIsPartial($partial) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function showOnlyExplicitUploads($explicit_uploads) { | public function showOnlyExplicitUploads($explicit_uploads) { | ||||
| $this->explicitUploads = $explicit_uploads; | $this->explicitUploads = $explicit_uploads; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needTransforms(array $transforms) { | |||||
| $this->needTransforms = $transforms; | |||||
| return $this; | |||||
| } | |||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new PhabricatorFile(); | return new PhabricatorFile(); | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| $files = $this->loadStandardPage(new PhabricatorFile()); | $files = $this->loadStandardPage(new PhabricatorFile()); | ||||
| if (!$files) { | if (!$files) { | ||||
| ▲ Show 20 Lines • Show All 85 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 didFilterPage(array $files) { | |||||
| $xform_keys = $this->needTransforms; | |||||
| if ($xform_keys !== null) { | |||||
| $xforms = id(new PhabricatorTransformedFile())->loadAllWhere( | |||||
| 'originalPHID IN (%Ls) AND transform IN (%Ls)', | |||||
| mpull($files, 'getPHID'), | |||||
| $xform_keys); | |||||
| if ($xforms) { | |||||
| $xfiles = id(new PhabricatorFile())->loadAllWhere( | |||||
| 'phid IN (%Ls)', | |||||
| mpull($xforms, 'getTransformedPHID')); | |||||
| $xfiles = mpull($xfiles, null, 'getPHID'); | |||||
| } | |||||
| $xform_map = array(); | |||||
| foreach ($xforms as $xform) { | |||||
| $xfile = idx($xfiles, $xform->getTransformedPHID()); | |||||
| if (!$xfile) { | |||||
| continue; | |||||
| } | |||||
| $original_phid = $xform->getOriginalPHID(); | |||||
| $xform_key = $xform->getTransform(); | |||||
| $xform_map[$original_phid][$xform_key] = $xfile; | |||||
| } | |||||
| $default_xforms = array_fill_keys($xform_keys, null); | |||||
| foreach ($files as $file) { | |||||
| $file_xforms = idx($xform_map, $file->getPHID(), array()); | |||||
| $file_xforms += $default_xforms; | |||||
| $file->attachTransforms($file_xforms); | |||||
| } | |||||
| } | |||||
| return $files; | |||||
| } | |||||
| protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $joins = parent::buildJoinClauseParts($conn); | $joins = parent::buildJoinClauseParts($conn); | ||||
| if ($this->transforms) { | if ($this->transforms) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn, | $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()); | ||||
| ▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines | |||||