Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositoryRefCursorQuery.php
blobc7b2c9d2ef4079fd50e171ed939006bbe1faa21b
1 <?php
3 final class PhabricatorRepositoryRefCursorQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $repositoryPHIDs;
9 private $refTypes;
10 private $refNames;
11 private $datasourceQuery;
12 private $needPositions;
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
24 public function withRepositoryPHIDs(array $phids) {
25 $this->repositoryPHIDs = $phids;
26 return $this;
29 public function withRefTypes(array $types) {
30 $this->refTypes = $types;
31 return $this;
34 public function withRefNames(array $names) {
35 $this->refNames = $names;
36 return $this;
39 public function withDatasourceQuery($query) {
40 $this->datasourceQuery = $query;
41 return $this;
44 public function needPositions($need) {
45 $this->needPositions = $need;
46 return $this;
49 public function newResultObject() {
50 return new PhabricatorRepositoryRefCursor();
53 protected function willFilterPage(array $refs) {
54 $repository_phids = mpull($refs, 'getRepositoryPHID');
56 $repositories = id(new PhabricatorRepositoryQuery())
57 ->setViewer($this->getViewer())
58 ->setParentQuery($this)
59 ->withPHIDs($repository_phids)
60 ->execute();
61 $repositories = mpull($repositories, null, 'getPHID');
63 foreach ($refs as $key => $ref) {
64 $repository = idx($repositories, $ref->getRepositoryPHID());
65 if (!$repository) {
66 $this->didRejectResult($ref);
67 unset($refs[$key]);
68 continue;
70 $ref->attachRepository($repository);
73 if (!$refs) {
74 return $refs;
77 if ($this->needPositions) {
78 $positions = id(new PhabricatorRepositoryRefPosition())->loadAllWhere(
79 'cursorID IN (%Ld)',
80 mpull($refs, 'getID'));
81 $positions = mgroup($positions, 'getCursorID');
83 foreach ($refs as $key => $ref) {
84 $ref_positions = idx($positions, $ref->getID(), array());
85 $ref->attachPositions($ref_positions);
89 return $refs;
92 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
93 $where = parent::buildWhereClauseParts($conn);
95 if ($this->ids !== null) {
96 $where[] = qsprintf(
97 $conn,
98 'id IN (%Ld)',
99 $this->ids);
102 if ($this->phids !== null) {
103 $where[] = qsprintf(
104 $conn,
105 'phid IN (%Ls)',
106 $this->phids);
109 if ($this->repositoryPHIDs !== null) {
110 $where[] = qsprintf(
111 $conn,
112 'repositoryPHID IN (%Ls)',
113 $this->repositoryPHIDs);
116 if ($this->refTypes !== null) {
117 $where[] = qsprintf(
118 $conn,
119 'refType IN (%Ls)',
120 $this->refTypes);
123 if ($this->refNames !== null) {
124 $name_hashes = array();
125 foreach ($this->refNames as $name) {
126 $name_hashes[] = PhabricatorHash::digestForIndex($name);
129 $where[] = qsprintf(
130 $conn,
131 'refNameHash IN (%Ls)',
132 $name_hashes);
135 if ($this->datasourceQuery !== null && strlen($this->datasourceQuery)) {
136 $where[] = qsprintf(
137 $conn,
138 'refNameRaw LIKE %>',
139 $this->datasourceQuery);
142 return $where;
145 public function getQueryApplicationClass() {
146 return 'PhabricatorDiffusionApplication';