mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 05:42:40 +01:00
Move paste search to generic search.
Summary: Begin implementing generic application search and refactoring paste search. Test Plan: See if the paste search still works. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5621
This commit is contained in:
parent
a1664d4c64
commit
1b4f03b5a8
5 changed files with 121 additions and 5 deletions
|
@ -724,6 +724,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationReleeph' => 'applications/releeph/application/PhabricatorApplicationReleeph.php',
|
||||
'PhabricatorApplicationReleephConfigOptions' => 'applications/releeph/config/PhabricatorApplicationReleephConfigOptions.php',
|
||||
'PhabricatorApplicationRepositories' => 'applications/repository/application/PhabricatorApplicationRepositories.php',
|
||||
'PhabricatorApplicationSearchEngine' => 'applications/search/engine/PhabricatorApplicationSearchEngine.php',
|
||||
'PhabricatorApplicationSettings' => 'applications/settings/application/PhabricatorApplicationSettings.php',
|
||||
'PhabricatorApplicationSlowvote' => 'applications/slowvote/application/PhabricatorApplicationSlowvote.php',
|
||||
'PhabricatorApplicationStatusView' => 'applications/meta/view/PhabricatorApplicationStatusView.php',
|
||||
|
@ -1193,6 +1194,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
|
||||
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
||||
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
||||
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
||||
'PhabricatorPasteViewController' => 'applications/paste/controller/PhabricatorPasteViewController.php',
|
||||
'PhabricatorPeopleController' => 'applications/people/controller/PhabricatorPeopleController.php',
|
||||
'PhabricatorPeopleEditController' => 'applications/people/controller/PhabricatorPeopleEditController.php',
|
||||
|
@ -1297,6 +1299,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorS3FileStorageEngine' => 'applications/files/engine/PhabricatorS3FileStorageEngine.php',
|
||||
'PhabricatorSQLPatchList' => 'infrastructure/storage/patch/PhabricatorSQLPatchList.php',
|
||||
'PhabricatorSSHWorkflow' => 'infrastructure/ssh/PhabricatorSSHWorkflow.php',
|
||||
'PhabricatorSavedQuery' => 'applications/search/storage/PhabricatorSavedQuery.php',
|
||||
'PhabricatorScopedEnv' => 'infrastructure/env/PhabricatorScopedEnv.php',
|
||||
'PhabricatorSearchAbstractDocument' => 'applications/search/index/PhabricatorSearchAbstractDocument.php',
|
||||
'PhabricatorSearchAttachController' => 'applications/search/controller/PhabricatorSearchAttachController.php',
|
||||
|
@ -2873,6 +2876,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasteListController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorPasteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
||||
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorPasteViewController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPeopleController' => 'PhabricatorController',
|
||||
'PhabricatorPeopleEditController' => 'PhabricatorPeopleController',
|
||||
|
|
|
@ -16,16 +16,14 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
|||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$query = id(new PhabricatorPasteQuery())
|
||||
->setViewer($user)
|
||||
->needContent(true);
|
||||
$saved_query = new PhabricatorSavedQuery();
|
||||
|
||||
$nav = $this->buildSideNavView($this->filter);
|
||||
$filter = $nav->getSelectedFilter();
|
||||
|
||||
switch ($filter) {
|
||||
case 'my':
|
||||
$query->withAuthorPHIDs(array($user->getPHID()));
|
||||
$saved_query->setParameter('authorPHIDs', array($user->getPHID()));
|
||||
$title = pht('My Pastes');
|
||||
$nodata = pht("You haven't created any Pastes yet.");
|
||||
break;
|
||||
|
@ -37,7 +35,11 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
|||
|
||||
$pager = new AphrontCursorPagerView();
|
||||
$pager->readFromRequest($request);
|
||||
$pastes = $query->executeWithCursorPager($pager);
|
||||
$engine = new PhabricatorPasteSearchEngine();
|
||||
$query = $engine->buildQueryFromSavedQuery($saved_query);
|
||||
$pastes = $query->setViewer($request->getUser())
|
||||
->needContent(true)
|
||||
->executeWithCursorPager($pager);
|
||||
|
||||
$list = $this->buildPasteList($pastes);
|
||||
$list->setPager($pager);
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Provides search functionality for the paste application.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
final class PhabricatorPasteSearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
/**
|
||||
* Create a saved query object from the request.
|
||||
*
|
||||
* @param AphrontRequest The search request.
|
||||
* @return The saved query that is built.
|
||||
*/
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$query = new PhabricatorSavedQuery();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the saved query.
|
||||
*
|
||||
* @param PhabricatorSavedQuery
|
||||
* @return The result of the query.
|
||||
*/
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new PhabricatorPasteQuery())
|
||||
->withIDs($saved->getParameter('ids', array()))
|
||||
->withPHIDs($saved->getParameter('phids', array()))
|
||||
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
|
||||
->withParentPHIDs($saved->getParameter('parentPHIDs', array()));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the search form using the request.
|
||||
*
|
||||
* @param PhabricatorSavedQuery The query to populate the form with.
|
||||
* @return void
|
||||
*/
|
||||
public function buildSearchForm(PhabricatorSavedQuery $saved_query) {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Represents an abstract search engine for an application. It supports
|
||||
* creating and storing saved queries.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
abstract class PhabricatorApplicationSearchEngine {
|
||||
|
||||
/**
|
||||
* Create a saved query object from the request.
|
||||
*
|
||||
* @param AphrontRequest The search request.
|
||||
* @return PhabricatorSavedQuery
|
||||
*/
|
||||
abstract public function buildSavedQueryFromRequest(
|
||||
AphrontRequest $request);
|
||||
|
||||
/**
|
||||
* Executes the saved query.
|
||||
*
|
||||
* @param PhabricatorSavedQuery The saved query to operate on.
|
||||
* @return The result of the query.
|
||||
*/
|
||||
abstract public function buildQueryFromSavedQuery(
|
||||
PhabricatorSavedQuery $saved);
|
||||
|
||||
/**
|
||||
* Builds the search form using the request.
|
||||
*
|
||||
* @param PhabricatorSavedQuery The query from which to build the form.
|
||||
* @return void
|
||||
*/
|
||||
abstract public function buildSearchForm(PhabricatorSavedQuery $query);
|
||||
|
||||
}
|
25
src/applications/search/storage/PhabricatorSavedQuery.php
Normal file
25
src/applications/search/storage/PhabricatorSavedQuery.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @group search
|
||||
*/
|
||||
final class PhabricatorSavedQuery extends PhabricatorSearchDAO {
|
||||
|
||||
protected $parameters = array();
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_SERIALIZATION => array(
|
||||
'parameters' => self::SERIALIZATION_JSON), )
|
||||
+ parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function setParameter($key, $value) {
|
||||
$this->parameters[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getParameter($key, $default = null) {
|
||||
return idx($this->parameters, $key, $default);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue