@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+47 -15
+13 -10
src/applications/paste/query/PhabricatorPasteSearchEngine.php
··· 11 11 return 'PhabricatorPasteApplication'; 12 12 } 13 13 14 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 14 + public function buildQueryFromParameters(array $map) { 15 15 $query = id(new PhabricatorPasteQuery()) 16 - ->needContent(true) 17 - ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())) 18 - ->withLanguages($saved->getParameter('languages', array())); 16 + ->needContent(true); 19 17 20 - $start = $this->parseDateTime($saved->getParameter('createdStart')); 21 - $end = $this->parseDateTime($saved->getParameter('createdEnd')); 18 + if ($map['authorPHIDs']) { 19 + $query->withAuthorPHIDs($map['authorPHIDs']); 20 + } 21 + 22 + if ($map['languages']) { 23 + $query->withLanguages($map['languages']); 24 + } 22 25 23 - if ($start) { 24 - $query->withDateCreatedAfter($start); 26 + if ($map['createdStart']) { 27 + $query->withDateCreatedAfter($map['createdStart']); 25 28 } 26 29 27 - if ($end) { 28 - $query->withDateCreatedBefore($end); 30 + if ($map['createdEnd']) { 31 + $query->withDateCreatedBefore($map['createdEnd']); 29 32 } 30 33 31 34 return $query;
+18 -2
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 90 90 * @param PhabricatorSavedQuery The saved query to operate on. 91 91 * @return The result of the query. 92 92 */ 93 - abstract public function buildQueryFromSavedQuery( 94 - PhabricatorSavedQuery $saved); 93 + public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 94 + $fields = $this->buildSearchFields(); 95 + $viewer = $this->requireViewer(); 96 + 97 + $parameters = array(); 98 + foreach ($fields as $field) { 99 + $field->setViewer($viewer); 100 + $field->readValueFromSavedQuery($saved); 101 + $value = $field->getValueForQuery($field->getValue()); 102 + $parameters[$field->getKey()] = $value; 103 + } 104 + 105 + return $this->buildQueryFromParameters($parameters); 106 + } 107 + 108 + protected function buildQueryFromParameters(array $parameters) { 109 + throw new PhutilMethodNotImplementedException(); 110 + } 95 111 96 112 /** 97 113 * Builds the search form using the request.
+4
src/applications/search/field/PhabricatorSearchDateField.php
··· 11 11 return $request->getStr($key); 12 12 } 13 13 14 + public function getValueForQuery($value) { 15 + return $this->parseDateTime($value); 16 + } 17 + 14 18 protected function validateControlValue($value) { 15 19 if (!strlen($value)) { 16 20 return;
+4
src/applications/search/field/PhabricatorSearchField.php
··· 201 201 return null; 202 202 } 203 203 204 + public function getValueForQuery($value) { 205 + return $value; 206 + } 207 + 204 208 205 209 /* -( Rendering Controls )------------------------------------------------- */ 206 210
+7
src/applications/search/field/PhabricatorSearchTokenizerField.php
··· 11 11 return $this->getListFromRequest($request, $key); 12 12 } 13 13 14 + public function getValueForQuery($value) { 15 + return $this->newDatasource() 16 + ->setViewer($this->getViewer()) 17 + ->evaluateTokens($value); 18 + } 19 + 14 20 protected function newControl() { 15 21 return id(new AphrontFormTokenizerControl()) 16 22 ->setDatasource($this->newDatasource()); 17 23 } 24 + 18 25 19 26 abstract protected function newDatasource(); 20 27
+1 -3
src/applications/search/field/PhabricatorSearchUsersField.php
··· 8 8 } 9 9 10 10 protected function newDatasource() { 11 - // TODO: Make this use PhabricatorPeopleUserFunctionDatasource once field 12 - // support is a little more powerful. 13 - return new PhabricatorPeopleDatasource(); 11 + return new PhabricatorPeopleUserFunctionDatasource(); 14 12 } 15 13 16 14 protected function getValueFromRequest(AphrontRequest $request, $key) {