Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2890055
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
12 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/paste/application/PhabricatorApplicationPaste.php b/src/applications/paste/application/PhabricatorApplicationPaste.php
index 92cd6bb275..006114cfec 100644
--- a/src/applications/paste/application/PhabricatorApplicationPaste.php
+++ b/src/applications/paste/application/PhabricatorApplicationPaste.php
@@ -1,45 +1,45 @@
<?php
final class PhabricatorApplicationPaste extends PhabricatorApplication {
public function getBaseURI() {
return '/paste/';
}
public function getIconName() {
return 'paste';
}
public function getTitleGlyph() {
return "\xE2\x9C\x8E";
}
public function getApplicationGroup() {
return self::GROUP_UTILITIES;
}
public function getQuickCreateURI() {
return $this->getBaseURI().'create/';
}
public function getRemarkupRules() {
return array(
new PhabricatorPasteRemarkupRule(),
);
}
public function getRoutes() {
return array(
'/P(?P<id>[1-9]\d*)' => 'PhabricatorPasteViewController',
'/paste/' => array(
'' => 'PhabricatorPasteListController',
'create/' => 'PhabricatorPasteEditController',
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
- 'query/(?P<queryKey>\w+)/'=> 'PhabricatorPasteListController',
+ 'query/(?P<queryKey>[^/]+)/'=> 'PhabricatorPasteListController',
'savedqueries/' => 'PhabricatorPasteQueriesController',
),
);
}
}
diff --git a/src/applications/paste/query/PhabricatorPasteSearchEngine.php b/src/applications/paste/query/PhabricatorPasteSearchEngine.php
index 51c18e81f8..553a7d67df 100644
--- a/src/applications/paste/query/PhabricatorPasteSearchEngine.php
+++ b/src/applications/paste/query/PhabricatorPasteSearchEngine.php
@@ -1,108 +1,112 @@
<?php
/**
* Provides search functionality for the paste application.
*
* @group search
*/
final class PhabricatorPasteSearchEngine
extends PhabricatorApplicationSearchEngine {
protected $filter;
protected $user;
/**
* 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) {
$saved = new PhabricatorSavedQuery();
if ($this->filter == "filter/my") {
$user = $request->getUser();
$saved->setParameter('authorPHIDs', array($user->getPHID()));
} else {
$data = $request->getRequestData();
if (array_key_exists('set_users', $data)) {
$saved->setParameter('authorPHIDs', $data['set_users']);
}
}
try {
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$saved->save();
unset($unguarded);
} catch (AphrontQueryDuplicateKeyException $ex) {
// Ignore, this is just a repeated search.
}
return $saved;
}
/**
* 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 AphrontFormView The built form.
*/
public function buildSearchForm(PhabricatorSavedQuery $saved_query) {
$phids = $saved_query->getParameter('authorPHIDs', array());
$handles = id(new PhabricatorObjectHandleData($phids))
->setViewer($this->user)
->loadHandles();
$users_searched = mpull($handles, 'getFullName', 'getPHID');
$form = id(new AphrontFormView())
->setUser($this->user);
$form->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/searchowner/')
->setName('set_users')
->setLabel(pht('Users'))
->setValue($users_searched));
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Filter Pastes'))
->addCancelButton(
'/search/name/'.$saved_query->getQueryKey().'/',
pht('Save Custom Query...')));
return $form;
}
public function setPasteSearchFilter($filter) {
$this->filter = $filter;
return $this;
}
public function getPasteSearchFilter() {
return $this->filter;
}
public function setPasteSearchUser($user) {
$this->user = $user;
return $this;
}
+ public function getQueryResultsPageURI(PhabricatorSavedQuery $query) {
+ return '/paste/query/'.$query->getQueryKey().'/';
+ }
+
}
diff --git a/src/applications/search/application/PhabricatorApplicationSearch.php b/src/applications/search/application/PhabricatorApplicationSearch.php
index e0e0ef4951..86945fbcdf 100644
--- a/src/applications/search/application/PhabricatorApplicationSearch.php
+++ b/src/applications/search/application/PhabricatorApplicationSearch.php
@@ -1,42 +1,42 @@
<?php
final class PhabricatorApplicationSearch extends PhabricatorApplication {
public function getBaseURI() {
return '/search/';
}
public function getName() {
return pht('Search');
}
public function getShortDescription() {
return pht('Search & Find');
}
public function getFlavorText() {
return pht('Find stuff in big piles.');
}
public function shouldAppearInLaunchView() {
return false;
}
public function getRoutes() {
return array(
'/search/' => array(
'' => 'PhabricatorSearchController',
'(?P<key>[^/]+)/' => 'PhabricatorSearchController',
'attach/(?P<phid>[^/]+)/(?P<type>\w+)/(?:(?P<action>\w+)/)?'
=> 'PhabricatorSearchAttachController',
'select/(?P<type>\w+)/'
=> 'PhabricatorSearchSelectController',
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
'hovercard/(?P<mode>retrieve|test)/' =>
'PhabricatorSearchHovercardController',
- 'name/(?P<queryKey>\w+)/' => 'PhabricatorSearchNameController',
+ 'name/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchNameController',
),
);
}
}
diff --git a/src/applications/search/controller/PhabricatorSearchNameController.php b/src/applications/search/controller/PhabricatorSearchNameController.php
index b24e0e8fc9..0a3f986549 100644
--- a/src/applications/search/controller/PhabricatorSearchNameController.php
+++ b/src/applications/search/controller/PhabricatorSearchNameController.php
@@ -1,70 +1,69 @@
<?php
/**
* @group search
*/
final class PhabricatorSearchNameController
extends PhabricatorSearchBaseController {
private $queryKey;
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
- if ($this->queryKey) {
- $saved_query = id(new PhabricatorSavedQueryQuery())
- ->setViewer($user)
- ->withQueryKeys(array($this->queryKey))
- ->executeOne();
- if (!$saved_query) {
- return new Aphront404Response();
- }
- } else {
+ $saved_query = id(new PhabricatorSavedQueryQuery())
+ ->setViewer($user)
+ ->withQueryKeys(array($this->queryKey))
+ ->executeOne();
+
+ if (!$saved_query) {
return new Aphront404Response();
}
+ $engine = $saved_query->newEngine();
+
if ($request->isFormPost()) {
$named_query = id(new PhabricatorNamedQuery())
->setUserPHID($user->getPHID())
->setQueryKey($saved_query->getQueryKey())
->setQueryName($request->getStr('name'))
->setEngineClassName($saved_query->getEngineClassName());
try {
$named_query->save();
} catch (AphrontQueryDuplicateKeyException $ex) {
// Ignore, the user is naming an identical query.
}
return id(new AphrontRedirectResponse())
- ->setURI('/search/');
+ ->setURI($engine->getQueryResultsPageURI($saved_query));
}
$form = id(new AphrontFormView())
->setUser($user);
$form->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel(pht('Query Name')));
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save')));
return $this->buildStandardPageResponse(
array(
$form,
),
array(
'title' => 'Name Query',
));
}
}
diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
index d1dedbb2de..b837042392 100644
--- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
@@ -1,37 +1,46 @@
<?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);
+
+ /**
+ * Return an application URI corresponding to the results page of a query.
+ * Normally, this is something like `/application/query/QUERYKEY/`.
+ *
+ * @param PhabricatorSavedQuery The query to build a URI for.
+ * @return string URI where the query can be executed.
+ */
+ abstract public function getQueryResultsPageURI(PhabricatorSavedQuery $query);
}
diff --git a/src/applications/search/storage/PhabricatorSavedQuery.php b/src/applications/search/storage/PhabricatorSavedQuery.php
index 460dc504d2..45da12fe46 100644
--- a/src/applications/search/storage/PhabricatorSavedQuery.php
+++ b/src/applications/search/storage/PhabricatorSavedQuery.php
@@ -1,58 +1,65 @@
<?php
/**
* @group search
*/
final class PhabricatorSavedQuery extends PhabricatorSearchDAO
implements PhabricatorPolicyInterface {
protected $parameters = array();
protected $queryKey = "";
protected $engineClassName = "PhabricatorPasteSearchEngine";
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);
}
public function save() {
if ($this->getEngineClassName() === null) {
throw new Exception(pht("Engine class is null."));
}
+ // Instantiate the engine to make sure it's valid.
+ $this->newEngine();
+
$serial = $this->getEngineClassName().serialize($this->parameters);
$this->queryKey = PhabricatorHash::digestForIndex($serial);
return parent::save();
}
+ public function newEngine() {
+ return newv($this->getEngineClassName(), array());
+ }
+
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
);
}
public function getPolicy($capability) {
return PhabricatorPolicies::POLICY_PUBLIC;
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return false;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 13:01 (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1124845
Default Alt Text
(12 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment