@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
at recaptime-dev/main 116 lines 2.7 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorAuthSession> 5 */ 6final class PhabricatorAuthSessionQuery 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 9 private $ids; 10 private $phids; 11 private $identityPHIDs; 12 private $sessionKeys; 13 private $sessionTypes; 14 15 public function withIdentityPHIDs(array $identity_phids) { 16 $this->identityPHIDs = $identity_phids; 17 return $this; 18 } 19 20 public function withSessionKeys(array $keys) { 21 $this->sessionKeys = $keys; 22 return $this; 23 } 24 25 public function withSessionTypes(array $types) { 26 $this->sessionTypes = $types; 27 return $this; 28 } 29 30 public function withIDs(array $ids) { 31 $this->ids = $ids; 32 return $this; 33 } 34 35 public function withPHIDs(array $phids) { 36 $this->phids = $phids; 37 return $this; 38 } 39 40 public function newResultObject() { 41 return new PhabricatorAuthSession(); 42 } 43 44 protected function willFilterPage(array $sessions) { 45 $identity_phids = mpull($sessions, 'getUserPHID'); 46 47 $identity_objects = id(new PhabricatorObjectQuery()) 48 ->setViewer($this->getViewer()) 49 ->setParentQuery($this) 50 ->withPHIDs($identity_phids) 51 ->execute(); 52 $identity_objects = mpull($identity_objects, null, 'getPHID'); 53 54 foreach ($sessions as $key => $session) { 55 $identity_object = idx($identity_objects, $session->getUserPHID()); 56 if (!$identity_object) { 57 unset($sessions[$key]); 58 } else { 59 $session->attachIdentityObject($identity_object); 60 } 61 } 62 63 return $sessions; 64 } 65 66 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 67 $where = parent::buildWhereClauseParts($conn); 68 69 if ($this->ids !== null) { 70 $where[] = qsprintf( 71 $conn, 72 'id IN (%Ld)', 73 $this->ids); 74 } 75 76 if ($this->phids !== null) { 77 $where[] = qsprintf( 78 $conn, 79 'phid IN (%Ls)', 80 $this->phids); 81 } 82 83 if ($this->identityPHIDs !== null) { 84 $where[] = qsprintf( 85 $conn, 86 'userPHID IN (%Ls)', 87 $this->identityPHIDs); 88 } 89 90 if ($this->sessionKeys !== null) { 91 $hashes = array(); 92 foreach ($this->sessionKeys as $session_key) { 93 $hashes[] = PhabricatorAuthSession::newSessionDigest( 94 new PhutilOpaqueEnvelope($session_key)); 95 } 96 $where[] = qsprintf( 97 $conn, 98 'sessionKey IN (%Ls)', 99 $hashes); 100 } 101 102 if ($this->sessionTypes !== null) { 103 $where[] = qsprintf( 104 $conn, 105 'type IN (%Ls)', 106 $this->sessionTypes); 107 } 108 109 return $where; 110 } 111 112 public function getQueryApplicationClass() { 113 return PhabricatorAuthApplication::class; 114 } 115 116}