mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +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:
parent
80f6d00940
commit
c587b8a9c8
5 changed files with 47 additions and 15 deletions
|
@ -26,8 +26,7 @@ final class PhabricatorProjectProfileController
|
|||
}
|
||||
|
||||
$profile = $project->getProfile();
|
||||
|
||||
$picture = $profile->loadProfileImageURI();
|
||||
$picture = $profile->getProfileImageURI();
|
||||
|
||||
require_celerity_resource('phabricator-profile-css');
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ final class PhabricatorProjectProfileEditController
|
|||
}
|
||||
|
||||
$profile = $project->getProfile();
|
||||
$img_src = $profile->loadProfileImageURI();
|
||||
$img_src = $profile->getProfileImageURI();
|
||||
|
||||
$options = PhabricatorProjectStatus::getStatusMap();
|
||||
|
||||
|
|
|
@ -120,11 +120,41 @@ final class PhabricatorProjectQuery
|
|||
'projectPHID IN (%Ls)',
|
||||
mpull($projects, 'getPHID'));
|
||||
$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) {
|
||||
$profile = idx($profiles, $project->getPHID());
|
||||
if (!$profile) {
|
||||
if (!$default) {
|
||||
$default = PhabricatorFile::loadBuiltin(
|
||||
$this->getViewer(),
|
||||
'profile.png');
|
||||
}
|
||||
$profile = id(new PhabricatorProjectProfile())
|
||||
->setProjectPHID($project->getPHID());
|
||||
->setProjectPHID($project->getPHID())
|
||||
->attachProfileImageFile($default);
|
||||
}
|
||||
$project->attachProfile($profile);
|
||||
}
|
||||
|
|
|
@ -6,16 +6,19 @@ final class PhabricatorProjectProfile extends PhabricatorProjectDAO {
|
|||
protected $blurb;
|
||||
protected $profileImagePHID;
|
||||
|
||||
public function loadProfileImageURI() {
|
||||
$src_phid = $this->getProfileImagePHID();
|
||||
private $profileImageFile = self::ATTACHABLE;
|
||||
|
||||
// TODO: (T603) Can we get rid of this and move it to a Query?
|
||||
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid);
|
||||
if ($file) {
|
||||
return $file->getBestURI();
|
||||
public function getProfileImageURI() {
|
||||
return $this->getProfileImageFile()->getBestURI();
|
||||
}
|
||||
|
||||
return PhabricatorUser::getDefaultProfileImageURI();
|
||||
public function attachProfileImageFile(PhabricatorFile $file) {
|
||||
$this->profileImageFile = $file;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProfileImageFile() {
|
||||
return $this->assertAttached($this->profileImageFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -231,10 +231,10 @@ final class PhabricatorTypeaheadCommonDatasourceController
|
|||
->setDisplayType("Project")
|
||||
->setURI('/project/view/'.$proj->getID().'/')
|
||||
->setPHID($proj->getPHID());
|
||||
|
||||
$prof = $proj->getProfile();
|
||||
if ($prof) {
|
||||
$proj_result->setImageURI($prof->loadProfileImageURI());
|
||||
}
|
||||
$proj_result->setImageURI($prof->getProfileImageURI());
|
||||
|
||||
$results[] = $proj_result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue