3 final class PhabricatorSearchDeleteController
4 extends PhabricatorSearchBaseController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $this->getViewer();
9 $id = $request->getURIData('id');
11 $named_query = id(new PhabricatorNamedQueryQuery())
14 ->requireCapabilities(
16 PhabricatorPolicyCapability
::CAN_VIEW
,
17 PhabricatorPolicyCapability
::CAN_EDIT
,
21 return new Aphront404Response();
24 $engine = newv($named_query->getEngineClassName(), array());
25 $engine->setViewer($viewer);
27 $key = $named_query->getQueryKey();
29 $key = $request->getURIData('queryKey');
30 $engine_class = $request->getURIData('engine');
32 $base_class = 'PhabricatorApplicationSearchEngine';
33 if (!is_subclass_of($engine_class, $base_class)) {
34 return new Aphront400Response();
37 $engine = newv($engine_class, array());
38 $engine->setViewer($viewer);
40 if (!$engine->isBuiltinQuery($key)) {
41 return new Aphront404Response();
44 $named_query = $engine->getBuiltinQuery($key);
46 // After loading a global query, make sure the viewer actually has
47 // permission to view and edit it.
49 PhabricatorPolicyFilter
::requireCapability(
52 PhabricatorPolicyCapability
::CAN_VIEW
);
54 PhabricatorPolicyFilter
::requireCapability(
57 PhabricatorPolicyCapability
::CAN_EDIT
);
61 if ($engine->isBuiltinQuery($key)) {
62 $builtin = $engine->getBuiltinQuery($key);
65 $return_uri = $engine->getQueryManagementURI();
67 if ($request->isDialogFormPost()) {
68 if ($named_query->getIsBuiltin()) {
69 $named_query->setIsDisabled((int)(!$named_query->getIsDisabled()));
72 $named_query->delete();
75 return id(new AphrontRedirectResponse())->setURI($return_uri);
78 if ($named_query->getIsBuiltin()) {
79 if ($named_query->getIsDisabled()) {
80 $title = pht('Enable Query?');
82 'Enable the built-in query "%s"? It will appear in your menu again.',
83 $builtin->getQueryName());
84 $button = pht('Enable Query');
86 $title = pht('Disable Query?');
88 'This built-in query can not be deleted, but you can disable it so '.
89 'it does not appear in your query menu. You can enable it again '.
90 'later. Disable built-in query "%s"?',
91 $builtin->getQueryName());
92 $button = pht('Disable Query');
95 $title = pht('Really Delete Query?');
97 'Really delete the query "%s"? You can not undo this. Remember '.
98 'all the great times you had filtering results together?',
99 $named_query->getQueryName());
100 $button = pht('Delete Query');
103 $dialog = id(new AphrontDialogView())
107 ->addCancelButton($return_uri)
108 ->addSubmitButton($button);
110 return id(new AphrontDialogResponse())->setDialog($dialog);