mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 04:50:55 +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';
|
return 'PhabricatorPasteApplication';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
public function buildQueryFromParameters(array $map) {
|
||||||
$query = id(new PhabricatorPasteQuery())
|
$query = id(new PhabricatorPasteQuery())
|
||||||
->needContent(true)
|
->needContent(true);
|
||||||
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
|
|
||||||
->withLanguages($saved->getParameter('languages', array()));
|
|
||||||
|
|
||||||
$start = $this->parseDateTime($saved->getParameter('createdStart'));
|
if ($map['authorPHIDs']) {
|
||||||
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
|
$query->withAuthorPHIDs($map['authorPHIDs']);
|
||||||
|
|
||||||
if ($start) {
|
|
||||||
$query->withDateCreatedAfter($start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($end) {
|
if ($map['languages']) {
|
||||||
$query->withDateCreatedBefore($end);
|
$query->withLanguages($map['languages']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($map['createdStart']) {
|
||||||
|
$query->withDateCreatedAfter($map['createdStart']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($map['createdEnd']) {
|
||||||
|
$query->withDateCreatedBefore($map['createdEnd']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
|
|
|
@ -90,8 +90,24 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
|
||||||
* @param PhabricatorSavedQuery The saved query to operate on.
|
* @param PhabricatorSavedQuery The saved query to operate on.
|
||||||
* @return The result of the query.
|
* @return The result of the query.
|
||||||
*/
|
*/
|
||||||
abstract public function buildQueryFromSavedQuery(
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
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.
|
* Builds the search form using the request.
|
||||||
|
|
|
@ -11,6 +11,10 @@ final class PhabricatorSearchDateField
|
||||||
return $request->getStr($key);
|
return $request->getStr($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValueForQuery($value) {
|
||||||
|
return $this->parseDateTime($value);
|
||||||
|
}
|
||||||
|
|
||||||
protected function validateControlValue($value) {
|
protected function validateControlValue($value) {
|
||||||
if (!strlen($value)) {
|
if (!strlen($value)) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -201,6 +201,10 @@ abstract class PhabricatorSearchField extends Phobject {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValueForQuery($value) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( Rendering Controls )------------------------------------------------- */
|
/* -( Rendering Controls )------------------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,18 @@ abstract class PhabricatorSearchTokenizerField
|
||||||
return $this->getListFromRequest($request, $key);
|
return $this->getListFromRequest($request, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getValueForQuery($value) {
|
||||||
|
return $this->newDatasource()
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->evaluateTokens($value);
|
||||||
|
}
|
||||||
|
|
||||||
protected function newControl() {
|
protected function newControl() {
|
||||||
return id(new AphrontFormTokenizerControl())
|
return id(new AphrontFormTokenizerControl())
|
||||||
->setDatasource($this->newDatasource());
|
->setDatasource($this->newDatasource());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
abstract protected function newDatasource();
|
abstract protected function newDatasource();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,7 @@ final class PhabricatorSearchUsersField
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function newDatasource() {
|
protected function newDatasource() {
|
||||||
// TODO: Make this use PhabricatorPeopleUserFunctionDatasource once field
|
return new PhabricatorPeopleUserFunctionDatasource();
|
||||||
// support is a little more powerful.
|
|
||||||
return new PhabricatorPeopleDatasource();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getValueFromRequest(AphrontRequest $request, $key) {
|
protected function getValueFromRequest(AphrontRequest $request, $key) {
|
||||||
|
|
Loading…
Reference in a new issue