Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/query/PhabricatorExternalAccountQuery.php
| Show All 9 Lines | |||||
| * interact directly with objects and can leave comments, sign documents, etc. | * interact directly with objects and can leave comments, sign documents, etc. | ||||
| * However, CAN_EDIT is restricted to users who own the accounts. | * However, CAN_EDIT is restricted to users who own the accounts. | ||||
| */ | */ | ||||
| final class PhabricatorExternalAccountQuery | final class PhabricatorExternalAccountQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $accountIDs; | |||||
| private $userPHIDs; | private $userPHIDs; | ||||
| private $needImages; | private $needImages; | ||||
| private $accountSecrets; | private $accountSecrets; | ||||
| private $providerConfigPHIDs; | private $providerConfigPHIDs; | ||||
| private $needAccountIdentifiers; | private $needAccountIdentifiers; | ||||
| private $rawAccountIdentifiers; | |||||
| public function withUserPHIDs(array $user_phids) { | public function withUserPHIDs(array $user_phids) { | ||||
| $this->userPHIDs = $user_phids; | $this->userPHIDs = $user_phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withAccountIDs(array $account_ids) { | |||||
| $this->accountIDs = $account_ids; | |||||
| return $this; | |||||
| } | |||||
| public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
| $this->phids = $phids; | $this->phids = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withIDs($ids) { | public function withIDs($ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| return $this; | return $this; | ||||
| Show All 14 Lines | public function needAccountIdentifiers($need) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withProviderConfigPHIDs(array $phids) { | public function withProviderConfigPHIDs(array $phids) { | ||||
| $this->providerConfigPHIDs = $phids; | $this->providerConfigPHIDs = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withRawAccountIdentifiers(array $identifiers) { | |||||
| $this->rawAccountIdentifiers = $identifiers; | |||||
| return $this; | |||||
| } | |||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new PhabricatorExternalAccount(); | return new PhabricatorExternalAccount(); | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | final class PhabricatorExternalAccountQuery | ||||
| } | } | ||||
| protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'id IN (%Ld)', | 'account.id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| } | } | ||||
| if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'phid IN (%Ls)', | 'account.phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->accountIDs !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'accountID IN (%Ls)', | |||||
| $this->accountIDs); | |||||
| } | |||||
| if ($this->userPHIDs !== null) { | if ($this->userPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'userPHID IN (%Ls)', | 'account.userPHID IN (%Ls)', | ||||
| $this->userPHIDs); | $this->userPHIDs); | ||||
| } | } | ||||
| if ($this->accountSecrets !== null) { | if ($this->accountSecrets !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'accountSecret IN (%Ls)', | 'account.accountSecret IN (%Ls)', | ||||
| $this->accountSecrets); | $this->accountSecrets); | ||||
| } | } | ||||
| if ($this->providerConfigPHIDs !== null) { | if ($this->providerConfigPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'providerConfigPHID IN (%Ls)', | 'account.providerConfigPHID IN (%Ls)', | ||||
| $this->providerConfigPHIDs); | $this->providerConfigPHIDs); | ||||
| // If we have a list of ProviderConfig PHIDs and are joining the | |||||
| // identifiers table, also include the list as an additional constraint | |||||
| // on the identifiers table. | |||||
| // This does not change the query results (an Account and its | |||||
| // Identifiers always have the same ProviderConfig PHID) but it allows | |||||
| // us to use keys on the Identifier table more efficiently. | |||||
| if ($this->shouldJoinIdentifiersTable()) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'identifier.providerConfigPHID IN (%Ls)', | |||||
| $this->providerConfigPHIDs); | |||||
| } | |||||
| } | |||||
| if ($this->rawAccountIdentifiers !== null) { | |||||
| $hashes = array(); | |||||
| foreach ($this->rawAccountIdentifiers as $raw_identifier) { | |||||
| $hashes[] = PhabricatorHash::digestForIndex($raw_identifier); | |||||
| } | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'identifier.identifierHash IN (%Ls)', | |||||
| $hashes); | |||||
| } | } | ||||
| return $where; | return $where; | ||||
| } | } | ||||
| protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | |||||
| $joins = parent::buildJoinClauseParts($conn); | |||||
| if ($this->shouldJoinIdentifiersTable()) { | |||||
| $joins[] = qsprintf( | |||||
| $conn, | |||||
| 'JOIN %R identifier ON account.phid = identifier.externalAccountPHID', | |||||
| new PhabricatorExternalAccountIdentifier()); | |||||
| } | |||||
| return $joins; | |||||
| } | |||||
| protected function shouldJoinIdentifiersTable() { | |||||
| return ($this->rawAccountIdentifiers !== null); | |||||
| } | |||||
| protected function shouldGroupQueryResultRows() { | |||||
| if ($this->shouldJoinIdentifiersTable()) { | |||||
| return true; | |||||
| } | |||||
| return parent::shouldGroupQueryResultRows(); | |||||
| } | |||||
| protected function getPrimaryTableAlias() { | |||||
| return 'account'; | |||||
| } | |||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorPeopleApplication'; | return 'PhabricatorPeopleApplication'; | ||||
| } | } | ||||
| } | } | ||||