Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/passphrase/query/PassphraseCredentialQuery.php b/src/applications/passphrase/query/PassphraseCredentialQuery.php
index 9cae8b1f85..9411fa8a77 100644
--- a/src/applications/passphrase/query/PassphraseCredentialQuery.php
+++ b/src/applications/passphrase/query/PassphraseCredentialQuery.php
@@ -1,163 +1,154 @@
<?php
final class PassphraseCredentialQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $credentialTypes;
private $providesTypes;
private $isDestroyed;
private $allowConduit;
private $nameContains;
private $needSecrets;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withCredentialTypes(array $credential_types) {
$this->credentialTypes = $credential_types;
return $this;
}
public function withProvidesTypes(array $provides_types) {
$this->providesTypes = $provides_types;
return $this;
}
public function withIsDestroyed($destroyed) {
$this->isDestroyed = $destroyed;
return $this;
}
public function withAllowConduit($allow_conduit) {
$this->allowConduit = $allow_conduit;
return $this;
}
public function withNameContains($name_contains) {
$this->nameContains = $name_contains;
return $this;
}
public function needSecrets($need_secrets) {
$this->needSecrets = $need_secrets;
return $this;
}
+ public function newResultObject() {
+ return new PassphraseCredential();
+ }
+
protected function loadPage() {
- $table = new PassphraseCredential();
- $conn_r = $table->establishConnection('r');
-
- $rows = queryfx_all(
- $conn_r,
- 'SELECT * FROM %T %Q %Q %Q',
- $table->getTableName(),
- $this->buildWhereClause($conn_r),
- $this->buildOrderClause($conn_r),
- $this->buildLimitClause($conn_r));
-
- return $table->loadAllFromArray($rows);
+ return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $page) {
if ($this->needSecrets) {
$secret_ids = mpull($page, 'getSecretID');
$secret_ids = array_filter($secret_ids);
$secrets = array();
if ($secret_ids) {
$secret_objects = id(new PassphraseSecret())->loadAllWhere(
'id IN (%Ld)',
$secret_ids);
foreach ($secret_objects as $secret) {
$secret_data = $secret->getSecretData();
$secrets[$secret->getID()] = new PhutilOpaqueEnvelope($secret_data);
}
}
foreach ($page as $key => $credential) {
$secret_id = $credential->getSecretID();
if (!$secret_id) {
$credential->attachSecret(null);
} else if (isset($secrets[$secret_id])) {
$credential->attachSecret($secrets[$secret_id]);
} else {
unset($page[$key]);
}
}
}
return $page;
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
- $where = array();
-
- $where[] = $this->buildPagingClause($conn_r);
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
- if ($this->ids) {
+ if ($this->ids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'id IN (%Ld)',
$this->ids);
}
- if ($this->phids) {
+ if ($this->phids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'phid IN (%Ls)',
$this->phids);
}
- if ($this->credentialTypes) {
+ if ($this->credentialTypes !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'credentialType in (%Ls)',
$this->credentialTypes);
}
- if ($this->providesTypes) {
+ if ($this->providesTypes !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'providesType IN (%Ls)',
$this->providesTypes);
}
if ($this->isDestroyed !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'isDestroyed = %d',
(int)$this->isDestroyed);
}
if ($this->allowConduit !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'allowConduit = %d',
(int)$this->allowConduit);
}
if (strlen($this->nameContains)) {
$where[] = qsprintf(
- $conn_r,
- 'name LIKE %~',
- $this->nameContains);
+ $conn,
+ 'LOWER(name) LIKE %~',
+ phutil_utf8_strtolower($this->nameContains));
}
- return $this->formatWhereClause($where);
+ return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorPassphraseApplication';
}
}
diff --git a/src/applications/passphrase/query/PassphraseCredentialSearchEngine.php b/src/applications/passphrase/query/PassphraseCredentialSearchEngine.php
index f503510e5a..be4305bcff 100644
--- a/src/applications/passphrase/query/PassphraseCredentialSearchEngine.php
+++ b/src/applications/passphrase/query/PassphraseCredentialSearchEngine.php
@@ -1,129 +1,110 @@
<?php
final class PassphraseCredentialSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Passphrase Credentials');
}
public function getApplicationClassName() {
return 'PhabricatorPassphraseApplication';
}
- public function buildSavedQueryFromRequest(AphrontRequest $request) {
- $saved = new PhabricatorSavedQuery();
-
- $saved->setParameter(
- 'isDestroyed',
- $this->readBoolFromRequest($request, 'isDestroyed'));
- $saved->setParameter('name', $request->getStr('name'));
+ public function newQuery() {
+ return new PassphraseCredentialQuery();
+ }
- return $saved;
+ protected function buildCustomSearchFields() {
+ return array(
+ id(new PhabricatorSearchThreeStateField())
+ ->setLabel(pht('Status'))
+ ->setKey('isDestroyed')
+ ->setOptions(
+ pht('Show All'),
+ pht('Show Only Destroyed Credentials'),
+ pht('Show Only Active Credentials')),
+ id(new PhabricatorSearchTextField())
+ ->setLabel(pht('Name Contains'))
+ ->setKey('name'),
+ );
}
- public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
- $query = id(new PassphraseCredentialQuery());
+ protected function buildQueryFromParameters(array $map) {
+ $query = $this->newQuery();
- $destroyed = $saved->getParameter('isDestroyed');
- if ($destroyed !== null) {
- $query->withIsDestroyed($destroyed);
+ if ($map['isDestroyed'] !== null) {
+ $query->withIsDestroyed($map['isDestroyed']);
}
- $name = $saved->getParameter('name');
- if (strlen($name)) {
- $query->withNameContains($name);
+ if (strlen($map['name'])) {
+ $query->withNameContains($map['name']);
}
return $query;
}
- public function buildSearchForm(
- AphrontFormView $form,
- PhabricatorSavedQuery $saved_query) {
-
- $name = $saved_query->getParameter('name');
-
- $form
- ->appendChild(
- id(new AphrontFormSelectControl())
- ->setName('isDestroyed')
- ->setLabel(pht('Status'))
- ->setValue($this->getBoolFromQuery($saved_query, 'isDestroyed'))
- ->setOptions(
- array(
- '' => pht('Show All Credentials'),
- 'false' => pht('Show Only Active Credentials'),
- 'true' => pht('Show Only Destroyed Credentials'),
- )))
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setName('name')
- ->setLabel(pht('Name Contains'))
- ->setValue($name));
- }
-
protected function getURI($path) {
return '/passphrase/'.$path;
}
protected function getBuiltinQueryNames() {
return array(
'active' => pht('Active Credentials'),
'all' => pht('All Credentials'),
);
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'active':
return $query->setParameter('isDestroyed', false);
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $credentials,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($credentials, 'PassphraseCredential');
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($credentials as $credential) {
$item = id(new PHUIObjectItemView())
->setObjectName('K'.$credential->getID())
->setHeader($credential->getName())
->setHref('/K'.$credential->getID())
->setObject($credential);
$item->addAttribute(
pht('Login: %s', $credential->getUsername()));
if ($credential->getIsDestroyed()) {
$item->addIcon('fa-ban', pht('Destroyed'));
$item->setDisabled(true);
}
$type = PassphraseCredentialType::getTypeByConstant(
$credential->getCredentialType());
if ($type) {
$item->addIcon('fa-wrench', $type->getCredentialTypeName());
}
$list->addItem($item);
}
return $list;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 10, 9:53 PM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
141131
Default Alt Text
(9 KB)

Event Timeline