1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-11 17:32:41 +01:00
phorge-phorge/src/applications/search/controller/PhabricatorSearchDeleteController.php
epriestley 3db82cb2ec Allow custom queries to be deleted
Summary:
Ref T2625. Currently, custom saved queries can be edited but not deleted. Allow them to be deleted. Also:

  - Clean up an unused property in `PhabricatorPasteViewController`.
  - Fix an issue with left nav highlighting of builtin queries.
  - Improve submit behavior for edits.
  - Add a cancel button on edits.

Test Plan: Saved, edited and deleted queries.

Reviewers: btrahan, blc

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

Differential Revision: https://secure.phabricator.com/D6059
2013-05-27 13:42:44 -07:00

60 lines
1.5 KiB
PHP

<?php
/**
* @group search
*/
final class PhabricatorSearchDeleteController
extends PhabricatorSearchBaseController {
private $queryKey;
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($this->queryKey))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();
}
$engine = $saved_query->newEngine();
$named_query = id(new PhabricatorNamedQueryQuery())
->setViewer($user)
->withQueryKeys(array($saved_query->getQueryKey()))
->withUserPHIDs(array($user->getPHID()))
->executeOne();
if (!$named_query) {
return new Aphront404Response();
}
$return_uri = $engine->getQueryManagementURI();
if ($request->isDialogFormPost()) {
$named_query->delete();
return id(new AphrontRedirectResponse())->setURI($return_uri);
}
$dialog = id(new AphrontDialogView())
->setUser($user)
->setTitle(pht("Really Delete Query?"))
->appendChild(
pht(
'Really delete the query "%s"? You can not undo this. Remember '.
'all the great times you had filtering results together?',
$named_query->getQueryName()))
->addCancelButton($return_uri)
->addSubmitButton(pht('Delete Query'));
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}