1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 09:20:58 +01:00

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
This commit is contained in:
epriestley 2013-10-06 17:07:43 -07:00
parent 80f6d00940
commit c587b8a9c8
5 changed files with 47 additions and 15 deletions

View file

@ -26,8 +26,7 @@ final class PhabricatorProjectProfileController
} }
$profile = $project->getProfile(); $profile = $project->getProfile();
$picture = $profile->getProfileImageURI();
$picture = $profile->loadProfileImageURI();
require_celerity_resource('phabricator-profile-css'); require_celerity_resource('phabricator-profile-css');

View file

@ -29,7 +29,7 @@ final class PhabricatorProjectProfileEditController
} }
$profile = $project->getProfile(); $profile = $project->getProfile();
$img_src = $profile->loadProfileImageURI(); $img_src = $profile->getProfileImageURI();
$options = PhabricatorProjectStatus::getStatusMap(); $options = PhabricatorProjectStatus::getStatusMap();

View file

@ -120,11 +120,41 @@ final class PhabricatorProjectQuery
'projectPHID IN (%Ls)', 'projectPHID IN (%Ls)',
mpull($projects, 'getPHID')); mpull($projects, 'getPHID'));
$profiles = mpull($profiles, null, 'getProjectPHID'); $profiles = mpull($profiles, null, 'getProjectPHID');
$default = null;
if ($profiles) {
$file_phids = mpull($profiles, 'getProfileImagePHID');
$files = id(new PhabricatorFileQuery())
->setViewer($this->getViewer())
->withPHIDs($file_phids)
->execute();
$files = mpull($files, null, 'getPHID');
foreach ($profiles as $profile) {
$file = idx($files, $profile->getProfileImagePHID());
if (!$file) {
if (!$default) {
$default = PhabricatorFile::loadBuiltin(
$this->getViewer(),
'profile.png');
}
$file = $default;
}
$profile->attachProfileImageFile($file);
}
}
foreach ($projects as $project) { foreach ($projects as $project) {
$profile = idx($profiles, $project->getPHID()); $profile = idx($profiles, $project->getPHID());
if (!$profile) { if (!$profile) {
if (!$default) {
$default = PhabricatorFile::loadBuiltin(
$this->getViewer(),
'profile.png');
}
$profile = id(new PhabricatorProjectProfile()) $profile = id(new PhabricatorProjectProfile())
->setProjectPHID($project->getPHID()); ->setProjectPHID($project->getPHID())
->attachProfileImageFile($default);
} }
$project->attachProfile($profile); $project->attachProfile($profile);
} }

View file

@ -6,16 +6,19 @@ final class PhabricatorProjectProfile extends PhabricatorProjectDAO {
protected $blurb; protected $blurb;
protected $profileImagePHID; protected $profileImagePHID;
public function loadProfileImageURI() { private $profileImageFile = self::ATTACHABLE;
$src_phid = $this->getProfileImagePHID();
// TODO: (T603) Can we get rid of this and move it to a Query? public function getProfileImageURI() {
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid); return $this->getProfileImageFile()->getBestURI();
if ($file) {
return $file->getBestURI();
} }
return PhabricatorUser::getDefaultProfileImageURI(); public function attachProfileImageFile(PhabricatorFile $file) {
$this->profileImageFile = $file;
return $this;
}
public function getProfileImageFile() {
return $this->assertAttached($this->profileImageFile);
} }
} }

View file

@ -231,10 +231,10 @@ final class PhabricatorTypeaheadCommonDatasourceController
->setDisplayType("Project") ->setDisplayType("Project")
->setURI('/project/view/'.$proj->getID().'/') ->setURI('/project/view/'.$proj->getID().'/')
->setPHID($proj->getPHID()); ->setPHID($proj->getPHID());
$prof = $proj->getProfile(); $prof = $proj->getProfile();
if ($prof) { $proj_result->setImageURI($prof->getProfileImageURI());
$proj_result->setImageURI($prof->loadProfileImageURI());
}
$results[] = $proj_result; $results[] = $proj_result;
} }
} }