2013-05-27 22:42:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSearchDeleteController
|
|
|
|
extends PhabricatorSearchBaseController {
|
|
|
|
|
2015-10-20 18:02:55 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$key = $request->getURIData('queryKey');
|
|
|
|
$engine_class = $request->getURIData('engine');
|
2013-05-27 22:42:44 +02:00
|
|
|
|
2013-06-05 14:28:25 +02:00
|
|
|
$base_class = 'PhabricatorApplicationSearchEngine';
|
2015-10-20 18:02:55 +02:00
|
|
|
if (!is_subclass_of($engine_class, $base_class)) {
|
2013-06-05 14:28:25 +02:00
|
|
|
return new Aphront400Response();
|
2013-05-27 22:42:44 +02:00
|
|
|
}
|
|
|
|
|
2015-10-20 18:02:55 +02:00
|
|
|
$engine = newv($engine_class, array());
|
|
|
|
$engine->setViewer($viewer);
|
2013-05-27 22:42:44 +02:00
|
|
|
|
|
|
|
$named_query = id(new PhabricatorNamedQueryQuery())
|
2015-10-20 18:02:55 +02:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withEngineClassNames(array($engine_class))
|
2013-06-05 14:28:25 +02:00
|
|
|
->withQueryKeys(array($key))
|
2015-10-20 18:02:55 +02:00
|
|
|
->withUserPHIDs(array($viewer->getPHID()))
|
2013-05-27 22:42:44 +02:00
|
|
|
->executeOne();
|
2013-06-05 14:28:25 +02:00
|
|
|
|
|
|
|
if (!$named_query && $engine->isBuiltinQuery($key)) {
|
2013-06-06 01:22:27 +02:00
|
|
|
$named_query = $engine->getBuiltinQuery($key);
|
2013-06-05 14:28:25 +02:00
|
|
|
}
|
|
|
|
|
2013-05-27 22:42:44 +02:00
|
|
|
if (!$named_query) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2013-06-05 14:28:25 +02:00
|
|
|
$builtin = null;
|
|
|
|
if ($engine->isBuiltinQuery($key)) {
|
|
|
|
$builtin = $engine->getBuiltinQuery($key);
|
|
|
|
}
|
|
|
|
|
2013-05-27 22:42:44 +02:00
|
|
|
$return_uri = $engine->getQueryManagementURI();
|
|
|
|
|
|
|
|
if ($request->isDialogFormPost()) {
|
2013-06-05 14:28:25 +02:00
|
|
|
if ($named_query->getIsBuiltin()) {
|
|
|
|
$named_query->setIsDisabled((int)(!$named_query->getIsDisabled()));
|
|
|
|
$named_query->save();
|
|
|
|
} else {
|
|
|
|
$named_query->delete();
|
|
|
|
}
|
|
|
|
|
2013-05-27 22:42:44 +02:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($return_uri);
|
|
|
|
}
|
|
|
|
|
2013-06-05 14:28:25 +02:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2013-05-27 22:42:44 +02:00
|
|
|
$dialog = id(new AphrontDialogView())
|
2015-10-20 18:02:55 +02:00
|
|
|
->setUser($viewer)
|
2013-06-05 14:28:25 +02:00
|
|
|
->setTitle($title)
|
|
|
|
->appendChild($desc)
|
2013-05-27 22:42:44 +02:00
|
|
|
->addCancelButton($return_uri)
|
2013-06-05 14:28:25 +02:00
|
|
|
->addSubmitButton($button);
|
2013-05-27 22:42:44 +02:00
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|