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())
22 ->withEngineClassNames(array($engine_class))
23 ->withQueryKeys(array($key))
27 PhabricatorNamedQuery
::SCOPE_GLOBAL
,
31 if (!$named_query && $engine->isBuiltinQuery($key)) {
32 $named_query = $engine->getBuiltinQuery($key);
36 return new Aphront404Response();
39 $return_uri = $engine->getQueryManagementURI();
42 if ($engine->isBuiltinQuery($key)) {
43 $builtin = $engine->getBuiltinQuery($key);
46 if ($request->isFormPost()) {
47 $config = id(new PhabricatorNamedQueryConfigQuery())
49 ->withEngineClassNames(array($engine_class))
50 ->withScopePHIDs(array($viewer->getPHID()))
53 $config = PhabricatorNamedQueryConfig
::initializeNewQueryConfig()
54 ->setEngineClassName($engine_class)
55 ->setScopePHID($viewer->getPHID());
58 $config->setConfigProperty(
59 PhabricatorNamedQueryConfig
::PROPERTY_PINNED
,
64 return id(new AphrontRedirectResponse())->setURI($return_uri);
67 if ($named_query->getIsBuiltin()) {
68 $query_name = $builtin->getQueryName();
70 $query_name = $named_query->getQueryName();
73 $title = pht('Set Default Query');
75 'This query will become your default query in the current application.');
76 $button = pht('Set Default Query');
78 return $this->newDialog()
81 ->addCancelButton($return_uri)
82 ->addSubmitButton($button);