@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
1<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhabricatorRepositoryURI>
5 */
6final class PhabricatorRepositoryURIQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $repositoryPHIDs;
12 private $repositories = array();
13
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
17 }
18
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
22 }
23
24 public function withRepositoryPHIDs(array $phids) {
25 $this->repositoryPHIDs = $phids;
26 return $this;
27 }
28
29 public function withRepositories(array $repositories) {
30 $repositories = mpull($repositories, null, 'getPHID');
31 $this->withRepositoryPHIDs(array_keys($repositories));
32 $this->repositories = $repositories;
33 return $this;
34 }
35
36 public function newResultObject() {
37 return new PhabricatorRepositoryURI();
38 }
39
40 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
41 $where = parent::buildWhereClauseParts($conn);
42
43 if ($this->ids !== null) {
44 $where[] = qsprintf(
45 $conn,
46 'id IN (%Ld)',
47 $this->ids);
48 }
49
50 if ($this->phids !== null) {
51 $where[] = qsprintf(
52 $conn,
53 'phid IN (%Ls)',
54 $this->phids);
55 }
56
57 if ($this->repositoryPHIDs !== null) {
58 $where[] = qsprintf(
59 $conn,
60 'repositoryPHID IN (%Ls)',
61 $this->repositoryPHIDs);
62 }
63
64 return $where;
65 }
66
67 protected function willFilterPage(array $uris) {
68 $repositories = $this->repositories;
69
70 $repository_phids = mpull($uris, 'getRepositoryPHID');
71 $repository_phids = array_fuse($repository_phids);
72 $repository_phids = array_diff_key($repository_phids, $repositories);
73
74 if ($repository_phids) {
75 $more_repositories = id(new PhabricatorRepositoryQuery())
76 ->setViewer($this->getViewer())
77 ->withPHIDs($repository_phids)
78 ->execute();
79 $repositories += mpull($more_repositories, null, 'getPHID');
80 }
81
82 foreach ($uris as $key => $uri) {
83 $repository_phid = $uri->getRepositoryPHID();
84 $repository = idx($repositories, $repository_phid);
85 if (!$repository) {
86 $this->didRejectResult($uri);
87 unset($uris[$key]);
88 continue;
89 }
90 $uri->attachRepository($repository);
91 }
92
93 return $uris;
94 }
95
96 public function getQueryApplicationClass() {
97 return PhabricatorDiffusionApplication::class;
98 }
99
100}