@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 `ProjectProfile->loadProfileImageURI()`

Summary: Ref T603. Gets rid of a sketchy, non-policy-aware, unbatched file query.

Test Plan: Looked at projects, typeahead, edited project profile images.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

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

+47 -15
+1 -2
src/applications/project/controller/PhabricatorProjectProfileController.php
··· 26 26 } 27 27 28 28 $profile = $project->getProfile(); 29 - 30 - $picture = $profile->loadProfileImageURI(); 29 + $picture = $profile->getProfileImageURI(); 31 30 32 31 require_celerity_resource('phabricator-profile-css'); 33 32
+1 -1
src/applications/project/controller/PhabricatorProjectProfileEditController.php
··· 29 29 } 30 30 31 31 $profile = $project->getProfile(); 32 - $img_src = $profile->loadProfileImageURI(); 32 + $img_src = $profile->getProfileImageURI(); 33 33 34 34 $options = PhabricatorProjectStatus::getStatusMap(); 35 35
+31 -1
src/applications/project/query/PhabricatorProjectQuery.php
··· 120 120 'projectPHID IN (%Ls)', 121 121 mpull($projects, 'getPHID')); 122 122 $profiles = mpull($profiles, null, 'getProjectPHID'); 123 + 124 + $default = null; 125 + 126 + if ($profiles) { 127 + $file_phids = mpull($profiles, 'getProfileImagePHID'); 128 + $files = id(new PhabricatorFileQuery()) 129 + ->setViewer($this->getViewer()) 130 + ->withPHIDs($file_phids) 131 + ->execute(); 132 + $files = mpull($files, null, 'getPHID'); 133 + foreach ($profiles as $profile) { 134 + $file = idx($files, $profile->getProfileImagePHID()); 135 + if (!$file) { 136 + if (!$default) { 137 + $default = PhabricatorFile::loadBuiltin( 138 + $this->getViewer(), 139 + 'profile.png'); 140 + } 141 + $file = $default; 142 + } 143 + $profile->attachProfileImageFile($file); 144 + } 145 + } 146 + 123 147 foreach ($projects as $project) { 124 148 $profile = idx($profiles, $project->getPHID()); 125 149 if (!$profile) { 150 + if (!$default) { 151 + $default = PhabricatorFile::loadBuiltin( 152 + $this->getViewer(), 153 + 'profile.png'); 154 + } 126 155 $profile = id(new PhabricatorProjectProfile()) 127 - ->setProjectPHID($project->getPHID()); 156 + ->setProjectPHID($project->getPHID()) 157 + ->attachProfileImageFile($default); 128 158 } 129 159 $project->attachProfile($profile); 130 160 }
+11 -8
src/applications/project/storage/PhabricatorProjectProfile.php
··· 6 6 protected $blurb; 7 7 protected $profileImagePHID; 8 8 9 - public function loadProfileImageURI() { 10 - $src_phid = $this->getProfileImagePHID(); 9 + private $profileImageFile = self::ATTACHABLE; 11 10 12 - // TODO: (T603) Can we get rid of this and move it to a Query? 13 - $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid); 14 - if ($file) { 15 - return $file->getBestURI(); 16 - } 11 + public function getProfileImageURI() { 12 + return $this->getProfileImageFile()->getBestURI(); 13 + } 14 + 15 + public function attachProfileImageFile(PhabricatorFile $file) { 16 + $this->profileImageFile = $file; 17 + return $this; 18 + } 17 19 18 - return PhabricatorUser::getDefaultProfileImageURI(); 20 + public function getProfileImageFile() { 21 + return $this->assertAttached($this->profileImageFile); 19 22 } 20 23 21 24 }
+3 -3
src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
··· 231 231 ->setDisplayType("Project") 232 232 ->setURI('/project/view/'.$proj->getID().'/') 233 233 ->setPHID($proj->getPHID()); 234 + 234 235 $prof = $proj->getProfile(); 235 - if ($prof) { 236 - $proj_result->setImageURI($prof->loadProfileImageURI()); 237 - } 236 + $proj_result->setImageURI($prof->getProfileImageURI()); 237 + 238 238 $results[] = $proj_result; 239 239 } 240 240 }