Page MenuHomePhabricator

D21819.id52027.diff
No OneTemporary

D21819.id52027.diff

diff --git a/resources/sql/autopatches/20140904.macroattach.php b/resources/sql/autopatches/20140904.macroattach.php
--- a/resources/sql/autopatches/20140904.macroattach.php
+++ b/resources/sql/autopatches/20140904.macroattach.php
@@ -16,7 +16,7 @@
foreach ($phids as $phid) {
$editor->addEdge(
$macro->getPHID(),
- PhabricatorObjectHasFileEdgeType::EDGECONST,
+ 25,
$phid);
}
$editor->save();
diff --git a/src/applications/files/query/PhabricatorFileQuery.php b/src/applications/files/query/PhabricatorFileQuery.php
--- a/src/applications/files/query/PhabricatorFileQuery.php
+++ b/src/applications/files/query/PhabricatorFileQuery.php
@@ -20,6 +20,7 @@
private $builtinKeys;
private $isBuiltin;
private $storageEngines;
+ private $attachedObjectPHIDs;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -61,6 +62,11 @@
return $this;
}
+ public function withAttachedObjectPHIDs(array $phids) {
+ $this->attachedObjectPHIDs = $phids;
+ return $this;
+ }
+
/**
* Select files which are transformations of some other file. For example,
* you can use this query to find previously generated thumbnails of an image
@@ -347,9 +353,20 @@
id(new PhabricatorTransformedFile())->getTableName());
}
+ if ($this->shouldJoinAttachmentsTable()) {
+ $joins[] = qsprintf(
+ $conn,
+ 'JOIN %R attachments ON attachments.filePHID = f.phid',
+ new PhabricatorFileAttachment());
+ }
+
return $joins;
}
+ private function shouldJoinAttachmentsTable() {
+ return ($this->attachedObjectPHIDs !== null);
+ }
+
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
@@ -482,6 +499,13 @@
$this->storageEngines);
}
+ if ($this->attachedObjectPHIDs !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'attachments.objectPHID IN (%Ls)',
+ $this->attachedObjectPHIDs);
+ }
+
return $where;
}
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -1416,12 +1416,6 @@
* @return this
*/
public function attachToObject($phid) {
- $edge_type = PhabricatorObjectHasFileEdgeType::EDGECONST;
-
- id(new PhabricatorEdgeEditor())
- ->addEdge($phid, $edge_type, $this->getPHID())
- ->save();
-
$attachment_table = new PhabricatorFileAttachment();
$attachment_conn = $attachment_table->establishConnection('w');
diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
--- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
+++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
@@ -1300,7 +1300,6 @@
}
$xactions = $this->sortTransactions($xactions);
- $file_phids = $this->extractFilePHIDs($object, $xactions);
if ($is_preview) {
$this->loadHandles($xactions);
@@ -1389,10 +1388,6 @@
}
}
- if ($file_phids) {
- $this->attachFiles($object, $file_phids);
- }
-
foreach ($xactions as $xaction) {
$this->applyExternalEffects($object, $xaction);
}
@@ -4353,20 +4348,8 @@
}
$phids = array_unique(array_filter(array_mergev($phids)));
- if (!$phids) {
- return array();
- }
-
- // Only let a user attach files they can actually see, since this would
- // otherwise let you access any file by attaching it to an object you have
- // view permission on.
- $files = id(new PhabricatorFileQuery())
- ->setViewer($this->getActor())
- ->withPHIDs($phids)
- ->execute();
-
- return mpull($files, 'getPHID');
+ return $phids;
}
/**
@@ -4379,28 +4362,6 @@
}
- /**
- * @task files
- */
- private function attachFiles(
- PhabricatorLiskDAO $object,
- array $file_phids) {
-
- if (!$file_phids) {
- return;
- }
-
- $editor = new PhabricatorEdgeEditor();
-
- $src = $object->getPHID();
- $type = PhabricatorObjectHasFileEdgeType::EDGECONST;
- foreach ($file_phids as $dst) {
- $editor->addEdge($src, $type, $dst);
- }
-
- $editor->save();
- }
-
private function applyInverseEdgeTransactions(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction,
@@ -4847,20 +4808,11 @@
}
}
- $phid = $object->getPHID();
-
- $attached_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
- $phid,
- PhabricatorObjectHasFileEdgeType::EDGECONST);
- if (!$attached_phids) {
- return;
- }
-
$omnipotent_viewer = PhabricatorUser::getOmnipotentUser();
$files = id(new PhabricatorFileQuery())
->setViewer($omnipotent_viewer)
- ->withPHIDs($attached_phids)
+ ->withAttachedObjectPHIDs(array($object->getPHID()))
->execute();
foreach ($files as $file) {
$view_policy = $file->getViewPolicy();

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 11:12 AM (6 d, 3 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7582113
Default Alt Text
D21819.id52027.diff (5 KB)

Event Timeline