@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 130 lines 3.1 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorAuthFactorConfig> 5 */ 6final class PhabricatorAuthFactorConfigQuery 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 9 private $ids; 10 private $phids; 11 private $userPHIDs; 12 private $factorProviderPHIDs; 13 private $factorProviderStatuses; 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 withUserPHIDs(array $user_phids) { 26 $this->userPHIDs = $user_phids; 27 return $this; 28 } 29 30 public function withFactorProviderPHIDs(array $provider_phids) { 31 $this->factorProviderPHIDs = $provider_phids; 32 return $this; 33 } 34 35 public function withFactorProviderStatuses(array $statuses) { 36 $this->factorProviderStatuses = $statuses; 37 return $this; 38 } 39 40 public function newResultObject() { 41 return new PhabricatorAuthFactorConfig(); 42 } 43 44 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 45 $where = parent::buildWhereClauseParts($conn); 46 47 if ($this->ids !== null) { 48 $where[] = qsprintf( 49 $conn, 50 'config.id IN (%Ld)', 51 $this->ids); 52 } 53 54 if ($this->phids !== null) { 55 $where[] = qsprintf( 56 $conn, 57 'config.phid IN (%Ls)', 58 $this->phids); 59 } 60 61 if ($this->userPHIDs !== null) { 62 $where[] = qsprintf( 63 $conn, 64 'config.userPHID IN (%Ls)', 65 $this->userPHIDs); 66 } 67 68 if ($this->factorProviderPHIDs !== null) { 69 $where[] = qsprintf( 70 $conn, 71 'config.factorProviderPHID IN (%Ls)', 72 $this->factorProviderPHIDs); 73 } 74 75 if ($this->factorProviderStatuses !== null) { 76 $where[] = qsprintf( 77 $conn, 78 'provider.status IN (%Ls)', 79 $this->factorProviderStatuses); 80 } 81 82 return $where; 83 } 84 85 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 86 $joins = parent::buildJoinClauseParts($conn); 87 88 if ($this->factorProviderStatuses !== null) { 89 $joins[] = qsprintf( 90 $conn, 91 'JOIN %R provider ON config.factorProviderPHID = provider.phid', 92 new PhabricatorAuthFactorProvider()); 93 } 94 95 return $joins; 96 } 97 98 protected function willFilterPage(array $configs) { 99 $provider_phids = mpull($configs, 'getFactorProviderPHID'); 100 101 $providers = id(new PhabricatorAuthFactorProviderQuery()) 102 ->setViewer($this->getViewer()) 103 ->withPHIDs($provider_phids) 104 ->execute(); 105 $providers = mpull($providers, null, 'getPHID'); 106 107 foreach ($configs as $key => $config) { 108 $provider = idx($providers, $config->getFactorProviderPHID()); 109 110 if (!$provider) { 111 unset($configs[$key]); 112 $this->didRejectResult($config); 113 continue; 114 } 115 116 $config->attachFactorProvider($provider); 117 } 118 119 return $configs; 120 } 121 122 protected function getPrimaryTableAlias() { 123 return 'config'; 124 } 125 126 public function getQueryApplicationClass() { 127 return PhabricatorAuthApplication::class; 128 } 129 130}