protected function didFilterPage(array $users) { if ($this->needProfile) { $user_list = mpull($users, null, 'getPHID'); $profiles = new PhabricatorUserProfile(); $profiles = $profiles->loadAllWhere('userPHID IN (%Ls)', array_keys($user_list)); $profiles = mpull($profiles, null, 'getUserPHID'); foreach ($user_list as $user_phid => $user) { $profile = idx($profiles, $user_phid); if (!$profile) { $profile = PhabricatorUserProfile::initializeNewProfile($user); } $user->attachUserProfile($profile); } } if ($this->needBadges) { $awards = id(new PhabricatorBadgesAwardQuery())->setViewer($this->getViewer())->withRecipientPHIDs(mpull($users, 'getPHID'))->execute(); $awards = mgroup($awards, 'getRecipientPHID'); foreach ($users as $user) { $user_awards = idx($awards, $user->getPHID(), array()); $badge_phids = mpull($user_awards, 'getBadgePHID'); $user->attachBadgePHIDs($badge_phids); } } if ($this->needAvailability) { $rebuild = array(); foreach ($users as $user) { $cache = $user->getAvailabilityCache(); if ($cache !== null) { $user->attachAvailability($cache); } else { $rebuild[] = $user; } } if ($rebuild) { $this->rebuildAvailabilityCache($rebuild); } } $this->fillUserCaches($users); return $users; }
public function loadUserProfile() { if ($this->profile) { return $this->profile; } $profile_dao = new PhabricatorUserProfile(); $this->profile = $profile_dao->loadOneWhere('userPHID = %s', $this->getPHID()); if (!$this->profile) { $this->profile = PhabricatorUserProfile::initializeNewProfile($this); } return $this->profile; }
protected function didFilterPage(array $users) { if ($this->needProfile) { $user_list = mpull($users, null, 'getPHID'); $profiles = new PhabricatorUserProfile(); $profiles = $profiles->loadAllWhere('userPHID IN (%Ls)', array_keys($user_list)); $profiles = mpull($profiles, null, 'getUserPHID'); foreach ($user_list as $user_phid => $user) { $profile = idx($profiles, $user_phid); if (!$profile) { $profile = PhabricatorUserProfile::initializeNewProfile($user); } $user->attachUserProfile($profile); } } if ($this->needBadges) { $edge_query = id(new PhabricatorEdgeQuery())->withSourcePHIDs(mpull($users, 'getPHID'))->withEdgeTypes(array(PhabricatorRecipientHasBadgeEdgeType::EDGECONST)); $edge_query->execute(); foreach ($users as $user) { $phids = $edge_query->getDestinationPHIDs(array($user->getPHID())); $user->attachBadgePHIDs($phids); } } if ($this->needProfileImage) { $rebuild = array(); foreach ($users as $user) { $image_uri = $user->getProfileImageCache(); if ($image_uri) { // This user has a valid cache, so we don't need to fetch any // data or rebuild anything. $user->attachProfileImageURI($image_uri); continue; } // This user's cache is invalid or missing, so we're going to rebuild // it. $rebuild[] = $user; } if ($rebuild) { $file_phids = mpull($rebuild, 'getProfileImagePHID'); $file_phids = array_filter($file_phids); if ($file_phids) { // NOTE: We're using the omnipotent user here because older profile // images do not have the 'profile' flag, so they may not be visible // to the executing viewer. At some point, we could migrate to add // this flag and then use the real viewer, or just use the real // viewer after enough time has passed to limit the impact of old // data. The consequence of missing here is that we cache a default // image when a real image exists. $files = id(new PhabricatorFileQuery())->setParentQuery($this)->setViewer(PhabricatorUser::getOmnipotentUser())->withPHIDs($file_phids)->execute(); $files = mpull($files, null, 'getPHID'); } else { $files = array(); } foreach ($rebuild as $user) { $image_phid = $user->getProfileImagePHID(); if (isset($files[$image_phid])) { $image_uri = $files[$image_phid]->getBestURI(); } else { $image_uri = PhabricatorUser::getDefaultProfileImageURI(); } $user->writeProfileImageCache($image_uri); $user->attachProfileImageURI($image_uri); } } } if ($this->needAvailability) { $rebuild = array(); foreach ($users as $user) { $cache = $user->getAvailabilityCache(); if ($cache !== null) { $user->attachAvailability($cache); } else { $rebuild[] = $user; } } if ($rebuild) { $this->rebuildAvailabilityCache($rebuild); } } return $users; }