Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / controller / PhabricatorSearchDefaultController.php
bloba4f68e503aed5aff7686d24b1fe8db388d3781fb
1 <?php
3 final class PhabricatorSearchDefaultController
4 extends PhabricatorSearchBaseController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
8 $engine_class = $request->getURIData('engine');
10 $base_class = 'PhabricatorApplicationSearchEngine';
11 if (!is_subclass_of($engine_class, $base_class)) {
12 return new Aphront400Response();
15 $engine = newv($engine_class, array());
16 $engine->setViewer($viewer);
18 $key = $request->getURIData('queryKey');
20 $named_query = id(new PhabricatorNamedQueryQuery())
21 ->setViewer($viewer)
22 ->withEngineClassNames(array($engine_class))
23 ->withQueryKeys(array($key))
24 ->withUserPHIDs(
25 array(
26 $viewer->getPHID(),
27 PhabricatorNamedQuery::SCOPE_GLOBAL,
29 ->executeOne();
31 if (!$named_query && $engine->isBuiltinQuery($key)) {
32 $named_query = $engine->getBuiltinQuery($key);
35 if (!$named_query) {
36 return new Aphront404Response();
39 $return_uri = $engine->getQueryManagementURI();
41 $builtin = null;
42 if ($engine->isBuiltinQuery($key)) {
43 $builtin = $engine->getBuiltinQuery($key);
46 if ($request->isFormPost()) {
47 $config = id(new PhabricatorNamedQueryConfigQuery())
48 ->setViewer($viewer)
49 ->withEngineClassNames(array($engine_class))
50 ->withScopePHIDs(array($viewer->getPHID()))
51 ->executeOne();
52 if (!$config) {
53 $config = PhabricatorNamedQueryConfig::initializeNewQueryConfig()
54 ->setEngineClassName($engine_class)
55 ->setScopePHID($viewer->getPHID());
58 $config->setConfigProperty(
59 PhabricatorNamedQueryConfig::PROPERTY_PINNED,
60 $key);
62 $config->save();
64 return id(new AphrontRedirectResponse())->setURI($return_uri);
67 if ($named_query->getIsBuiltin()) {
68 $query_name = $builtin->getQueryName();
69 } else {
70 $query_name = $named_query->getQueryName();
73 $title = pht('Set Default Query');
74 $body = pht(
75 'This query will become your default query in the current application.');
76 $button = pht('Set Default Query');
78 return $this->newDialog()
79 ->setTitle($title)
80 ->appendChild($body)
81 ->addCancelButton($return_uri)
82 ->addSubmitButton($button);