Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositoryURIQuery.php
blob5b75e1ef63950383a2168e0727ef89306c6e5c3c
1 <?php
3 final class PhabricatorRepositoryURIQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $repositoryPHIDs;
9 private $repositories = array();
11 public function withIDs(array $ids) {
12 $this->ids = $ids;
13 return $this;
16 public function withPHIDs(array $phids) {
17 $this->phids = $phids;
18 return $this;
21 public function withRepositoryPHIDs(array $phids) {
22 $this->repositoryPHIDs = $phids;
23 return $this;
26 public function withRepositories(array $repositories) {
27 $repositories = mpull($repositories, null, 'getPHID');
28 $this->withRepositoryPHIDs(array_keys($repositories));
29 $this->repositories = $repositories;
30 return $this;
33 public function newResultObject() {
34 return new PhabricatorRepositoryURI();
37 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
38 $where = parent::buildWhereClauseParts($conn);
40 if ($this->ids !== null) {
41 $where[] = qsprintf(
42 $conn,
43 'id IN (%Ld)',
44 $this->ids);
47 if ($this->phids !== null) {
48 $where[] = qsprintf(
49 $conn,
50 'phid IN (%Ls)',
51 $this->phids);
54 if ($this->repositoryPHIDs !== null) {
55 $where[] = qsprintf(
56 $conn,
57 'repositoryPHID IN (%Ls)',
58 $this->repositoryPHIDs);
61 return $where;
64 protected function willFilterPage(array $uris) {
65 $repositories = $this->repositories;
67 $repository_phids = mpull($uris, 'getRepositoryPHID');
68 $repository_phids = array_fuse($repository_phids);
69 $repository_phids = array_diff_key($repository_phids, $repositories);
71 if ($repository_phids) {
72 $more_repositories = id(new PhabricatorRepositoryQuery())
73 ->setViewer($this->getViewer())
74 ->withPHIDs($repository_phids)
75 ->execute();
76 $repositories += mpull($more_repositories, null, 'getPHID');
79 foreach ($uris as $key => $uri) {
80 $repository_phid = $uri->getRepositoryPHID();
81 $repository = idx($repositories, $repository_phid);
82 if (!$repository) {
83 $this->didRejectResult($uri);
84 unset($uris[$key]);
85 continue;
87 $uri->attachRepository($repository);
90 return $uris;
93 public function getQueryApplicationClass() {
94 return 'PhabricatorDiffusionApplication';