2013-05-27 22:42:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSearchEditController
|
|
|
|
extends PhabricatorSearchBaseController {
|
|
|
|
|
2015-10-20 18:02:55 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $this->getViewer();
|
2013-05-27 22:42:01 +02:00
|
|
|
|
|
|
|
$saved_query = id(new PhabricatorSavedQueryQuery())
|
2015-10-20 18:02:55 +02:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withQueryKeys(array($request->getURIData('queryKey')))
|
2013-05-27 22:42:01 +02:00
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$saved_query) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2015-10-20 18:02:55 +02:00
|
|
|
$engine = $saved_query->newEngine()->setViewer($viewer);
|
2013-05-27 22:42:44 +02:00
|
|
|
|
|
|
|
$complete_uri = $engine->getQueryManagementURI();
|
|
|
|
$cancel_uri = $complete_uri;
|
2013-05-27 22:42:01 +02:00
|
|
|
|
|
|
|
$named_query = id(new PhabricatorNamedQueryQuery())
|
2015-10-20 18:02:55 +02:00
|
|
|
->setViewer($viewer)
|
2013-05-27 22:42:01 +02:00
|
|
|
->withQueryKeys(array($saved_query->getQueryKey()))
|
2015-10-20 18:02:55 +02:00
|
|
|
->withUserPHIDs(array($viewer->getPHID()))
|
2013-05-27 22:42:01 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$named_query) {
|
|
|
|
$named_query = id(new PhabricatorNamedQuery())
|
2015-10-20 18:02:55 +02:00
|
|
|
->setUserPHID($viewer->getPHID())
|
2013-05-27 22:42:01 +02:00
|
|
|
->setQueryKey($saved_query->getQueryKey())
|
|
|
|
->setEngineClassName($saved_query->getEngineClassName());
|
2013-05-27 22:42:44 +02:00
|
|
|
|
|
|
|
// If we haven't saved the query yet, this is a "Save..." operation, so
|
|
|
|
// take the user back to the query if they cancel instead of back to the
|
|
|
|
// management interface.
|
2013-05-27 22:43:02 +02:00
|
|
|
$cancel_uri = $engine->getQueryResultsPageURI(
|
|
|
|
$saved_query->getQueryKey());
|
2013-05-27 22:42:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$e_name = true;
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$named_query->setQueryName($request->getStr('name'));
|
|
|
|
if (!strlen($named_query->getQueryName())) {
|
|
|
|
$e_name = pht('Required');
|
|
|
|
$errors[] = pht('You must name the query.');
|
|
|
|
} else {
|
|
|
|
$e_name = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$named_query->save();
|
2013-05-27 22:42:44 +02:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($complete_uri);
|
2013-05-27 22:42:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
2015-10-20 18:02:55 +02:00
|
|
|
->setUser($viewer);
|
2013-05-27 22:42:01 +02:00
|
|
|
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('name')
|
|
|
|
->setLabel(pht('Query Name'))
|
|
|
|
->setValue($named_query->getQueryName())
|
|
|
|
->setError($e_name));
|
|
|
|
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-05-27 22:42:44 +02:00
|
|
|
->setValue(pht('Save Query'))
|
|
|
|
->addCancelButton($cancel_uri));
|
2013-05-27 22:42:01 +02:00
|
|
|
|
|
|
|
if ($named_query->getID()) {
|
|
|
|
$title = pht('Edit Saved Query');
|
|
|
|
} else {
|
|
|
|
$title = pht('Save Query');
|
|
|
|
}
|
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setHeaderText($title)
|
2014-01-10 18:17:37 +01:00
|
|
|
->setFormErrors($errors)
|
2013-08-26 20:53:11 +02:00
|
|
|
->setForm($form);
|
|
|
|
|
2013-05-27 22:42:01 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb($title);
|
2013-05-27 22:42:01 +02:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-08-26 20:53:11 +02:00
|
|
|
$form_box,
|
2013-05-27 22:42:01 +02:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|