Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/passphrase/query/PassphraseCredentialQuery.php
12256 views
1
<?php
2
3
final class PassphraseCredentialQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $credentialTypes;
9
private $providesTypes;
10
private $isDestroyed;
11
private $allowConduit;
12
private $nameContains;
13
14
private $needSecrets;
15
16
public function withIDs(array $ids) {
17
$this->ids = $ids;
18
return $this;
19
}
20
21
public function withPHIDs(array $phids) {
22
$this->phids = $phids;
23
return $this;
24
}
25
26
public function withCredentialTypes(array $credential_types) {
27
$this->credentialTypes = $credential_types;
28
return $this;
29
}
30
31
public function withProvidesTypes(array $provides_types) {
32
$this->providesTypes = $provides_types;
33
return $this;
34
}
35
36
public function withIsDestroyed($destroyed) {
37
$this->isDestroyed = $destroyed;
38
return $this;
39
}
40
41
public function withAllowConduit($allow_conduit) {
42
$this->allowConduit = $allow_conduit;
43
return $this;
44
}
45
46
public function withNameContains($name_contains) {
47
$this->nameContains = $name_contains;
48
return $this;
49
}
50
51
public function needSecrets($need_secrets) {
52
$this->needSecrets = $need_secrets;
53
return $this;
54
}
55
56
public function newResultObject() {
57
return new PassphraseCredential();
58
}
59
60
protected function willFilterPage(array $page) {
61
if ($this->needSecrets) {
62
$secret_ids = mpull($page, 'getSecretID');
63
$secret_ids = array_filter($secret_ids);
64
65
$secrets = array();
66
if ($secret_ids) {
67
$secret_objects = id(new PassphraseSecret())->loadAllWhere(
68
'id IN (%Ld)',
69
$secret_ids);
70
foreach ($secret_objects as $secret) {
71
$secret_data = $secret->getSecretData();
72
$secrets[$secret->getID()] = new PhutilOpaqueEnvelope($secret_data);
73
}
74
}
75
76
foreach ($page as $key => $credential) {
77
$secret_id = $credential->getSecretID();
78
if (!$secret_id) {
79
$credential->attachSecret(null);
80
} else if (isset($secrets[$secret_id])) {
81
$credential->attachSecret($secrets[$secret_id]);
82
} else {
83
unset($page[$key]);
84
}
85
}
86
}
87
88
foreach ($page as $key => $credential) {
89
$type = PassphraseCredentialType::getTypeByConstant(
90
$credential->getCredentialType());
91
if (!$type) {
92
unset($page[$key]);
93
continue;
94
}
95
96
$credential->attachImplementation(clone $type);
97
}
98
99
return $page;
100
}
101
102
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
103
$where = parent::buildWhereClauseParts($conn);
104
105
if ($this->ids !== null) {
106
$where[] = qsprintf(
107
$conn,
108
'c.id IN (%Ld)',
109
$this->ids);
110
}
111
112
if ($this->phids !== null) {
113
$where[] = qsprintf(
114
$conn,
115
'c.phid IN (%Ls)',
116
$this->phids);
117
}
118
119
if ($this->credentialTypes !== null) {
120
$where[] = qsprintf(
121
$conn,
122
'c.credentialType in (%Ls)',
123
$this->credentialTypes);
124
}
125
126
if ($this->providesTypes !== null) {
127
$where[] = qsprintf(
128
$conn,
129
'c.providesType IN (%Ls)',
130
$this->providesTypes);
131
}
132
133
if ($this->isDestroyed !== null) {
134
$where[] = qsprintf(
135
$conn,
136
'c.isDestroyed = %d',
137
(int)$this->isDestroyed);
138
}
139
140
if ($this->allowConduit !== null) {
141
$where[] = qsprintf(
142
$conn,
143
'c.allowConduit = %d',
144
(int)$this->allowConduit);
145
}
146
147
if (phutil_nonempty_string($this->nameContains)) {
148
$where[] = qsprintf(
149
$conn,
150
'LOWER(c.name) LIKE %~',
151
phutil_utf8_strtolower($this->nameContains));
152
}
153
154
return $where;
155
}
156
157
public function getQueryApplicationClass() {
158
return 'PhabricatorPassphraseApplication';
159
}
160
161
protected function getPrimaryTableAlias() {
162
return 'c';
163
}
164
165
}
166
167