Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
3.2 kB · 140 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141<?php
/** * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorAuthSSHKey> */final class PhabricatorAuthSSHKeyQuery extends PhabricatorCursorPagedPolicyAwareQuery {
const AUTHSTRUCT_CACHEKEY = 'ssh.authstruct';
private $ids; private $phids; private $objectPHIDs; private $keys; private $isActive;
public static function deleteSSHKeyCache() { $cache = PhabricatorCaches::getMutableCache(); $authfile_key = self::AUTHSTRUCT_CACHEKEY; $cache->deleteKey($authfile_key); }
public function withIDs(array $ids) { $this->ids = $ids; return $this; }
public function withPHIDs(array $phids) { $this->phids = $phids; return $this; }
public function withObjectPHIDs(array $object_phids) { $this->objectPHIDs = $object_phids; return $this; }
/** * @param array<PhabricatorAuthSSHPublicKey> $keys */ public function withKeys(array $keys) { assert_instances_of($keys, PhabricatorAuthSSHPublicKey::class); $this->keys = $keys; return $this; }
public function withIsActive($active) { $this->isActive = $active; return $this; }
public function newResultObject() { return new PhabricatorAuthSSHKey(); }
protected function willFilterPage(array $keys) { $object_phids = mpull($keys, 'getObjectPHID');
$objects = id(new PhabricatorObjectQuery()) ->setViewer($this->getViewer()) ->setParentQuery($this) ->withPHIDs($object_phids) ->execute(); $objects = mpull($objects, null, 'getPHID');
foreach ($keys as $key => $ssh_key) { $object = idx($objects, $ssh_key->getObjectPHID());
// We must have an object, and that object must be a valid object for // SSH keys. if (!$object || !($object instanceof PhabricatorSSHPublicKeyInterface)) { $this->didRejectResult($ssh_key); unset($keys[$key]); continue; }
$ssh_key->attachObject($object); }
return $keys; }
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) { $where[] = qsprintf( $conn, 'id IN (%Ld)', $this->ids); }
if ($this->phids !== null) { $where[] = qsprintf( $conn, 'phid IN (%Ls)', $this->phids); }
if ($this->objectPHIDs !== null) { $where[] = qsprintf( $conn, 'objectPHID IN (%Ls)', $this->objectPHIDs); }
if ($this->keys !== null) { $sql = array(); foreach ($this->keys as $key) { $sql[] = qsprintf( $conn, '(keyType = %s AND keyIndex = %s)', $key->getType(), $key->getHash()); } $where[] = qsprintf($conn, '%LO', $sql); }
if ($this->isActive !== null) { if ($this->isActive) { $where[] = qsprintf( $conn, 'isActive = %d', 1); } else { $where[] = qsprintf( $conn, 'isActive IS NULL'); } }
return $where;
}
public function getQueryApplicationClass() { return PhabricatorAuthApplication::class; }
}