Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / packages / query / PhabricatorPackagesPackageQuery.php
blobc97e3b244c4c74db24c65865a3ad50b94869bbcf
1 <?php
3 final class PhabricatorPackagesPackageQuery
4 extends PhabricatorPackagesQuery {
6 private $ids;
7 private $phids;
8 private $publisherPHIDs;
9 private $packageKeys;
10 private $fullKeys;
12 public function withIDs(array $ids) {
13 $this->ids = $ids;
14 return $this;
17 public function withPHIDs(array $phids) {
18 $this->phids = $phids;
19 return $this;
22 public function withPublisherPHIDs(array $phids) {
23 $this->publisherPHIDs = $phids;
24 return $this;
27 public function withPackageKeys(array $keys) {
28 $this->packageKeys = $keys;
29 return $this;
32 public function withFullKeys(array $keys) {
33 $this->fullKeys = $keys;
34 return $this;
37 public function withNameNgrams($ngrams) {
38 return $this->withNgramsConstraint(
39 new PhabricatorPackagesPackageNameNgrams(),
40 $ngrams);
43 public function newResultObject() {
44 return new PhabricatorPackagesPackage();
47 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
48 $where = parent::buildWhereClauseParts($conn);
50 if ($this->ids !== null) {
51 $where[] = qsprintf(
52 $conn,
53 'p.id IN (%Ld)',
54 $this->ids);
57 if ($this->phids !== null) {
58 $where[] = qsprintf(
59 $conn,
60 'p.phid IN (%Ls)',
61 $this->phids);
64 if ($this->publisherPHIDs !== null) {
65 $where[] = qsprintf(
66 $conn,
67 'p.publisherPHID IN (%Ls)',
68 $this->publisherPHIDs);
71 if ($this->packageKeys !== null) {
72 $where[] = qsprintf(
73 $conn,
74 'p.packageKey IN (%Ls)',
75 $this->packageKeys);
78 if ($this->fullKeys !== null) {
79 $parts = $this->buildFullKeyClauseParts($conn, $this->fullKeys);
80 $where[] = qsprintf($conn, '%Q', $parts);
83 return $where;
86 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
87 $joins = parent::buildJoinClauseParts($conn);
89 $join_publisher = ($this->fullKeys !== null);
90 if ($join_publisher) {
91 $publisher_table = new PhabricatorPackagesPublisher();
93 $joins[] = qsprintf(
94 $conn,
95 'JOIN %T u ON u.phid = p.publisherPHID',
96 $publisher_table->getTableName());
99 return $joins;
102 protected function willFilterPage(array $packages) {
103 $publisher_phids = mpull($packages, 'getPublisherPHID');
105 $publishers = id(new PhabricatorPackagesPublisherQuery())
106 ->setViewer($this->getViewer())
107 ->setParentQuery($this)
108 ->withPHIDs($publisher_phids)
109 ->execute();
110 $publishers = mpull($publishers, null, 'getPHID');
112 foreach ($packages as $key => $package) {
113 $publisher = idx($publishers, $package->getPublisherPHID());
115 if (!$publisher) {
116 unset($packages[$key]);
117 $this->didRejectResult($package);
118 continue;
121 $package->attachPublisher($publisher);
124 return $packages;
127 protected function getPrimaryTableAlias() {
128 return 'p';