Skip to content

Commit fb765b8

Browse files
author
epriestley
committed
Add language and date ranges to Paste queries
Summary: Ref T2625. Ref T3273. This is mostly a UI foil for T3273. Right now, to find tasks without owners or without projects you search for the magic strings "upforgrabs" and "noproject". Unsurprisingly, no users have ever figured this out. I want to get rid of it. Instead, these interfaces will look like: Assigned: [ Type a user name... ] [ X ] Find unassigned tasks. Projects: [ Type a project name... ] [ X ] Find tasks with no projects. Seems reasonable, I think? Test Plan: Searched for "rainbow, js", "rainbow + no language", "no language", date ranges, etc. Reviewers: chad, btrahan Reviewed By: chad CC: aran Maniphest Tasks: T2625, T3273 Differential Revision: https://secure.phabricator.com/D6085
1 parent 2427d31 commit fb765b8

File tree

4 files changed

+116
-33
lines changed

4 files changed

+116
-33
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTER TABLE {$NAMESPACE}_pastebin.pastebin_paste
2+
ADD KEY `key_dateCreated` (dateCreated);
3+
4+
ALTER TABLE {$NAMESPACE}_pastebin.pastebin_paste
5+
ADD KEY `key_language` (language);

src/applications/paste/query/PhabricatorPasteQuery.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ final class PhabricatorPasteQuery
1010

1111
private $needContent;
1212
private $needRawContent;
13+
private $languages;
14+
private $includeNoLanguage;
15+
private $dateCreatedAfter;
16+
private $dateCreatedBefore;
1317

1418
public function withIDs(array $ids) {
1519
$this->ids = $ids;
@@ -41,6 +45,28 @@ public function needRawContent($need_raw_content) {
4145
return $this;
4246
}
4347

48+
public function withLanguages(array $languages) {
49+
$this->includeNoLanguage = false;
50+
foreach ($languages as $key => $language) {
51+
if ($language === null) {
52+
$languages[$key] = '';
53+
continue;
54+
}
55+
}
56+
$this->languages = $languages;
57+
return $this;
58+
}
59+
60+
public function withDateCreatedBefore($date_created_before) {
61+
$this->dateCreatedBefore = $date_created_before;
62+
return $this;
63+
}
64+
65+
public function withDateCreatedAfter($date_created_after) {
66+
$this->dateCreatedAfter = $date_created_after;
67+
return $this;
68+
}
69+
4470
protected function loadPage() {
4571
$table = new PhabricatorPaste();
4672
$conn_r = $table->establishConnection('r');
@@ -107,6 +133,27 @@ protected function buildWhereClause($conn_r) {
107133
$this->parentPHIDs);
108134
}
109135

136+
if ($this->languages) {
137+
$where[] = qsprintf(
138+
$conn_r,
139+
'language IN (%Ls)',
140+
$this->languages);
141+
}
142+
143+
if ($this->dateCreatedAfter) {
144+
$where[] = qsprintf(
145+
$conn_r,
146+
'dateCreated >= %d',
147+
$this->dateCreatedAfter);
148+
}
149+
150+
if ($this->dateCreatedBefore) {
151+
$where[] = qsprintf(
152+
$conn_r,
153+
'dateCreated <= %d',
154+
$this->dateCreatedBefore);
155+
}
156+
110157
return $this->formatWhereClause($where);
111158
}
112159

src/applications/paste/query/PhabricatorPasteSearchEngine.php

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
<?php
22

3-
/**
4-
* Provides search functionality for the paste application.
5-
*
6-
* @group search
7-
*/
83
final class PhabricatorPasteSearchEngine
94
extends PhabricatorApplicationSearchEngine {
105

11-
/**
12-
* Create a saved query object from the request.
13-
*
14-
* @param AphrontRequest The search request.
15-
* @return The saved query that is built.
16-
*/
176
public function buildSavedQueryFromRequest(AphrontRequest $request) {
187
$saved = new PhabricatorSavedQuery();
198
$saved->setParameter(
209
'authorPHIDs',
2110
array_values($request->getArr('authors')));
2211

12+
$languages = $request->getStrList('languages');
13+
if ($request->getBool('noLanguage')) {
14+
$languages[] = null;
15+
}
16+
$saved->setParameter('languages', $languages);
17+
18+
$saved->setParameter('createdStart', $request->getStr('createdStart'));
19+
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
20+
2321
return $saved;
2422
}
2523

26-
/**
27-
* Executes the saved query.
28-
*
29-
* @param PhabricatorSavedQuery
30-
* @return The result of the query.
31-
*/
3224
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
3325
$query = id(new PhabricatorPasteQuery())
3426
->needContent(true)
35-
->withIDs($saved->getParameter('ids', array()))
36-
->withPHIDs($saved->getParameter('phids', array()))
3727
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
38-
->withParentPHIDs($saved->getParameter('parentPHIDs', array()));
28+
->withLanguages($saved->getParameter('languages', array()));
29+
30+
$start = $this->parseDateTime($saved->getParameter('createdStart'));
31+
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
32+
33+
if ($start) {
34+
$query->withDateCreatedAfter($start);
35+
}
36+
37+
if ($end) {
38+
$query->withDateCreatedBefore($end);
39+
}
3940

4041
return $query;
4142
}
4243

43-
/**
44-
* Builds the search form using the request.
45-
*
46-
* @param PhabricatorSavedQuery The query to populate the form with.
47-
* @return AphrontFormView The built form.
48-
*/
4944
public function buildSearchForm(
5045
AphrontFormView $form,
5146
PhabricatorSavedQuery $saved_query) {
@@ -55,12 +50,44 @@ public function buildSearchForm(
5550
->loadHandles();
5651
$author_tokens = mpull($handles, 'getFullName', 'getPHID');
5752

58-
$form->appendChild(
59-
id(new AphrontFormTokenizerControl())
60-
->setDatasource('/typeahead/common/users/')
61-
->setName('authors')
62-
->setLabel(pht('Authors'))
63-
->setValue($author_tokens));
53+
$languages = $saved_query->getParameter('languages', array());
54+
$no_language = false;
55+
foreach ($languages as $key => $language) {
56+
if ($language === null) {
57+
$no_language = true;
58+
unset($languages[$key]);
59+
continue;
60+
}
61+
}
62+
63+
$form
64+
->appendChild(
65+
id(new AphrontFormTokenizerControl())
66+
->setDatasource('/typeahead/common/users/')
67+
->setName('authors')
68+
->setLabel(pht('Authors'))
69+
->setValue($author_tokens))
70+
->appendChild(
71+
id(new AphrontFormTextControl())
72+
->setName('languages')
73+
->setLabel(pht('Languages'))
74+
->setValue(implode(', ', $languages)))
75+
->appendChild(
76+
id(new AphrontFormCheckboxControl())
77+
->addCheckbox(
78+
'noLanguage',
79+
1,
80+
pht('Find Pastes with no specified language.'),
81+
$no_language));
82+
83+
$this->buildDateRange(
84+
$form,
85+
$saved_query,
86+
'createdStart',
87+
pht('Created After'),
88+
'createdEnd',
89+
pht('Created Before'));
90+
6491
}
6592

6693
protected function getURI($path) {
@@ -69,7 +96,7 @@ protected function getURI($path) {
6996

7097
public function getBuiltinQueryNames() {
7198
$names = array(
72-
'all' => pht('All Pastes'),
99+
'all' => pht('All Pastes'),
73100
);
74101

75102
if ($this->requireViewer()->isLoggedIn()) {

src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,10 @@ public function getPatches() {
13341334
'type' => 'sql',
13351335
'name' => $this->getPatchPath('20130530.macrodatekey.sql'),
13361336
),
1337+
'20130530.pastekeys.sql' => array(
1338+
'type' => 'sql',
1339+
'name' => $this->getPatchPath('20130530.pastekeys.sql'),
1340+
),
13371341
);
13381342
}
13391343
}

0 commit comments

Comments
 (0)