Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/query/PhabricatorFileQuery.php
Show First 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | final class PhabricatorFileQuery | ||||
private function newAttachmentsMap(array $files) { | private function newAttachmentsMap(array $files) { | ||||
$file_phids = mpull($files, 'getPHID'); | $file_phids = mpull($files, 'getPHID'); | ||||
$attachments_table = new PhabricatorFileAttachment(); | $attachments_table = new PhabricatorFileAttachment(); | ||||
$attachments_conn = $attachments_table->establishConnection('r'); | $attachments_conn = $attachments_table->establishConnection('r'); | ||||
$attachments = queryfx_all( | $attachments = queryfx_all( | ||||
$attachments_conn, | $attachments_conn, | ||||
'SELECT filePHID, objectPHID FROM %R WHERE filePHID IN (%Ls)', | 'SELECT filePHID, objectPHID FROM %R WHERE filePHID IN (%Ls) | ||||
AND attachmentMode IN (%Ls)', | |||||
$attachments_table, | $attachments_table, | ||||
$file_phids); | $file_phids, | ||||
array( | |||||
PhabricatorFileAttachment::MODE_ATTACH, | |||||
)); | |||||
$attachments_map = array_fill_keys($file_phids, array()); | $attachments_map = array_fill_keys($file_phids, array()); | ||||
foreach ($attachments as $row) { | foreach ($attachments as $row) { | ||||
$file_phid = $row['filePHID']; | $file_phid = $row['filePHID']; | ||||
$object_phid = $row['objectPHID']; | $object_phid = $row['objectPHID']; | ||||
$attachments_map[$file_phid][] = $object_phid; | $attachments_map[$file_phid][] = $object_phid; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if ($this->transforms) { | ||||
$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()); | ||||
} | } | ||||
if ($this->shouldJoinAttachmentsTable()) { | if ($this->shouldJoinAttachmentsTable()) { | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn, | $conn, | ||||
'JOIN %R attachments ON attachments.filePHID = f.phid', | 'JOIN %R attachments ON attachments.filePHID = f.phid | ||||
new PhabricatorFileAttachment()); | AND attachmentMode IN (%Ls)', | ||||
new PhabricatorFileAttachment(), | |||||
array( | |||||
PhabricatorFileAttachment::MODE_ATTACH, | |||||
)); | |||||
} | } | ||||
return $joins; | return $joins; | ||||
} | } | ||||
private function shouldJoinAttachmentsTable() { | private function shouldJoinAttachmentsTable() { | ||||
return ($this->attachedObjectPHIDs !== null); | return ($this->attachedObjectPHIDs !== null); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |