[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorAuthSessionQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $identityPHIDs; 8 private $sessionKeys; 9 private $sessionTypes; 10 11 public function withIdentityPHIDs(array $identity_phids) { 12 $this->identityPHIDs = $identity_phids; 13 return $this; 14 } 15 16 public function withSessionKeys(array $keys) { 17 $this->sessionKeys = $keys; 18 return $this; 19 } 20 21 public function withSessionTypes(array $types) { 22 $this->sessionTypes = $types; 23 return $this; 24 } 25 26 public function withIDs(array $ids) { 27 $this->ids = $ids; 28 return $this; 29 } 30 31 protected function loadPage() { 32 $table = new PhabricatorAuthSession(); 33 $conn_r = $table->establishConnection('r'); 34 35 $data = queryfx_all( 36 $conn_r, 37 'SELECT * FROM %T %Q %Q %Q', 38 $table->getTableName(), 39 $this->buildWhereClause($conn_r), 40 $this->buildOrderClause($conn_r), 41 $this->buildLimitClause($conn_r)); 42 43 return $table->loadAllFromArray($data); 44 } 45 46 protected function willFilterPage(array $sessions) { 47 $identity_phids = mpull($sessions, 'getUserPHID'); 48 49 $identity_objects = id(new PhabricatorObjectQuery()) 50 ->setViewer($this->getViewer()) 51 ->setParentQuery($this) 52 ->withPHIDs($identity_phids) 53 ->execute(); 54 $identity_objects = mpull($identity_objects, null, 'getPHID'); 55 56 foreach ($sessions as $key => $session) { 57 $identity_object = idx($identity_objects, $session->getUserPHID()); 58 if (!$identity_object) { 59 unset($sessions[$key]); 60 } else { 61 $session->attachIdentityObject($identity_object); 62 } 63 } 64 65 return $sessions; 66 } 67 68 protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 69 $where = array(); 70 71 if ($this->ids) { 72 $where[] = qsprintf( 73 $conn_r, 74 'id IN (%Ld)', 75 $this->ids); 76 } 77 78 if ($this->identityPHIDs) { 79 $where[] = qsprintf( 80 $conn_r, 81 'userPHID IN (%Ls)', 82 $this->identityPHIDs); 83 } 84 85 if ($this->sessionKeys) { 86 $hashes = array(); 87 foreach ($this->sessionKeys as $session_key) { 88 $hashes[] = PhabricatorHash::digest($session_key); 89 } 90 $where[] = qsprintf( 91 $conn_r, 92 'sessionKey IN (%Ls)', 93 $hashes); 94 } 95 96 if ($this->sessionTypes) { 97 $where[] = qsprintf( 98 $conn_r, 99 'type IN (%Ls)', 100 $this->sessionTypes); 101 } 102 103 $where[] = $this->buildPagingClause($conn_r); 104 105 return $this->formatWhereClause($where); 106 } 107 108 public function getQueryApplicationClass() { 109 return 'PhabricatorAuthApplication'; 110 } 111 112 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |