3 final class PhabricatorFileChunkQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
10 private $needDataFiles;
12 public function withChunkHandles(array $handles) {
13 $this->chunkHandles
= $handles;
17 public function withByteRange($start, $end) {
18 $this->rangeStart
= $start;
19 $this->rangeEnd
= $end;
23 public function withIsComplete($complete) {
24 $this->isComplete
= $complete;
28 public function needDataFiles($need) {
29 $this->needDataFiles
= $need;
33 protected function loadPage() {
34 $table = new PhabricatorFileChunk();
35 $conn_r = $table->establishConnection('r');
39 'SELECT * FROM %T %Q %Q %Q',
40 $table->getTableName(),
41 $this->buildWhereClause($conn_r),
42 $this->buildOrderClause($conn_r),
43 $this->buildLimitClause($conn_r));
45 return $table->loadAllFromArray($data);
48 protected function willFilterPage(array $chunks) {
50 if ($this->needDataFiles
) {
51 $file_phids = mpull($chunks, 'getDataFilePHID');
52 $file_phids = array_filter($file_phids);
54 $files = id(new PhabricatorFileQuery())
55 ->setViewer($this->getViewer())
56 ->setParentQuery($this)
57 ->withPHIDs($file_phids)
59 $files = mpull($files, null, 'getPHID');
64 foreach ($chunks as $key => $chunk) {
65 $data_phid = $chunk->getDataFilePHID();
67 $chunk->attachDataFile(null);
71 $file = idx($files, $data_phid);
74 $this->didRejectResult($chunk);
78 $chunk->attachDataFile($file);
89 protected function buildWhereClause(AphrontDatabaseConnection
$conn) {
92 if ($this->chunkHandles
!== null) {
95 'chunkHandle IN (%Ls)',
99 if ($this->rangeStart
!== null) {
106 if ($this->rangeEnd
!== null) {
113 if ($this->isComplete
!== null) {
114 if ($this->isComplete
) {
117 'dataFilePHID IS NOT NULL');
121 'dataFilePHID IS NULL');
125 $where[] = $this->buildPagingClause($conn);
127 return $this->formatWhereClause($conn, $where);
130 public function getQueryApplicationClass() {
131 return 'PhabricatorFilesApplication';