Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/feed/query/PhabricatorFeedQuery.php b/src/applications/feed/query/PhabricatorFeedQuery.php
index 7335a6d5b1..f8f67f7a3e 100644
--- a/src/applications/feed/query/PhabricatorFeedQuery.php
+++ b/src/applications/feed/query/PhabricatorFeedQuery.php
@@ -1,125 +1,139 @@
<?php
final class PhabricatorFeedQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $filterPHIDs;
private $chronologicalKeys;
public function withFilterPHIDs(array $phids) {
$this->filterPHIDs = $phids;
return $this;
}
public function withChronologicalKeys(array $keys) {
$this->chronologicalKeys = $keys;
return $this;
}
public function newResultObject() {
return new PhabricatorFeedStoryData();
}
protected function loadPage() {
// NOTE: We return raw rows from this method, which is a little unusual.
return $this->loadStandardPageRows($this->newResultObject());
}
protected function willFilterPage(array $data) {
return PhabricatorFeedStory::loadAllFromRows($data, $this->getViewer());
}
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = parent::buildJoinClauseParts($conn);
// NOTE: We perform this join unconditionally (even if we have no filter
// PHIDs) to omit rows which have no story references. These story data
// rows are notifications or realtime alerts.
$ref_table = new PhabricatorFeedStoryReference();
$joins[] = qsprintf(
$conn,
'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey',
$ref_table->getTableName());
return $joins;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->filterPHIDs !== null) {
$where[] = qsprintf(
$conn,
'ref.objectPHID IN (%Ls)',
$this->filterPHIDs);
}
if ($this->chronologicalKeys !== null) {
// NOTE: We want to use integers in the query so we can take advantage
// of keys, but can't use %d on 32-bit systems. Make sure all the keys
// are integers and then format them raw.
$keys = $this->chronologicalKeys;
foreach ($keys as $key) {
if (!ctype_digit($key)) {
throw new Exception(
pht("Key '%s' is not a valid chronological key!", $key));
}
}
$where[] = qsprintf(
$conn,
'ref.chronologicalKey IN (%Q)',
implode(', ', $keys));
}
return $where;
}
protected function buildGroupClause(AphrontDatabaseConnection $conn) {
if ($this->filterPHIDs !== null) {
return qsprintf($conn, 'GROUP BY ref.chronologicalKey');
} else {
return qsprintf($conn, 'GROUP BY story.chronologicalKey');
}
}
protected function getDefaultOrderVector() {
return array('key');
}
+ public function getBuiltinOrders() {
+ return array(
+ 'newest' => array(
+ 'vector' => array('key'),
+ 'name' => pht('Creation (Newest First)'),
+ 'aliases' => array('created'),
+ ),
+ 'oldest' => array(
+ 'vector' => array('-key'),
+ 'name' => pht('Creation (Oldest First)'),
+ ),
+ );
+ }
+
public function getOrderableColumns() {
$table = ($this->filterPHIDs ? 'ref' : 'story');
return array(
'key' => array(
'table' => $table,
'column' => 'chronologicalKey',
'type' => 'string',
'unique' => true,
),
);
}
protected function getPagingValueMap($cursor, array $keys) {
return array(
'key' => $cursor,
);
}
protected function getResultCursor($item) {
if ($item instanceof PhabricatorFeedStory) {
return $item->getChronologicalKey();
}
return $item['chronologicalKey'];
}
protected function getPrimaryTableAlias() {
return 'story';
}
public function getQueryApplicationClass() {
return 'PhabricatorFeedApplication';
}
}
diff --git a/src/applications/feed/query/PhabricatorFeedSearchEngine.php b/src/applications/feed/query/PhabricatorFeedSearchEngine.php
index 43a0b716ca..6dae9f9c37 100644
--- a/src/applications/feed/query/PhabricatorFeedSearchEngine.php
+++ b/src/applications/feed/query/PhabricatorFeedSearchEngine.php
@@ -1,150 +1,132 @@
<?php
final class PhabricatorFeedSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Feed Stories');
}
public function getApplicationClassName() {
return 'PhabricatorFeedApplication';
}
- public function buildSavedQueryFromRequest(AphrontRequest $request) {
- $saved = new PhabricatorSavedQuery();
-
- $saved->setParameter(
- 'userPHIDs',
- $this->readUsersFromRequest($request, 'users'));
-
- $saved->setParameter(
- 'projectPHIDs',
- array_values($request->getArr('projectPHIDs')));
+ public function newQuery() {
+ return new PhabricatorFeedQuery();
+ }
- $saved->setParameter(
- 'viewerProjects',
- $request->getBool('viewerProjects'));
+ protected function shouldShowOrderField() {
+ return false;
+ }
- return $saved;
+ protected function buildCustomSearchFields() {
+ return array(
+ id(new PhabricatorUsersSearchField())
+ ->setLabel(pht('Include Users'))
+ ->setKey('userPHIDs'),
+ // NOTE: This query is not executed with EdgeLogic, so we can't use
+ // a fancy logical datasource.
+ id(new PhabricatorSearchDatasourceField())
+ ->setDatasource(new PhabricatorProjectDatasource())
+ ->setLabel(pht('Include Projects'))
+ ->setKey('projectPHIDs'),
+
+ // NOTE: This is a legacy field retained only for backward
+ // compatibility. If the projects field used EdgeLogic, we could use
+ // `viewerprojects()` to execute an equivalent query.
+ id(new PhabricatorSearchCheckboxesField())
+ ->setKey('viewerProjects')
+ ->setOptions(
+ array(
+ 'self' => pht('Include stories about projects I am a member of.'),
+ )),
+ );
}
- public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
- $query = id(new PhabricatorFeedQuery());
+ protected function buildQueryFromParameters(array $map) {
+ $query = $this->newQuery();
$phids = array();
-
- $user_phids = $saved->getParameter('userPHIDs');
- if ($user_phids) {
- $phids[] = $user_phids;
+ if ($map['userPHIDs']) {
+ $phids += array_fuse($map['userPHIDs']);
}
- $proj_phids = $saved->getParameter('projectPHIDs');
- if ($proj_phids) {
- $phids[] = $proj_phids;
+ if ($map['projectPHIDs']) {
+ $phids += array_fuse($map['projectPHIDs']);
}
- $viewer_projects = $saved->getParameter('viewerProjects');
+ // NOTE: This value may be `true` for older saved queries, or
+ // `array('self')` for newer ones.
+ $viewer_projects = $map['viewerProjects'];
if ($viewer_projects) {
$viewer = $this->requireViewer();
$projects = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withMemberPHIDs(array($viewer->getPHID()))
->execute();
- $phids[] = mpull($projects, 'getPHID');
+ $phids += array_fuse(mpull($projects, 'getPHID'));
}
- $phids = array_mergev($phids);
if ($phids) {
$query->withFilterPHIDs($phids);
}
return $query;
}
- public function buildSearchForm(
- AphrontFormView $form,
- PhabricatorSavedQuery $saved_query) {
-
- $user_phids = $saved_query->getParameter('userPHIDs', array());
- $proj_phids = $saved_query->getParameter('projectPHIDs', array());
- $viewer_projects = $saved_query->getParameter('viewerProjects');
-
- $form
- ->appendControl(
- id(new AphrontFormTokenizerControl())
- ->setDatasource(new PhabricatorPeopleDatasource())
- ->setName('users')
- ->setLabel(pht('Include Users'))
- ->setValue($user_phids))
- ->appendControl(
- id(new AphrontFormTokenizerControl())
- ->setDatasource(new PhabricatorProjectDatasource())
- ->setName('projectPHIDs')
- ->setLabel(pht('Include Projects'))
- ->setValue($proj_phids))
- ->appendChild(
- id(new AphrontFormCheckboxControl())
- ->addCheckbox(
- 'viewerProjects',
- 1,
- pht('Include stories about projects I am a member of.'),
- $viewer_projects));
- }
-
protected function getURI($path) {
return '/feed/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Stories'),
);
if ($this->requireViewer()->isLoggedIn()) {
$names['projects'] = pht('Tags');
}
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'projects':
- return $query->setParameter('viewerProjects', true);
+ return $query->setParameter('viewerProjects', array('self'));
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $objects,
PhabricatorSavedQuery $query,
array $handles) {
$builder = new PhabricatorFeedBuilder($objects);
if ($this->isPanelContext()) {
$builder->setShowHovercards(false);
} else {
$builder->setShowHovercards(true);
}
$builder->setUser($this->requireViewer());
$view = $builder->buildView();
$list = phutil_tag_div('phabricator-feed-frame', $view);
$result = new PhabricatorApplicationSearchResultView();
$result->setContent($list);
return $result;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jul 29, 8:42 AM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
188387
Default Alt Text
(9 KB)

Event Timeline