@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 119 lines 2.8 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorAuthInvite> 5 */ 6final class PhabricatorAuthInviteQuery 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 9 private $ids; 10 private $phids; 11 private $emailAddresses; 12 private $verificationCodes; 13 private $authorPHIDs; 14 15 public function withIDs(array $ids) { 16 $this->ids = $ids; 17 return $this; 18 } 19 20 public function withPHIDs(array $phids) { 21 $this->phids = $phids; 22 return $this; 23 } 24 25 public function withEmailAddresses(array $addresses) { 26 $this->emailAddresses = $addresses; 27 return $this; 28 } 29 30 public function withVerificationCodes(array $codes) { 31 $this->verificationCodes = $codes; 32 return $this; 33 } 34 35 public function withAuthorPHIDs(array $phids) { 36 $this->authorPHIDs = $phids; 37 return $this; 38 } 39 40 protected function loadPage() { 41 $table = new PhabricatorAuthInvite(); 42 $conn_r = $table->establishConnection('r'); 43 44 $data = queryfx_all( 45 $conn_r, 46 'SELECT * FROM %T %Q %Q %Q', 47 $table->getTableName(), 48 $this->buildWhereClause($conn_r), 49 $this->buildOrderClause($conn_r), 50 $this->buildLimitClause($conn_r)); 51 52 $invites = $table->loadAllFromArray($data); 53 54 // If the objects were loaded via verification code, set a flag to make 55 // sure the viewer can see them. 56 if ($this->verificationCodes !== null) { 57 foreach ($invites as $invite) { 58 $invite->setViewerHasVerificationCode(true); 59 } 60 } 61 62 return $invites; 63 } 64 65 protected function buildWhereClause(AphrontDatabaseConnection $conn) { 66 $where = array(); 67 68 if ($this->ids !== null) { 69 $where[] = qsprintf( 70 $conn, 71 'id IN (%Ld)', 72 $this->ids); 73 } 74 75 if ($this->phids !== null) { 76 $where[] = qsprintf( 77 $conn, 78 'phid IN (%Ls)', 79 $this->phids); 80 } 81 82 if ($this->emailAddresses !== null) { 83 $where[] = qsprintf( 84 $conn, 85 'emailAddress IN (%Ls)', 86 $this->emailAddresses); 87 } 88 89 if ($this->verificationCodes !== null) { 90 $hashes = array(); 91 foreach ($this->verificationCodes as $code) { 92 $hashes[] = PhabricatorHash::digestForIndex($code); 93 } 94 95 $where[] = qsprintf( 96 $conn, 97 'verificationHash IN (%Ls)', 98 $hashes); 99 } 100 101 if ($this->authorPHIDs !== null) { 102 $where[] = qsprintf( 103 $conn, 104 'authorPHID IN (%Ls)', 105 $this->authorPHIDs); 106 } 107 108 $where[] = $this->buildPagingClause($conn); 109 110 return $this->formatWhereClause($conn, $where); 111 } 112 113 public function getQueryApplicationClass() { 114 // NOTE: This query is issued by logged-out users, who often will not be 115 // able to see applications. They still need to be able to see invites. 116 return null; 117 } 118 119}