mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Add ability to name saved queries.
Summary: Can name saved queries. Test Plan: Try naming some saved queries using the form. Reviewers: epriestley CC: aran, Korvin, AnhNhan Maniphest Tasks: T2625 Differential Revision: https://secure.phabricator.com/D5878 Conflicts: src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
This commit is contained in:
parent
c36f44a014
commit
3c1f402da3
10 changed files with 182 additions and 2 deletions
12
resources/sql/patches/20130508.search_namedquery.sql
Normal file
12
resources/sql/patches/20130508.search_namedquery.sql
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
CREATE TABLE {$NAMESPACE}_search.search_namedquery (
|
||||||
|
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||||
|
userPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
|
||||||
|
engineClassName VARCHAR(128) NOT NULL COLLATE utf8_bin,
|
||||||
|
queryName VARCHAR(255) NOT NULL COLLATE utf8_bin,
|
||||||
|
queryKey VARCHAR(12) NOT NULL COLLATE utf8_bin,
|
||||||
|
dateCreated INT(10) UNSIGNED NOT NULL,
|
||||||
|
dateModified INT(10) UNSIGNED NOT NULL,
|
||||||
|
UNIQUE KEY `key_userquery` (userPHID, engineClassName, queryKey),
|
||||||
|
PRIMARY KEY(id)
|
||||||
|
)
|
||||||
|
ENGINE=InnoDB, COLLATE utf8_general_ci
|
|
@ -1115,6 +1115,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorMustVerifyEmailController' => 'applications/auth/controller/PhabricatorMustVerifyEmailController.php',
|
'PhabricatorMustVerifyEmailController' => 'applications/auth/controller/PhabricatorMustVerifyEmailController.php',
|
||||||
'PhabricatorMySQLConfigOptions' => 'applications/config/option/PhabricatorMySQLConfigOptions.php',
|
'PhabricatorMySQLConfigOptions' => 'applications/config/option/PhabricatorMySQLConfigOptions.php',
|
||||||
'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/PhabricatorMySQLFileStorageEngine.php',
|
'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/PhabricatorMySQLFileStorageEngine.php',
|
||||||
|
'PhabricatorNamedQuery' => 'applications/search/storage/PhabricatorNamedQuery.php',
|
||||||
'PhabricatorNoteExample' => 'applications/uiexample/examples/PhabricatorNoteExample.php',
|
'PhabricatorNoteExample' => 'applications/uiexample/examples/PhabricatorNoteExample.php',
|
||||||
'PhabricatorNotificationBuilder' => 'applications/notification/builder/PhabricatorNotificationBuilder.php',
|
'PhabricatorNotificationBuilder' => 'applications/notification/builder/PhabricatorNotificationBuilder.php',
|
||||||
'PhabricatorNotificationClearController' => 'applications/notification/controller/PhabricatorNotificationClearController.php',
|
'PhabricatorNotificationClearController' => 'applications/notification/controller/PhabricatorNotificationClearController.php',
|
||||||
|
@ -1198,6 +1199,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
|
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
|
||||||
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
|
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
|
||||||
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
|
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
|
||||||
|
'PhabricatorPasteQueriesController' => 'applications/paste/controller/PhabricatorPasteQueriesController.php',
|
||||||
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
|
||||||
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
|
||||||
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
|
||||||
|
@ -1331,6 +1333,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSearchIndexer' => 'applications/search/index/PhabricatorSearchIndexer.php',
|
'PhabricatorSearchIndexer' => 'applications/search/index/PhabricatorSearchIndexer.php',
|
||||||
'PhabricatorSearchManagementIndexWorkflow' => 'applications/search/management/PhabricatorSearchManagementIndexWorkflow.php',
|
'PhabricatorSearchManagementIndexWorkflow' => 'applications/search/management/PhabricatorSearchManagementIndexWorkflow.php',
|
||||||
'PhabricatorSearchManagementWorkflow' => 'applications/search/management/PhabricatorSearchManagementWorkflow.php',
|
'PhabricatorSearchManagementWorkflow' => 'applications/search/management/PhabricatorSearchManagementWorkflow.php',
|
||||||
|
'PhabricatorSearchNameController' => 'applications/search/controller/PhabricatorSearchNameController.php',
|
||||||
'PhabricatorSearchQuery' => 'applications/search/storage/PhabricatorSearchQuery.php',
|
'PhabricatorSearchQuery' => 'applications/search/storage/PhabricatorSearchQuery.php',
|
||||||
'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php',
|
'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php',
|
||||||
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
|
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
|
||||||
|
@ -2828,6 +2831,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorMustVerifyEmailController' => 'PhabricatorAuthController',
|
'PhabricatorMustVerifyEmailController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorMySQLConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorMySQLConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
||||||
|
'PhabricatorNamedQuery' => 'PhabricatorSearchDAO',
|
||||||
'PhabricatorNoteExample' => 'PhabricatorUIExample',
|
'PhabricatorNoteExample' => 'PhabricatorUIExample',
|
||||||
'PhabricatorNotificationClearController' => 'PhabricatorNotificationController',
|
'PhabricatorNotificationClearController' => 'PhabricatorNotificationController',
|
||||||
'PhabricatorNotificationConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorNotificationConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
|
@ -2908,6 +2912,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorPasteEditController' => 'PhabricatorPasteController',
|
'PhabricatorPasteEditController' => 'PhabricatorPasteController',
|
||||||
'PhabricatorPasteListController' => 'PhabricatorPasteController',
|
'PhabricatorPasteListController' => 'PhabricatorPasteController',
|
||||||
|
'PhabricatorPasteQueriesController' => 'PhabricatorPasteController',
|
||||||
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhabricatorPasteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
'PhabricatorPasteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
|
||||||
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
|
@ -3038,6 +3043,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSearchHovercardController' => 'PhabricatorSearchBaseController',
|
'PhabricatorSearchHovercardController' => 'PhabricatorSearchBaseController',
|
||||||
'PhabricatorSearchManagementIndexWorkflow' => 'PhabricatorSearchManagementWorkflow',
|
'PhabricatorSearchManagementIndexWorkflow' => 'PhabricatorSearchManagementWorkflow',
|
||||||
'PhabricatorSearchManagementWorkflow' => 'PhutilArgumentWorkflow',
|
'PhabricatorSearchManagementWorkflow' => 'PhutilArgumentWorkflow',
|
||||||
|
'PhabricatorSearchNameController' => 'PhabricatorSearchBaseController',
|
||||||
'PhabricatorSearchQuery' => 'PhabricatorSearchDAO',
|
'PhabricatorSearchQuery' => 'PhabricatorSearchDAO',
|
||||||
'PhabricatorSearchResultView' => 'AphrontView',
|
'PhabricatorSearchResultView' => 'AphrontView',
|
||||||
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
|
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
|
||||||
|
@ -3452,6 +3458,7 @@ phutil_register_library_map(array(
|
||||||
'ReleephBranchEditor' => 'PhabricatorEditor',
|
'ReleephBranchEditor' => 'PhabricatorEditor',
|
||||||
'ReleephBranchNamePreviewController' => 'PhabricatorController',
|
'ReleephBranchNamePreviewController' => 'PhabricatorController',
|
||||||
'ReleephBranchPreviewView' => 'AphrontFormControl',
|
'ReleephBranchPreviewView' => 'AphrontFormControl',
|
||||||
|
'ReleephBranchTemplate' => 'PhabricatorMarkupInterface',
|
||||||
'ReleephBranchViewController' => 'ReleephController',
|
'ReleephBranchViewController' => 'ReleephController',
|
||||||
'ReleephCommitFinderException' => 'Exception',
|
'ReleephCommitFinderException' => 'Exception',
|
||||||
'ReleephCommitMessageFieldSpecification' => 'ReleephFieldSpecification',
|
'ReleephCommitMessageFieldSpecification' => 'ReleephFieldSpecification',
|
||||||
|
|
|
@ -37,6 +37,7 @@ final class PhabricatorApplicationPaste extends PhabricatorApplication {
|
||||||
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
||||||
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
|
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
|
||||||
'query/(?P<queryKey>\w+)/'=> 'PhabricatorPasteListController',
|
'query/(?P<queryKey>\w+)/'=> 'PhabricatorPasteListController',
|
||||||
|
'savedqueries/' => 'PhabricatorPasteQueriesController',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,11 @@ abstract class PhabricatorPasteController extends PhabricatorController {
|
||||||
if ($user->isLoggedIn()) {
|
if ($user->isLoggedIn()) {
|
||||||
$nav->addFilter('my', pht('My Pastes'));
|
$nav->addFilter('my', pht('My Pastes'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$nav->addLabel(pht('Search'));
|
||||||
$nav->addFilter('advanced', pht('Advanced Search'));
|
$nav->addFilter('advanced', pht('Advanced Search'));
|
||||||
|
$nav->addFilter('', pht('Saved Queries'),
|
||||||
|
$this->getApplicationURI('/savedqueries/'));
|
||||||
|
|
||||||
$nav->selectFilter($filter, 'all');
|
$nav->selectFilter($filter, 'all');
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorPasteQueriesController
|
||||||
|
extends PhabricatorPasteController {
|
||||||
|
|
||||||
|
public function processRequest() {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$user = $request->getUser();
|
||||||
|
|
||||||
|
$nav = $this->buildSideNavView("");
|
||||||
|
$filter = $nav->getSelectedFilter();
|
||||||
|
|
||||||
|
$table = new PhabricatorNamedQuery();
|
||||||
|
$conn = $table->establishConnection('r');
|
||||||
|
$data = queryfx_all(
|
||||||
|
$conn,
|
||||||
|
'SELECT * FROM %T WHERE userPHID=%s AND engineClassName=%s',
|
||||||
|
$table->getTableName(),
|
||||||
|
$user->getPHID(),
|
||||||
|
'PhabricatorPasteSearchEngine');
|
||||||
|
|
||||||
|
$list = new PhabricatorObjectItemListView();
|
||||||
|
$list->setUser($user);
|
||||||
|
|
||||||
|
foreach ($data as $key => $saved_query) {
|
||||||
|
$date_created = phabricator_datetime($saved_query["dateCreated"], $user);
|
||||||
|
$item = id(new PhabricatorObjectItemView())
|
||||||
|
->setHeader($saved_query["queryName"])
|
||||||
|
->setHref('/paste/query/'.$saved_query["queryKey"].'/')
|
||||||
|
->addByline(pht('Date Created: ').$date_created);
|
||||||
|
$list->addItem($item);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pager = new AphrontCursorPagerView();
|
||||||
|
$pager->readFromRequest($request);
|
||||||
|
|
||||||
|
$list->setPager($pager);
|
||||||
|
|
||||||
|
$list->setNoDataString(pht("No results found for this query."));
|
||||||
|
|
||||||
|
$nav->appendChild(
|
||||||
|
array(
|
||||||
|
$list,
|
||||||
|
));
|
||||||
|
|
||||||
|
$crumbs = $this
|
||||||
|
->buildApplicationCrumbs($nav)
|
||||||
|
->addCrumb(
|
||||||
|
id(new PhabricatorCrumbView())
|
||||||
|
->setName(pht("Saved Queries"))
|
||||||
|
->setHref($this->getApplicationURI('/savedqueries/')));
|
||||||
|
|
||||||
|
$nav->setCrumbs($crumbs);
|
||||||
|
|
||||||
|
return $this->buildApplicationPage(
|
||||||
|
$nav,
|
||||||
|
array(
|
||||||
|
'title' => pht("Saved Queries"),
|
||||||
|
'device' => true,
|
||||||
|
'dust' => true,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -83,7 +83,10 @@ final class PhabricatorPasteSearchEngine
|
||||||
|
|
||||||
$form->appendChild(
|
$form->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue(pht('Filter Pastes')));
|
->setValue(pht('Filter Pastes'))
|
||||||
|
->addCancelButton(
|
||||||
|
'/search/name/'.$saved_query->getQueryKey().'/',
|
||||||
|
pht('Save Custom Query...')));
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,8 @@ final class PhabricatorApplicationSearch extends PhabricatorApplication {
|
||||||
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
|
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
|
||||||
'hovercard/(?P<mode>retrieve|test)/' =>
|
'hovercard/(?P<mode>retrieve|test)/' =>
|
||||||
'PhabricatorSearchHovercardController',
|
'PhabricatorSearchHovercardController',
|
||||||
),
|
'name/(?P<queryKey>\w+)/' => 'PhabricatorSearchNameController',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group search
|
||||||
|
*/
|
||||||
|
final class PhabricatorSearchNameController
|
||||||
|
extends PhabricatorSearchBaseController {
|
||||||
|
|
||||||
|
private $queryKey;
|
||||||
|
|
||||||
|
public function willProcessRequest(array $data) {
|
||||||
|
$this->queryKey = idx($data, 'queryKey');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processRequest() {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$user = $request->getUser();
|
||||||
|
|
||||||
|
if ($this->queryKey) {
|
||||||
|
$saved_query = id(new PhabricatorSavedQuery())->loadOneWhere(
|
||||||
|
'queryKey = %s',
|
||||||
|
$this->queryKey);
|
||||||
|
if (!$saved_query) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->isFormPost()) {
|
||||||
|
$request_data = $request->getRequestData();
|
||||||
|
|
||||||
|
$named_query = id(new PhabricatorNamedQuery())
|
||||||
|
->setUserPHID($user->getPHID())
|
||||||
|
->setQueryKey($saved_query->getQueryKey())
|
||||||
|
->setQueryName($request_data["set_name"])
|
||||||
|
->setEngineClassName($saved_query->getEngineClassName());
|
||||||
|
|
||||||
|
try {
|
||||||
|
$named_query->save();
|
||||||
|
} catch (AphrontQueryDuplicateKeyException $ex) {
|
||||||
|
// Ignore, the user is naming an identical query.
|
||||||
|
}
|
||||||
|
|
||||||
|
return id(new AphrontRedirectResponse())
|
||||||
|
->setURI('/search/');
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = id(new AphrontFormView())
|
||||||
|
->setUser($user);
|
||||||
|
|
||||||
|
$form->appendChild(
|
||||||
|
id(new AphrontFormTextControl())
|
||||||
|
->setName('set_name')
|
||||||
|
->setLabel(pht('Query Name')));
|
||||||
|
|
||||||
|
$form->appendChild(
|
||||||
|
id(new AphrontFormSubmitControl())
|
||||||
|
->setValue(pht('Save')));
|
||||||
|
|
||||||
|
return $this->buildStandardPageResponse(
|
||||||
|
array(
|
||||||
|
$form,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'title' => 'Name Query',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
13
src/applications/search/storage/PhabricatorNamedQuery.php
Normal file
13
src/applications/search/storage/PhabricatorNamedQuery.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group search
|
||||||
|
*/
|
||||||
|
final class PhabricatorNamedQuery extends PhabricatorSearchDAO {
|
||||||
|
|
||||||
|
protected $queryKey = "";
|
||||||
|
protected $queryName = "";
|
||||||
|
protected $userPHID = "";
|
||||||
|
protected $engineClassName = "";
|
||||||
|
|
||||||
|
}
|
|
@ -1282,6 +1282,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'php',
|
'type' => 'php',
|
||||||
'name' => $this->getPatchPath('20130507.releephrqmailkeypop.php'),
|
'name' => $this->getPatchPath('20130507.releephrqmailkeypop.php'),
|
||||||
),
|
),
|
||||||
|
'20130508.search_namedquery.sql' => array(
|
||||||
|
'type' => 'sql',
|
||||||
|
'name' => $this->getPatchPath('20130508.search_namedquery.sql'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue