[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/auth/query/ -> PhabricatorAuthSSHKeyQuery.php (source)

   1  <?php
   2  
   3  final class PhabricatorAuthSSHKeyQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $objectPHIDs;
   8    private $keys;
   9  
  10    public function withIDs(array $ids) {
  11      $this->ids = $ids;
  12      return $this;
  13    }
  14  
  15    public function withObjectPHIDs(array $object_phids) {
  16      $this->objectPHIDs = $object_phids;
  17      return $this;
  18    }
  19  
  20    public function withKeys(array $keys) {
  21      assert_instances_of($keys, 'PhabricatorAuthSSHPublicKey');
  22      $this->keys = $keys;
  23      return $this;
  24    }
  25  
  26    protected function loadPage() {
  27      $table = new PhabricatorAuthSSHKey();
  28      $conn_r = $table->establishConnection('r');
  29  
  30      $data = queryfx_all(
  31        $conn_r,
  32        'SELECT * FROM %T %Q %Q %Q',
  33        $table->getTableName(),
  34        $this->buildWhereClause($conn_r),
  35        $this->buildOrderClause($conn_r),
  36        $this->buildLimitClause($conn_r));
  37  
  38      return $table->loadAllFromArray($data);
  39    }
  40  
  41    protected function willFilterPage(array $keys) {
  42      $object_phids = mpull($keys, 'getObjectPHID');
  43  
  44      $objects = id(new PhabricatorObjectQuery())
  45        ->setViewer($this->getViewer())
  46        ->setParentQuery($this)
  47        ->withPHIDs($object_phids)
  48        ->execute();
  49      $objects = mpull($objects, null, 'getPHID');
  50  
  51      foreach ($keys as $key => $ssh_key) {
  52        $object = idx($objects, $ssh_key->getObjectPHID());
  53  
  54        // We must have an object, and that object must be a valid object for
  55        // SSH keys.
  56        if (!$object || !($object instanceof PhabricatorSSHPublicKeyInterface)) {
  57          unset($keys[$key]);
  58          continue;
  59        }
  60  
  61        $ssh_key->attachObject($object);
  62      }
  63  
  64      return $keys;
  65    }
  66  
  67    protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  68      $where = array();
  69  
  70      if ($this->ids !== null) {
  71        $where[] = qsprintf(
  72          $conn_r,
  73          'id IN (%Ld)',
  74          $this->ids);
  75      }
  76  
  77      if ($this->objectPHIDs !== null) {
  78        $where[] = qsprintf(
  79          $conn_r,
  80          'objectPHID IN (%Ls)',
  81          $this->objectPHIDs);
  82      }
  83  
  84      if ($this->keys !== null) {
  85        $sql = array();
  86        foreach ($this->keys as $key) {
  87          $sql[] = qsprintf(
  88            $conn_r,
  89            '(keyType = %s AND keyIndex = %s)',
  90            $key->getType(),
  91            $key->getHash());
  92        }
  93        $where[] = implode(' OR ', $sql);
  94      }
  95  
  96      $where[] = $this->buildPagingClause($conn_r);
  97  
  98      return $this->formatWhereClause($where);
  99    }
 100  
 101    public function getQueryApplicationClass() {
 102      return 'PhabricatorAuthApplication';
 103    }
 104  
 105  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1