@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 "PhabricatorFile->detachFromObject()"

Summary:
Ref T13603. Currently, files are sometimes detached from objects. For example, when you change the image for a Macro, the old image is detached.

This is wrong: the image should remain attached so users who can view the macro can view the complete "alice change the image from X to Y" transaction. To be able to understand the change that was applied, you need to be able to view both files.

All workflows which currently detach files aren't conistent with the modern way applications behave, except maybe one callsite in a unit test, and that one's kind of moot.

Get rid of this stuff and just use PHID extraction to perform file attachment in all cases.

Test Plan: Created and edited macros, verified files were properly attached and remained attached across edits.

Maniphest Tasks: T13603

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

+7 -106
-17
src/applications/files/storage/PhabricatorFile.php
··· 1427 1427 1428 1428 1429 1429 /** 1430 - * Remove the policy edge between this file and some object. 1431 - * 1432 - * @param phid Object PHID to detach from. 1433 - * @return this 1434 - */ 1435 - public function detachFromObject($phid) { 1436 - $edge_type = PhabricatorObjectHasFileEdgeType::EDGECONST; 1437 - 1438 - id(new PhabricatorEdgeEditor()) 1439 - ->removeEdge($phid, $edge_type, $this->getPHID()) 1440 - ->save(); 1441 - 1442 - return $this; 1443 - } 1444 - 1445 - 1446 - /** 1447 1430 * Configure a newly created file object according to specified parameters. 1448 1431 * 1449 1432 * This method is called both when creating a file from fresh data, and
-12
src/applications/files/storage/__tests__/PhabricatorFileTestCase.php
··· 224 224 ), 225 225 $this->canViewFile($users, $xform), 226 226 pht('Attached Thumbnail Visibility')); 227 - 228 - // Detach the object and make sure it affects the thumbnail. 229 - $file->detachFromObject($object->getPHID()); 230 - 231 - // Test the detached thumbnail's visibility. 232 - $this->assertEqual( 233 - array( 234 - true, 235 - false, 236 - ), 237 - $this->canViewFile($users, $xform), 238 - pht('Detached Thumbnail Visibility')); 239 227 } 240 228 241 229 private function canViewFile(array $users, PhabricatorFile $file) {
+5 -23
src/applications/macro/xaction/PhabricatorMacroAudioTransaction.php
··· 13 13 $object->setAudioPHID($value); 14 14 } 15 15 16 - public function applyExternalEffects($object, $value) { 17 - $old = $this->generateOldValue($object); 18 - $new = $value; 19 - $all = array(); 20 - if ($old) { 21 - $all[] = $old; 22 - } 23 - if ($new) { 24 - $all[] = $new; 25 - } 26 - 27 - $files = id(new PhabricatorFileQuery()) 28 - ->setViewer($this->getActor()) 29 - ->withPHIDs($all) 30 - ->execute(); 31 - $files = mpull($files, null, 'getPHID'); 16 + public function extractFilePHIDs($object, $value) { 17 + $file_phids = array(); 32 18 33 - $old_file = idx($files, $old); 34 - if ($old_file) { 35 - $old_file->detachFromObject($object->getPHID()); 19 + if ($value) { 20 + $file_phids[] = $value; 36 21 } 37 22 38 - $new_file = idx($files, $new); 39 - if ($new_file) { 40 - $new_file->attachToObject($object->getPHID()); 41 - } 23 + return $file_phids; 42 24 } 43 25 44 26 public function getTitle() {
+2 -26
src/applications/macro/xaction/PhabricatorMacroFileTransaction.php
··· 13 13 $object->setFilePHID($value); 14 14 } 15 15 16 - public function applyExternalEffects($object, $value) { 17 - $old = $this->generateOldValue($object); 18 - $new = $value; 19 - $all = array(); 20 - if ($old) { 21 - $all[] = $old; 22 - } 23 - if ($new) { 24 - $all[] = $new; 25 - } 26 - 27 - $files = id(new PhabricatorFileQuery()) 28 - ->setViewer($this->getActor()) 29 - ->withPHIDs($all) 30 - ->execute(); 31 - $files = mpull($files, null, 'getPHID'); 32 - 33 - $old_file = idx($files, $old); 34 - if ($old_file) { 35 - $old_file->detachFromObject($object->getPHID()); 36 - } 37 - 38 - $new_file = idx($files, $new); 39 - if ($new_file) { 40 - $new_file->attachToObject($object->getPHID()); 41 - } 16 + public function extractFilePHIDs($object, $value) { 17 + return array($value); 42 18 } 43 19 44 20 public function getTitle() {
-28
src/applications/project/xaction/PhabricatorProjectImageTransaction.php
··· 13 13 $object->setProfileImagePHID($value); 14 14 } 15 15 16 - public function applyExternalEffects($object, $value) { 17 - $old = $this->getOldValue(); 18 - $new = $value; 19 - $all = array(); 20 - if ($old) { 21 - $all[] = $old; 22 - } 23 - if ($new) { 24 - $all[] = $new; 25 - } 26 - 27 - $files = id(new PhabricatorFileQuery()) 28 - ->setViewer($this->getActor()) 29 - ->withPHIDs($all) 30 - ->execute(); 31 - $files = mpull($files, null, 'getPHID'); 32 - 33 - $old_file = idx($files, $old); 34 - if ($old_file) { 35 - $old_file->detachFromObject($object->getPHID()); 36 - } 37 - 38 - $new_file = idx($files, $new); 39 - if ($new_file) { 40 - $new_file->attachToObject($object->getPHID()); 41 - } 42 - } 43 - 44 16 public function getTitle() { 45 17 $old = $this->getOldValue(); 46 18 $new = $this->getNewValue();