Path: blob/master/src/applications/passphrase/query/PassphraseCredentialQuery.php
12256 views
<?php12final class PassphraseCredentialQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $ids;6private $phids;7private $credentialTypes;8private $providesTypes;9private $isDestroyed;10private $allowConduit;11private $nameContains;1213private $needSecrets;1415public function withIDs(array $ids) {16$this->ids = $ids;17return $this;18}1920public function withPHIDs(array $phids) {21$this->phids = $phids;22return $this;23}2425public function withCredentialTypes(array $credential_types) {26$this->credentialTypes = $credential_types;27return $this;28}2930public function withProvidesTypes(array $provides_types) {31$this->providesTypes = $provides_types;32return $this;33}3435public function withIsDestroyed($destroyed) {36$this->isDestroyed = $destroyed;37return $this;38}3940public function withAllowConduit($allow_conduit) {41$this->allowConduit = $allow_conduit;42return $this;43}4445public function withNameContains($name_contains) {46$this->nameContains = $name_contains;47return $this;48}4950public function needSecrets($need_secrets) {51$this->needSecrets = $need_secrets;52return $this;53}5455public function newResultObject() {56return new PassphraseCredential();57}5859protected function willFilterPage(array $page) {60if ($this->needSecrets) {61$secret_ids = mpull($page, 'getSecretID');62$secret_ids = array_filter($secret_ids);6364$secrets = array();65if ($secret_ids) {66$secret_objects = id(new PassphraseSecret())->loadAllWhere(67'id IN (%Ld)',68$secret_ids);69foreach ($secret_objects as $secret) {70$secret_data = $secret->getSecretData();71$secrets[$secret->getID()] = new PhutilOpaqueEnvelope($secret_data);72}73}7475foreach ($page as $key => $credential) {76$secret_id = $credential->getSecretID();77if (!$secret_id) {78$credential->attachSecret(null);79} else if (isset($secrets[$secret_id])) {80$credential->attachSecret($secrets[$secret_id]);81} else {82unset($page[$key]);83}84}85}8687foreach ($page as $key => $credential) {88$type = PassphraseCredentialType::getTypeByConstant(89$credential->getCredentialType());90if (!$type) {91unset($page[$key]);92continue;93}9495$credential->attachImplementation(clone $type);96}9798return $page;99}100101protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {102$where = parent::buildWhereClauseParts($conn);103104if ($this->ids !== null) {105$where[] = qsprintf(106$conn,107'c.id IN (%Ld)',108$this->ids);109}110111if ($this->phids !== null) {112$where[] = qsprintf(113$conn,114'c.phid IN (%Ls)',115$this->phids);116}117118if ($this->credentialTypes !== null) {119$where[] = qsprintf(120$conn,121'c.credentialType in (%Ls)',122$this->credentialTypes);123}124125if ($this->providesTypes !== null) {126$where[] = qsprintf(127$conn,128'c.providesType IN (%Ls)',129$this->providesTypes);130}131132if ($this->isDestroyed !== null) {133$where[] = qsprintf(134$conn,135'c.isDestroyed = %d',136(int)$this->isDestroyed);137}138139if ($this->allowConduit !== null) {140$where[] = qsprintf(141$conn,142'c.allowConduit = %d',143(int)$this->allowConduit);144}145146if (phutil_nonempty_string($this->nameContains)) {147$where[] = qsprintf(148$conn,149'LOWER(c.name) LIKE %~',150phutil_utf8_strtolower($this->nameContains));151}152153return $where;154}155156public function getQueryApplicationClass() {157return 'PhabricatorPassphraseApplication';158}159160protected function getPrimaryTableAlias() {161return 'c';162}163164}165166167