mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 09:20:58 +01:00
Move some value massaging into SearchFields
Summary: Ref T8441. Ref T7715. Let SearchFields do some value massaging before buiding queries so we don't have to work as hard in each SearchEngine. Particularly, they can handle evaluateTokens() from Tokenizers. Test Plan: Paste automatically gained access to `viewer()`, etc. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7715, T8441 Differential Revision: https://secure.phabricator.com/D13170
This commit is contained in:
parent
08966ba311
commit
65b891b095
6 changed files with 48 additions and 16 deletions
|
@ -11,21 +11,24 @@ final class PhabricatorPasteSearchEngine
|
|||
return 'PhabricatorPasteApplication';
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
public function buildQueryFromParameters(array $map) {
|
||||
$query = id(new PhabricatorPasteQuery())
|
||||
->needContent(true)
|
||||
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
|
||||
->withLanguages($saved->getParameter('languages', array()));
|
||||
->needContent(true);
|
||||
|
||||
$start = $this->parseDateTime($saved->getParameter('createdStart'));
|
||||
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
|
||||
|
||||
if ($start) {
|
||||
$query->withDateCreatedAfter($start);
|
||||
if ($map['authorPHIDs']) {
|
||||
$query->withAuthorPHIDs($map['authorPHIDs']);
|
||||
}
|
||||
|
||||
if ($end) {
|
||||
$query->withDateCreatedBefore($end);
|
||||
if ($map['languages']) {
|
||||
$query->withLanguages($map['languages']);
|
||||
}
|
||||
|
||||
if ($map['createdStart']) {
|
||||
$query->withDateCreatedAfter($map['createdStart']);
|
||||
}
|
||||
|
||||
if ($map['createdEnd']) {
|
||||
$query->withDateCreatedBefore($map['createdEnd']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
|
|
@ -90,8 +90,24 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
|
|||
* @param PhabricatorSavedQuery The saved query to operate on.
|
||||
* @return The result of the query.
|
||||
*/
|
||||
abstract public function buildQueryFromSavedQuery(
|
||||
PhabricatorSavedQuery $saved);
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$fields = $this->buildSearchFields();
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
$parameters = array();
|
||||
foreach ($fields as $field) {
|
||||
$field->setViewer($viewer);
|
||||
$field->readValueFromSavedQuery($saved);
|
||||
$value = $field->getValueForQuery($field->getValue());
|
||||
$parameters[$field->getKey()] = $value;
|
||||
}
|
||||
|
||||
return $this->buildQueryFromParameters($parameters);
|
||||
}
|
||||
|
||||
protected function buildQueryFromParameters(array $parameters) {
|
||||
throw new PhutilMethodNotImplementedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the search form using the request.
|
||||
|
|
|
@ -11,6 +11,10 @@ final class PhabricatorSearchDateField
|
|||
return $request->getStr($key);
|
||||
}
|
||||
|
||||
public function getValueForQuery($value) {
|
||||
return $this->parseDateTime($value);
|
||||
}
|
||||
|
||||
protected function validateControlValue($value) {
|
||||
if (!strlen($value)) {
|
||||
return;
|
||||
|
|
|
@ -201,6 +201,10 @@ abstract class PhabricatorSearchField extends Phobject {
|
|||
return null;
|
||||
}
|
||||
|
||||
public function getValueForQuery($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
/* -( Rendering Controls )------------------------------------------------- */
|
||||
|
||||
|
|
|
@ -11,11 +11,18 @@ abstract class PhabricatorSearchTokenizerField
|
|||
return $this->getListFromRequest($request, $key);
|
||||
}
|
||||
|
||||
public function getValueForQuery($value) {
|
||||
return $this->newDatasource()
|
||||
->setViewer($this->getViewer())
|
||||
->evaluateTokens($value);
|
||||
}
|
||||
|
||||
protected function newControl() {
|
||||
return id(new AphrontFormTokenizerControl())
|
||||
->setDatasource($this->newDatasource());
|
||||
}
|
||||
|
||||
|
||||
abstract protected function newDatasource();
|
||||
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ final class PhabricatorSearchUsersField
|
|||
}
|
||||
|
||||
protected function newDatasource() {
|
||||
// TODO: Make this use PhabricatorPeopleUserFunctionDatasource once field
|
||||
// support is a little more powerful.
|
||||
return new PhabricatorPeopleDatasource();
|
||||
return new PhabricatorPeopleUserFunctionDatasource();
|
||||
}
|
||||
|
||||
protected function getValueFromRequest(AphrontRequest $request, $key) {
|
||||
|
|
Loading…
Reference in a new issue