diff --git a/src/applications/project/controller/PhabricatorProjectProfileController.php b/src/applications/project/controller/PhabricatorProjectProfileController.php index 953cbb5c11..42dc88ab03 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileController.php @@ -26,8 +26,7 @@ final class PhabricatorProjectProfileController } $profile = $project->getProfile(); - - $picture = $profile->loadProfileImageURI(); + $picture = $profile->getProfileImageURI(); require_celerity_resource('phabricator-profile-css'); diff --git a/src/applications/project/controller/PhabricatorProjectProfileEditController.php b/src/applications/project/controller/PhabricatorProjectProfileEditController.php index 608438ce96..d482afbc5c 100644 --- a/src/applications/project/controller/PhabricatorProjectProfileEditController.php +++ b/src/applications/project/controller/PhabricatorProjectProfileEditController.php @@ -29,7 +29,7 @@ final class PhabricatorProjectProfileEditController } $profile = $project->getProfile(); - $img_src = $profile->loadProfileImageURI(); + $img_src = $profile->getProfileImageURI(); $options = PhabricatorProjectStatus::getStatusMap(); diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index 0f4c6440e2..00f6ead387 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -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); } diff --git a/src/applications/project/storage/PhabricatorProjectProfile.php b/src/applications/project/storage/PhabricatorProjectProfile.php index ee8f42abea..57c835761f 100644 --- a/src/applications/project/storage/PhabricatorProjectProfile.php +++ b/src/applications/project/storage/PhabricatorProjectProfile.php @@ -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); } } diff --git a/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php b/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php index 74a4f35563..ce2bcce99f 100644 --- a/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php +++ b/src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php @@ -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; } }