diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index aa152dc968..7d2641f5a0 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1366,6 +1366,7 @@ phutil_register_library_map(array( 'PhabricatorSearchDocumentField' => 'applications/search/storage/document/PhabricatorSearchDocumentField.php', 'PhabricatorSearchDocumentIndexer' => 'applications/search/index/PhabricatorSearchDocumentIndexer.php', 'PhabricatorSearchDocumentRelationship' => 'applications/search/storage/document/PhabricatorSearchDocumentRelationship.php', + 'PhabricatorSearchEditController' => 'applications/search/controller/PhabricatorSearchEditController.php', 'PhabricatorSearchEngine' => 'applications/search/engine/PhabricatorSearchEngine.php', 'PhabricatorSearchEngineElastic' => 'applications/search/engine/PhabricatorSearchEngineElastic.php', 'PhabricatorSearchEngineMySQL' => 'applications/search/engine/PhabricatorSearchEngineMySQL.php', @@ -1375,7 +1376,6 @@ phutil_register_library_map(array( 'PhabricatorSearchIndexer' => 'applications/search/index/PhabricatorSearchIndexer.php', 'PhabricatorSearchManagementIndexWorkflow' => 'applications/search/management/PhabricatorSearchManagementIndexWorkflow.php', 'PhabricatorSearchManagementWorkflow' => 'applications/search/management/PhabricatorSearchManagementWorkflow.php', - 'PhabricatorSearchNameController' => 'applications/search/controller/PhabricatorSearchNameController.php', 'PhabricatorSearchQuery' => 'applications/search/storage/PhabricatorSearchQuery.php', 'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php', 'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php', @@ -3150,12 +3150,12 @@ phutil_register_library_map(array( 'PhabricatorSearchDocument' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentRelationship' => 'PhabricatorSearchDAO', + 'PhabricatorSearchEditController' => 'PhabricatorSearchBaseController', 'PhabricatorSearchEngineElastic' => 'PhabricatorSearchEngine', 'PhabricatorSearchEngineMySQL' => 'PhabricatorSearchEngine', 'PhabricatorSearchHovercardController' => 'PhabricatorSearchBaseController', 'PhabricatorSearchManagementIndexWorkflow' => 'PhabricatorSearchManagementWorkflow', 'PhabricatorSearchManagementWorkflow' => 'PhutilArgumentWorkflow', - 'PhabricatorSearchNameController' => 'PhabricatorSearchBaseController', 'PhabricatorSearchQuery' => 'PhabricatorSearchDAO', 'PhabricatorSearchResultView' => 'AphrontView', 'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController', diff --git a/src/applications/paste/controller/PhabricatorPasteQueriesController.php b/src/applications/paste/controller/PhabricatorPasteQueriesController.php index 5bafa4a821..2e6e1ea631 100644 --- a/src/applications/paste/controller/PhabricatorPasteQueriesController.php +++ b/src/applications/paste/controller/PhabricatorPasteQueriesController.php @@ -27,7 +27,11 @@ final class PhabricatorPasteQueriesController $item = id(new PhabricatorObjectItemView()) ->setHeader($named_query->getQueryName()) ->setHref('/paste/query/'.$named_query->getQueryKey().'/') - ->addIcon('none', $date_created); + ->addIcon('none', $date_created) + ->addAction( + id(new PhabricatorMenuItemView()) + ->setIcon('edit') + ->setHref('/search/edit/'.$named_query->getQueryKey().'/')); $list->addItem($item); } diff --git a/src/applications/paste/query/PhabricatorPasteSearchEngine.php b/src/applications/paste/query/PhabricatorPasteSearchEngine.php index 553a7d67df..afd7db4e82 100644 --- a/src/applications/paste/query/PhabricatorPasteSearchEngine.php +++ b/src/applications/paste/query/PhabricatorPasteSearchEngine.php @@ -85,7 +85,7 @@ final class PhabricatorPasteSearchEngine id(new AphrontFormSubmitControl()) ->setValue(pht('Filter Pastes')) ->addCancelButton( - '/search/name/'.$saved_query->getQueryKey().'/', + '/search/edit/'.$saved_query->getQueryKey().'/', pht('Save Custom Query...'))); return $form; diff --git a/src/applications/search/application/PhabricatorApplicationSearch.php b/src/applications/search/application/PhabricatorApplicationSearch.php index 86945fbcdf..26e20148f4 100644 --- a/src/applications/search/application/PhabricatorApplicationSearch.php +++ b/src/applications/search/application/PhabricatorApplicationSearch.php @@ -34,7 +34,7 @@ final class PhabricatorApplicationSearch extends PhabricatorApplication { 'index/(?P[^/]+)/' => 'PhabricatorSearchIndexController', 'hovercard/(?Pretrieve|test)/' => 'PhabricatorSearchHovercardController', - 'name/(?P[^/]+)/' => 'PhabricatorSearchNameController', + 'edit/(?P[^/]+)/' => 'PhabricatorSearchEditController', ), ); } diff --git a/src/applications/search/controller/PhabricatorSearchEditController.php b/src/applications/search/controller/PhabricatorSearchEditController.php new file mode 100644 index 0000000000..a2cbfcc33b --- /dev/null +++ b/src/applications/search/controller/PhabricatorSearchEditController.php @@ -0,0 +1,106 @@ +queryKey = idx($data, 'queryKey'); + } + + public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); + + $saved_query = id(new PhabricatorSavedQueryQuery()) + ->setViewer($user) + ->withQueryKeys(array($this->queryKey)) + ->executeOne(); + + if (!$saved_query) { + return new Aphront404Response(); + } + + $engine = $saved_query->newEngine(); + + $named_query = id(new PhabricatorNamedQueryQuery()) + ->setViewer($user) + ->withQueryKeys(array($saved_query->getQueryKey())) + ->withUserPHIDs(array($user->getPHID())) + ->executeOne(); + if (!$named_query) { + $named_query = id(new PhabricatorNamedQuery()) + ->setUserPHID($user->getPHID()) + ->setQueryKey($saved_query->getQueryKey()) + ->setEngineClassName($saved_query->getEngineClassName()); + } + + $e_name = true; + $errors = array(); + + if ($request->isFormPost()) { + $named_query->setQueryName($request->getStr('name')); + if (!strlen($named_query->getQueryName())) { + $e_name = pht('Required'); + $errors[] = pht('You must name the query.'); + } else { + $e_name = null; + } + + if (!$errors) { + $named_query->save(); + + $results_uri = $engine->getQueryResultsPageURI($saved_query); + return id(new AphrontRedirectResponse())->setURI($results_uri); + } + } + + if ($errors) { + $errors = id(new AphrontErrorView()) + ->setErrors($errors); + } + + $form = id(new AphrontFormView()) + ->setUser($user); + + $form->appendChild( + id(new AphrontFormTextControl()) + ->setName('name') + ->setLabel(pht('Query Name')) + ->setValue($named_query->getQueryName()) + ->setError($e_name)); + + $form->appendChild( + id(new AphrontFormSubmitControl()) + ->setValue(pht('Save Query'))); + + if ($named_query->getID()) { + $title = pht('Edit Saved Query'); + } else { + $title = pht('Save Query'); + } + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addCrumb( + id(new PhabricatorCrumbView()) + ->setName($title)); + + return $this->buildApplicationPage( + array( + $crumbs, + $errors, + $form, + ), + array( + 'title' => $title, + 'device' => true, + 'dust' => true, + )); + } + + +} diff --git a/src/applications/search/controller/PhabricatorSearchNameController.php b/src/applications/search/controller/PhabricatorSearchNameController.php deleted file mode 100644 index 0a3f986549..0000000000 --- a/src/applications/search/controller/PhabricatorSearchNameController.php +++ /dev/null @@ -1,69 +0,0 @@ -queryKey = idx($data, 'queryKey'); - } - - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); - - $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($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', - )); - } - - -}