forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorSearchDeleteController.php
100 lines (83 loc) · 2.94 KB
/
PhabricatorSearchDeleteController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
final class PhabricatorSearchDeleteController
extends PhabricatorSearchBaseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$id = $request->getURIData('id');
if ($id) {
$named_query = id(new PhabricatorNamedQueryQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$named_query) {
return new Aphront404Response();
}
$engine = newv($named_query->getEngineClassName(), array());
$engine->setViewer($viewer);
$key = $named_query->getQueryKey();
} else {
$key = $request->getURIData('queryKey');
$engine_class = $request->getURIData('engine');
$base_class = 'PhabricatorApplicationSearchEngine';
if (!is_subclass_of($engine_class, $base_class)) {
return new Aphront400Response();
}
$engine = newv($engine_class, array());
$engine->setViewer($viewer);
if (!$engine->isBuiltinQuery($key)) {
return new Aphront404Response();
}
$named_query = $engine->getBuiltinQuery($key);
}
$builtin = null;
if ($engine->isBuiltinQuery($key)) {
$builtin = $engine->getBuiltinQuery($key);
}
$return_uri = $engine->getQueryManagementURI();
if ($request->isDialogFormPost()) {
if ($named_query->getIsBuiltin()) {
$named_query->setIsDisabled((int)(!$named_query->getIsDisabled()));
$named_query->save();
} else {
$named_query->delete();
}
return id(new AphrontRedirectResponse())->setURI($return_uri);
}
if ($named_query->getIsBuiltin()) {
if ($named_query->getIsDisabled()) {
$title = pht('Enable Query?');
$desc = pht(
'Enable the built-in query "%s"? It will appear in your menu again.',
$builtin->getQueryName());
$button = pht('Enable Query');
} else {
$title = pht('Disable Query?');
$desc = pht(
'This built-in query can not be deleted, but you can disable it so '.
'it does not appear in your query menu. You can enable it again '.
'later. Disable built-in query "%s"?',
$builtin->getQueryName());
$button = pht('Disable Query');
}
} else {
$title = pht('Really Delete Query?');
$desc = pht(
'Really delete the query "%s"? You can not undo this. Remember '.
'all the great times you had filtering results together?',
$named_query->getQueryName());
$button = pht('Delete Query');
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle($title)
->appendChild($desc)
->addCancelButton($return_uri)
->addSubmitButton($button);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}