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 @@ -53,19 +53,12 @@ final class PassphraseCredentialQuery 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) { @@ -99,61 +92,59 @@ final class PassphraseCredentialQuery return $page; } - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { - $where = array(); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); - $where[] = $this->buildPagingClause($conn_r); - - 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() { 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 @@ -11,58 +11,39 @@ final class PassphraseCredentialSearchEngine return 'PhabricatorPassphraseApplication'; } - public function buildSavedQueryFromRequest(AphrontRequest $request) { - $saved = new PhabricatorSavedQuery(); - - $saved->setParameter( - 'isDestroyed', - $this->readBoolFromRequest($request, 'isDestroyed')); - $saved->setParameter('name', $request->getStr('name')); - - return $saved; + public function newQuery() { + return new PassphraseCredentialQuery(); } - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { - $query = id(new PassphraseCredentialQuery()); + 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'), + ); + } - $destroyed = $saved->getParameter('isDestroyed'); - if ($destroyed !== null) { - $query->withIsDestroyed($destroyed); + protected function buildQueryFromParameters(array $map) { + $query = $this->newQuery(); + + 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; }