forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorSearchController.php
122 lines (97 loc) · 3.69 KB
/
PhabricatorSearchController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
final class PhabricatorSearchController
extends PhabricatorSearchBaseController {
const SCOPE_CURRENT_APPLICATION = 'application';
private $queryKey;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
if ($request->getStr('jump') != 'no') {
$pref_jump = PhabricatorUserPreferences::PREFERENCE_SEARCHBAR_JUMP;
if ($viewer->loadPreferences($pref_jump, 1)) {
$response = PhabricatorJumpNavHandler::getJumpResponse(
$viewer,
$request->getStr('query'));
if ($response) {
return $response;
}
}
}
$engine = new PhabricatorSearchApplicationSearchEngine();
$engine->setViewer($viewer);
// If we're coming from primary search, do some special handling to
// interpret the scope selector and query.
if ($request->getBool('search:primary')) {
// If there's no query, just take the user to advanced search.
if (!strlen($request->getStr('query'))) {
$advanced_uri = '/search/query/advanced/';
return id(new AphrontRedirectResponse())->setURI($advanced_uri);
}
// First, load or construct a template for the search by examining
// the current search scope.
$scope = $request->getStr('search:scope');
$saved = null;
if ($scope == self::SCOPE_CURRENT_APPLICATION) {
$application = id(new PhabricatorApplicationQuery())
->setViewer($viewer)
->withClasses(array($request->getStr('search:application')))
->executeOne();
if ($application) {
$types = $application->getApplicationSearchDocumentTypes();
if ($types) {
$saved = id(new PhabricatorSavedQuery())
->setEngineClassName(get_class($engine))
->setParameter('types', $types)
->setParameter('statuses', array('open'));
}
}
}
if (!$saved && !$engine->isBuiltinQuery($scope)) {
$saved = id(new PhabricatorSavedQueryQuery())
->setViewer($viewer)
->withQueryKeys(array($scope))
->executeOne();
}
if (!$saved) {
if (!$engine->isBuiltinQuery($scope)) {
$scope = 'all';
}
$saved = $engine->buildSavedQueryFromBuiltin($scope);
}
// Add the user's query, then save this as a new saved query and send
// the user to the results page.
$saved->setParameter('query', $request->getStr('query'));
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
try {
$saved->setID(null)->save();
} catch (AphrontDuplicateKeyQueryException $ex) {
// Ignore, this is just a repeated search.
}
unset($unguarded);
$query_key = $saved->getQueryKey();
$results_uri = $engine->getQueryResultsPageURI($query_key).'#R';
return id(new AphrontRedirectResponse())->setURI($results_uri);
}
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($this->queryKey)
->setSearchEngine($engine)
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
public function buildSideNavView($for_app = false) {
$viewer = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
id(new PhabricatorSearchApplicationSearchEngine())
->setViewer($viewer)
->addNavigationItems($nav->getMenu());
$nav->selectFilter(null);
return $nav;
}
}