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 @@ getBaseURI().'create/'; } public function getRemarkupRules() { return array( new PhabricatorPasteRemarkupRule(), ); } public function getRoutes() { return array( '/P(?P[1-9]\d*)' => 'PhabricatorPasteViewController', '/paste/' => array( '' => 'PhabricatorPasteListController', 'create/' => 'PhabricatorPasteEditController', 'edit/(?P[1-9]\d*)/' => 'PhabricatorPasteEditController', 'filter/(?P\w+)/' => 'PhabricatorPasteListController', - 'query/(?P\w+)/'=> 'PhabricatorPasteListController', + 'query/(?P[^/]+)/'=> '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 @@ 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 @@ array( '' => 'PhabricatorSearchController', '(?P[^/]+)/' => 'PhabricatorSearchController', 'attach/(?P[^/]+)/(?P\w+)/(?:(?P\w+)/)?' => 'PhabricatorSearchAttachController', 'select/(?P\w+)/' => 'PhabricatorSearchSelectController', 'index/(?P[^/]+)/' => 'PhabricatorSearchIndexController', 'hovercard/(?Pretrieve|test)/' => 'PhabricatorSearchHovercardController', - 'name/(?P\w+)/' => 'PhabricatorSearchNameController', + 'name/(?P[^/]+)/' => '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 @@ 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 @@ 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; } }