Path: blob/master/src/applications/auth/query/PhabricatorAuthSSHKeyQuery.php
12256 views
<?php12final class PhabricatorAuthSSHKeyQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45const AUTHSTRUCT_CACHEKEY = 'ssh.authstruct';67private $ids;8private $phids;9private $objectPHIDs;10private $keys;11private $isActive;1213public static function deleteSSHKeyCache() {14$cache = PhabricatorCaches::getMutableCache();15$authfile_key = self::AUTHSTRUCT_CACHEKEY;16$cache->deleteKey($authfile_key);17}1819public function withIDs(array $ids) {20$this->ids = $ids;21return $this;22}2324public function withPHIDs(array $phids) {25$this->phids = $phids;26return $this;27}2829public function withObjectPHIDs(array $object_phids) {30$this->objectPHIDs = $object_phids;31return $this;32}3334public function withKeys(array $keys) {35assert_instances_of($keys, 'PhabricatorAuthSSHPublicKey');36$this->keys = $keys;37return $this;38}3940public function withIsActive($active) {41$this->isActive = $active;42return $this;43}4445public function newResultObject() {46return new PhabricatorAuthSSHKey();47}4849protected function willFilterPage(array $keys) {50$object_phids = mpull($keys, 'getObjectPHID');5152$objects = id(new PhabricatorObjectQuery())53->setViewer($this->getViewer())54->setParentQuery($this)55->withPHIDs($object_phids)56->execute();57$objects = mpull($objects, null, 'getPHID');5859foreach ($keys as $key => $ssh_key) {60$object = idx($objects, $ssh_key->getObjectPHID());6162// We must have an object, and that object must be a valid object for63// SSH keys.64if (!$object || !($object instanceof PhabricatorSSHPublicKeyInterface)) {65$this->didRejectResult($ssh_key);66unset($keys[$key]);67continue;68}6970$ssh_key->attachObject($object);71}7273return $keys;74}7576protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {77$where = parent::buildWhereClauseParts($conn);7879if ($this->ids !== null) {80$where[] = qsprintf(81$conn,82'id IN (%Ld)',83$this->ids);84}8586if ($this->phids !== null) {87$where[] = qsprintf(88$conn,89'phid IN (%Ls)',90$this->phids);91}9293if ($this->objectPHIDs !== null) {94$where[] = qsprintf(95$conn,96'objectPHID IN (%Ls)',97$this->objectPHIDs);98}99100if ($this->keys !== null) {101$sql = array();102foreach ($this->keys as $key) {103$sql[] = qsprintf(104$conn,105'(keyType = %s AND keyIndex = %s)',106$key->getType(),107$key->getHash());108}109$where[] = qsprintf($conn, '%LO', $sql);110}111112if ($this->isActive !== null) {113if ($this->isActive) {114$where[] = qsprintf(115$conn,116'isActive = %d',1171);118} else {119$where[] = qsprintf(120$conn,121'isActive IS NULL');122}123}124125return $where;126127}128129public function getQueryApplicationClass() {130return 'PhabricatorAuthApplication';131}132133}134135136