2013-05-27 22:42:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSearchDeleteController
|
|
|
|
extends PhabricatorSearchBaseController {
|
|
|
|
|
|
|
|
private $queryKey;
|
2013-06-05 14:28:25 +02:00
|
|
|
private $engineClass;
|
2013-05-27 22:42:44 +02:00
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->queryKey = idx($data, 'queryKey');
|
2013-06-05 14:28:25 +02:00
|
|
|
$this->engineClass = idx($data, 'engine');
|
2013-05-27 22:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
2013-06-05 14:28:25 +02:00
|
|
|
$key = $this->queryKey;
|
2013-05-27 22:42:44 +02:00
|
|
|
|
2013-06-05 14:28:25 +02:00
|
|
|
$base_class = 'PhabricatorApplicationSearchEngine';
|
|
|
|
if (!is_subclass_of($this->engineClass, $base_class)) {
|
|
|
|
return new Aphront400Response();
|
2013-05-27 22:42:44 +02:00
|
|
|
}
|
|
|
|
|
2013-06-05 14:28:25 +02:00
|
|
|
$engine = newv($this->engineClass, array());
|
|
|
|
$engine->setViewer($user);
|
2013-05-27 22:42:44 +02:00
|
|
|
|
|
|
|
$named_query = id(new PhabricatorNamedQueryQuery())
|
|
|
|
->setViewer($user)
|
2013-06-05 14:28:25 +02:00
|
|
|
->withEngineClassNames(array($this->engineClass))
|
|
|
|
->withQueryKeys(array($key))
|
2013-05-27 22:42:44 +02:00
|
|
|
->withUserPHIDs(array($user->getPHID()))
|
|
|
|
->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())
|
|
|
|
->setUser($user)
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|