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);
48 if ($engine->isBuiltinQuery($key)) {
49 $builtin = $engine->getBuiltinQuery($key);
52 $return_uri = $engine->getQueryManagementURI();
54 if ($request->isDialogFormPost()) {
55 if ($named_query->getIsBuiltin()) {
56 $named_query->setIsDisabled((int)(!$named_query->getIsDisabled()));
59 $named_query->delete();
62 return id(new AphrontRedirectResponse())->setURI($return_uri);
65 if ($named_query->getIsBuiltin()) {
66 if ($named_query->getIsDisabled()) {
67 $title = pht('Enable Query?');
69 'Enable the built-in query "%s"? It will appear in your menu again.',
70 $builtin->getQueryName());
71 $button = pht('Enable Query');
73 $title = pht('Disable Query?');
75 'This built-in query can not be deleted, but you can disable it so '.
76 'it does not appear in your query menu. You can enable it again '.
77 'later. Disable built-in query "%s"?',
78 $builtin->getQueryName());
79 $button = pht('Disable Query');
82 $title = pht('Really Delete Query?');
84 'Really delete the query "%s"? You can not undo this. Remember '.
85 'all the great times you had filtering results together?',
86 $named_query->getQueryName());
87 $button = pht('Delete Query');
90 $dialog = id(new AphrontDialogView())
94 ->addCancelButton($return_uri)
95 ->addSubmitButton($button);
97 return id(new AphrontDialogResponse())->setDialog($dialog);