Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/packages/query/PhabricatorPackagesPackageQuery.php
12242 views
1
<?php
2
3
final class PhabricatorPackagesPackageQuery
4
extends PhabricatorPackagesQuery {
5
6
private $ids;
7
private $phids;
8
private $publisherPHIDs;
9
private $packageKeys;
10
private $fullKeys;
11
12
public function withIDs(array $ids) {
13
$this->ids = $ids;
14
return $this;
15
}
16
17
public function withPHIDs(array $phids) {
18
$this->phids = $phids;
19
return $this;
20
}
21
22
public function withPublisherPHIDs(array $phids) {
23
$this->publisherPHIDs = $phids;
24
return $this;
25
}
26
27
public function withPackageKeys(array $keys) {
28
$this->packageKeys = $keys;
29
return $this;
30
}
31
32
public function withFullKeys(array $keys) {
33
$this->fullKeys = $keys;
34
return $this;
35
}
36
37
public function withNameNgrams($ngrams) {
38
return $this->withNgramsConstraint(
39
new PhabricatorPackagesPackageNameNgrams(),
40
$ngrams);
41
}
42
43
public function newResultObject() {
44
return new PhabricatorPackagesPackage();
45
}
46
47
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
48
$where = parent::buildWhereClauseParts($conn);
49
50
if ($this->ids !== null) {
51
$where[] = qsprintf(
52
$conn,
53
'p.id IN (%Ld)',
54
$this->ids);
55
}
56
57
if ($this->phids !== null) {
58
$where[] = qsprintf(
59
$conn,
60
'p.phid IN (%Ls)',
61
$this->phids);
62
}
63
64
if ($this->publisherPHIDs !== null) {
65
$where[] = qsprintf(
66
$conn,
67
'p.publisherPHID IN (%Ls)',
68
$this->publisherPHIDs);
69
}
70
71
if ($this->packageKeys !== null) {
72
$where[] = qsprintf(
73
$conn,
74
'p.packageKey IN (%Ls)',
75
$this->packageKeys);
76
}
77
78
if ($this->fullKeys !== null) {
79
$parts = $this->buildFullKeyClauseParts($conn, $this->fullKeys);
80
$where[] = qsprintf($conn, '%Q', $parts);
81
}
82
83
return $where;
84
}
85
86
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
87
$joins = parent::buildJoinClauseParts($conn);
88
89
$join_publisher = ($this->fullKeys !== null);
90
if ($join_publisher) {
91
$publisher_table = new PhabricatorPackagesPublisher();
92
93
$joins[] = qsprintf(
94
$conn,
95
'JOIN %T u ON u.phid = p.publisherPHID',
96
$publisher_table->getTableName());
97
}
98
99
return $joins;
100
}
101
102
protected function willFilterPage(array $packages) {
103
$publisher_phids = mpull($packages, 'getPublisherPHID');
104
105
$publishers = id(new PhabricatorPackagesPublisherQuery())
106
->setViewer($this->getViewer())
107
->setParentQuery($this)
108
->withPHIDs($publisher_phids)
109
->execute();
110
$publishers = mpull($publishers, null, 'getPHID');
111
112
foreach ($packages as $key => $package) {
113
$publisher = idx($publishers, $package->getPublisherPHID());
114
115
if (!$publisher) {
116
unset($packages[$key]);
117
$this->didRejectResult($package);
118
continue;
119
}
120
121
$package->attachPublisher($publisher);
122
}
123
124
return $packages;
125
}
126
127
protected function getPrimaryTableAlias() {
128
return 'p';
129
}
130
131
}
132
133