Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/storage/PhabricatorUser.php
| <?php | <?php | ||||
| /** | /** | ||||
| * @task availability Availability | * @task availability Availability | ||||
| * @task image-cache Profile Image Cache | * @task image-cache Profile Image Cache | ||||
| * @task factors Multi-Factor Authentication | * @task factors Multi-Factor Authentication | ||||
| * @task handles Managing Handles | * @task handles Managing Handles | ||||
| * @task cache User Cache | |||||
| */ | */ | ||||
| final class PhabricatorUser | final class PhabricatorUser | ||||
| extends PhabricatorUserDAO | extends PhabricatorUserDAO | ||||
| implements | implements | ||||
| PhutilPerson, | PhutilPerson, | ||||
| PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
| PhabricatorCustomFieldInterface, | PhabricatorCustomFieldInterface, | ||||
| PhabricatorDestructibleInterface, | PhabricatorDestructibleInterface, | ||||
| Show All 40 Lines | final class PhabricatorUser | ||||
| private $availability = self::ATTACHABLE; | private $availability = self::ATTACHABLE; | ||||
| private $preferences = null; | private $preferences = null; | ||||
| private $omnipotent = false; | private $omnipotent = false; | ||||
| private $customFields = self::ATTACHABLE; | private $customFields = self::ATTACHABLE; | ||||
| private $badgePHIDs = self::ATTACHABLE; | private $badgePHIDs = self::ATTACHABLE; | ||||
| private $alternateCSRFString = self::ATTACHABLE; | private $alternateCSRFString = self::ATTACHABLE; | ||||
| private $session = self::ATTACHABLE; | private $session = self::ATTACHABLE; | ||||
| private $rawCacheData = array(); | |||||
| private $usableCacheData = array(); | |||||
| private $authorities = array(); | private $authorities = array(); | ||||
| private $handlePool; | private $handlePool; | ||||
| private $csrfSalt; | private $csrfSalt; | ||||
| protected function readField($field) { | protected function readField($field) { | ||||
| switch ($field) { | switch ($field) { | ||||
| case 'timezoneIdentifier': | case 'timezoneIdentifier': | ||||
| ▲ Show 20 Lines • Show All 410 Lines • ▼ Show 20 Lines | final class PhabricatorUser | ||||
| public function loadPrimaryEmail() { | public function loadPrimaryEmail() { | ||||
| return $this->loadOneRelative( | return $this->loadOneRelative( | ||||
| new PhabricatorUserEmail(), | new PhabricatorUserEmail(), | ||||
| 'userPHID', | 'userPHID', | ||||
| 'getPHID', | 'getPHID', | ||||
| '(isPrimary = 1)'); | '(isPrimary = 1)'); | ||||
| } | } | ||||
| public function getUserSetting($key) { | |||||
| $settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; | |||||
| $settings = $this->requireCacheData($settings_key); | |||||
| if (array_key_exists($key, $settings)) { | |||||
| return $settings[$key]; | |||||
| } | |||||
| $defaults = PhabricatorSetting::getAllEnabledSettings($this); | |||||
| if (isset($defaults[$key])) { | |||||
| return $defaults[$key]->getSettingDefaultValue(); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| public function loadPreferences() { | public function loadPreferences() { | ||||
| if ($this->preferences) { | if ($this->preferences) { | ||||
| return $this->preferences; | return $this->preferences; | ||||
| } | } | ||||
| $preferences = null; | $preferences = null; | ||||
| if ($this->getPHID()) { | if ($this->getPHID()) { | ||||
| $preferences = id(new PhabricatorUserPreferencesQuery()) | $preferences = id(new PhabricatorUserPreferencesQuery()) | ||||
| ▲ Show 20 Lines • Show All 958 Lines • ▼ Show 20 Lines | public function getFieldValuesForConduit() { | ||||
| ); | ); | ||||
| } | } | ||||
| public function getConduitSearchAttachments() { | public function getConduitSearchAttachments() { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| /* -( User Cache )--------------------------------------------------------- */ | |||||
| /** | |||||
| * @task cache | |||||
| */ | |||||
| public function attachRawCacheData(array $data) { | |||||
| $this->rawCacheData = $data + $this->rawCacheData; | |||||
| return $this; | |||||
| } | |||||
| /** | |||||
| * @task cache | |||||
| */ | |||||
| protected function requireCacheData($key) { | |||||
| if (isset($this->usableCacheData[$key])) { | |||||
| return $this->usableCacheData[$key]; | |||||
| } | |||||
| $type = PhabricatorUserCacheType::requireCacheTypeForKey($key); | |||||
| if (isset($this->rawCacheData[$key])) { | |||||
| $raw_value = $this->rawCacheData[$key]; | |||||
| $usable_value = $type->getValueFromStorage($raw_value); | |||||
| $this->usableCacheData[$key] = $usable_value; | |||||
| return $usable_value; | |||||
| } | |||||
| $usable_value = $type->getDefaultValue(); | |||||
| $user_phid = $this->getPHID(); | |||||
| if ($user_phid) { | |||||
| $map = $type->newValueForUsers($key, array($this)); | |||||
| if (array_key_exists($user_phid, $map)) { | |||||
| $usable_value = $map[$user_phid]; | |||||
| $raw_value = $type->getValueForStorage($usable_value); | |||||
| $this->rawCacheData[$key] = $raw_value; | |||||
| PhabricatorUserCache::writeCache( | |||||
| $type, | |||||
| $key, | |||||
| $user_phid, | |||||
| $raw_value); | |||||
| } | |||||
| } | |||||
| $this->usableCacheData[$key] = $usable_value; | |||||
| return $usable_value; | |||||
| } | |||||
| } | } | ||||