@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove all "ObjectHasFile" edge reads and writes

Summary: Ref T13603. Migrate all code which interacts with the "ObjectHasFile" edge to use the "Attachments" table instead.

Test Plan:
- Edited a paste's view policy, confirmed associated file secret was scrambled.
- Verified I could still view paste content as a user who could not naturally view the underlying file.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13603

Differential Revision: https://secure.phabricator.com/D21819

+27 -57
+1 -1
resources/sql/autopatches/20140904.macroattach.php
··· 16 16 foreach ($phids as $phid) { 17 17 $editor->addEdge( 18 18 $macro->getPHID(), 19 - PhabricatorObjectHasFileEdgeType::EDGECONST, 19 + 25, 20 20 $phid); 21 21 } 22 22 $editor->save();
+24
src/applications/files/query/PhabricatorFileQuery.php
··· 20 20 private $builtinKeys; 21 21 private $isBuiltin; 22 22 private $storageEngines; 23 + private $attachedObjectPHIDs; 23 24 24 25 public function withIDs(array $ids) { 25 26 $this->ids = $ids; ··· 58 59 59 60 public function withIsBuiltin($is_builtin) { 60 61 $this->isBuiltin = $is_builtin; 62 + return $this; 63 + } 64 + 65 + public function withAttachedObjectPHIDs(array $phids) { 66 + $this->attachedObjectPHIDs = $phids; 61 67 return $this; 62 68 } 63 69 ··· 347 353 id(new PhabricatorTransformedFile())->getTableName()); 348 354 } 349 355 356 + if ($this->shouldJoinAttachmentsTable()) { 357 + $joins[] = qsprintf( 358 + $conn, 359 + 'JOIN %R attachments ON attachments.filePHID = f.phid', 360 + new PhabricatorFileAttachment()); 361 + } 362 + 350 363 return $joins; 364 + } 365 + 366 + private function shouldJoinAttachmentsTable() { 367 + return ($this->attachedObjectPHIDs !== null); 351 368 } 352 369 353 370 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { ··· 480 497 $conn, 481 498 'storageEngine IN (%Ls)', 482 499 $this->storageEngines); 500 + } 501 + 502 + if ($this->attachedObjectPHIDs !== null) { 503 + $where[] = qsprintf( 504 + $conn, 505 + 'attachments.objectPHID IN (%Ls)', 506 + $this->attachedObjectPHIDs); 483 507 } 484 508 485 509 return $where;
-6
src/applications/files/storage/PhabricatorFile.php
··· 1416 1416 * @return this 1417 1417 */ 1418 1418 public function attachToObject($phid) { 1419 - $edge_type = PhabricatorObjectHasFileEdgeType::EDGECONST; 1420 - 1421 - id(new PhabricatorEdgeEditor()) 1422 - ->addEdge($phid, $edge_type, $this->getPHID()) 1423 - ->save(); 1424 - 1425 1419 $attachment_table = new PhabricatorFileAttachment(); 1426 1420 $attachment_conn = $attachment_table->establishConnection('w'); 1427 1421
+2 -50
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 1300 1300 } 1301 1301 1302 1302 $xactions = $this->sortTransactions($xactions); 1303 - $file_phids = $this->extractFilePHIDs($object, $xactions); 1304 1303 1305 1304 if ($is_preview) { 1306 1305 $this->loadHandles($xactions); ··· 1387 1386 $xaction->save(); 1388 1387 } 1389 1388 } 1390 - } 1391 - 1392 - if ($file_phids) { 1393 - $this->attachFiles($object, $file_phids); 1394 1389 } 1395 1390 1396 1391 foreach ($xactions as $xaction) { ··· 4353 4348 } 4354 4349 4355 4350 $phids = array_unique(array_filter(array_mergev($phids))); 4356 - if (!$phids) { 4357 - return array(); 4358 - } 4359 4351 4360 - // Only let a user attach files they can actually see, since this would 4361 - // otherwise let you access any file by attaching it to an object you have 4362 - // view permission on. 4363 - 4364 - $files = id(new PhabricatorFileQuery()) 4365 - ->setViewer($this->getActor()) 4366 - ->withPHIDs($phids) 4367 - ->execute(); 4368 - 4369 - return mpull($files, 'getPHID'); 4352 + return $phids; 4370 4353 } 4371 4354 4372 4355 /** ··· 4378 4361 return array(); 4379 4362 } 4380 4363 4381 - 4382 - /** 4383 - * @task files 4384 - */ 4385 - private function attachFiles( 4386 - PhabricatorLiskDAO $object, 4387 - array $file_phids) { 4388 - 4389 - if (!$file_phids) { 4390 - return; 4391 - } 4392 - 4393 - $editor = new PhabricatorEdgeEditor(); 4394 - 4395 - $src = $object->getPHID(); 4396 - $type = PhabricatorObjectHasFileEdgeType::EDGECONST; 4397 - foreach ($file_phids as $dst) { 4398 - $editor->addEdge($src, $type, $dst); 4399 - } 4400 - 4401 - $editor->save(); 4402 - } 4403 4364 4404 4365 private function applyInverseEdgeTransactions( 4405 4366 PhabricatorLiskDAO $object, ··· 4847 4808 } 4848 4809 } 4849 4810 4850 - $phid = $object->getPHID(); 4851 - 4852 - $attached_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 4853 - $phid, 4854 - PhabricatorObjectHasFileEdgeType::EDGECONST); 4855 - if (!$attached_phids) { 4856 - return; 4857 - } 4858 - 4859 4811 $omnipotent_viewer = PhabricatorUser::getOmnipotentUser(); 4860 4812 4861 4813 $files = id(new PhabricatorFileQuery()) 4862 4814 ->setViewer($omnipotent_viewer) 4863 - ->withPHIDs($attached_phids) 4815 + ->withAttachedObjectPHIDs(array($object->getPHID())) 4864 4816 ->execute(); 4865 4817 foreach ($files as $file) { 4866 4818 $view_policy = $file->getViewPolicy();