2011-12-16 17:08:18 -08:00
|
|
|
<?php
|
|
|
|
|
|
2012-09-13 10:15:08 -07:00
|
|
|
final class PhabricatorProjectQuery
|
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2011-12-16 17:08:18 -08:00
|
|
|
|
2012-01-17 16:29:35 -08:00
|
|
|
private $ids;
|
|
|
|
|
private $phids;
|
2012-08-07 11:54:24 -07:00
|
|
|
private $memberPHIDs;
|
2016-02-17 11:37:01 -08:00
|
|
|
private $watcherPHIDs;
|
2013-03-08 07:12:24 -08:00
|
|
|
private $slugs;
|
2015-12-27 02:28:36 -08:00
|
|
|
private $slugNormals;
|
|
|
|
|
private $slugMap;
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
private $allSlugs;
|
2013-10-25 10:16:39 -07:00
|
|
|
private $names;
|
Separate sever-side typeahead queries into "prefix" and "content" phases
Summary:
Ref T8510. When users type "platypus" into a typeahead, they want "Platypus Playground" to be a higher-ranked match than "AAA Platypus", even though the latter is alphabetically first.
Specifically, the rule is: results which match the query as a prefix of the result text should rank above results which do not.
I believe we now always get this right on the client side. However, WMF has at least one case (described in T8510) where we do not get it right on the server side, and thus the user sees the wrong result.
The remaining issue is that if "platypus" matches more than 100 results, the result "Platypus Playground" may not appear in the result set at all, beacuse there are 100 copies of "AAA Platypus 1", "AAA Platypus 2", etc., first. So even though the client will apply the correct sort, it doesn't have the result the user wants and can't show it to them.
To fix this, split the server-side query into two phases:
- In the first phase, the "prefix" phase, we find results that **start with** "platypus".
- In the second phase, the "content" phase, we find results that contain "platypus" anywhere.
We skip the "prefix" phase if the user has not typed a query (for example, in the browse view).
Test Plan:
This is a lot of stuff, but the new ranking here puts projects which start with "w" at the top of the list. Lower down the list, you can see some projects which contain "w" but do not appear at the top (like "Serious Work").
{F1913931}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T8510
Differential Revision: https://secure.phabricator.com/D16838
2016-11-10 07:24:15 -08:00
|
|
|
private $namePrefixes;
|
2015-04-15 11:49:07 -07:00
|
|
|
private $nameTokens;
|
2014-08-12 08:04:38 -07:00
|
|
|
private $icons;
|
|
|
|
|
private $colors;
|
2015-12-23 07:01:27 -08:00
|
|
|
private $ancestorPHIDs;
|
|
|
|
|
private $parentPHIDs;
|
|
|
|
|
private $isMilestone;
|
2015-12-23 03:12:20 -08:00
|
|
|
private $hasSubprojects;
|
2015-12-23 07:01:27 -08:00
|
|
|
private $minDepth;
|
|
|
|
|
private $maxDepth;
|
2016-02-12 10:57:13 -08:00
|
|
|
private $minMilestoneNumber;
|
|
|
|
|
private $maxMilestoneNumber;
|
2019-01-26 07:29:03 -08:00
|
|
|
private $subtypes;
|
2011-12-16 17:08:18 -08:00
|
|
|
|
2012-02-07 14:59:38 -08:00
|
|
|
private $status = 'status-any';
|
|
|
|
|
const STATUS_ANY = 'status-any';
|
|
|
|
|
const STATUS_OPEN = 'status-open';
|
|
|
|
|
const STATUS_CLOSED = 'status-closed';
|
|
|
|
|
const STATUS_ACTIVE = 'status-active';
|
|
|
|
|
const STATUS_ARCHIVED = 'status-archived';
|
2016-02-06 12:40:31 -08:00
|
|
|
private $statuses;
|
2012-02-07 14:59:38 -08:00
|
|
|
|
2014-05-22 11:19:03 -07:00
|
|
|
private $needSlugs;
|
2012-01-17 16:29:35 -08:00
|
|
|
private $needMembers;
|
2016-01-19 09:36:40 -08:00
|
|
|
private $needAncestorMembers;
|
2014-05-19 12:40:57 -07:00
|
|
|
private $needWatchers;
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
private $needImages;
|
2012-01-17 16:29:35 -08:00
|
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
|
$this->ids = $ids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
|
$this->phids = $phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 14:59:38 -08:00
|
|
|
public function withStatus($status) {
|
|
|
|
|
$this->status = $status;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-06 12:40:31 -08:00
|
|
|
public function withStatuses(array $statuses) {
|
|
|
|
|
$this->statuses = $statuses;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-07 11:54:24 -07:00
|
|
|
public function withMemberPHIDs(array $member_phids) {
|
|
|
|
|
$this->memberPHIDs = $member_phids;
|
2011-12-16 17:08:18 -08:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 11:37:01 -08:00
|
|
|
public function withWatcherPHIDs(array $watcher_phids) {
|
|
|
|
|
$this->watcherPHIDs = $watcher_phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 11:19:03 -07:00
|
|
|
public function withSlugs(array $slugs) {
|
2013-03-08 07:12:24 -08:00
|
|
|
$this->slugs = $slugs;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 10:16:39 -07:00
|
|
|
public function withNames(array $names) {
|
|
|
|
|
$this->names = $names;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
Separate sever-side typeahead queries into "prefix" and "content" phases
Summary:
Ref T8510. When users type "platypus" into a typeahead, they want "Platypus Playground" to be a higher-ranked match than "AAA Platypus", even though the latter is alphabetically first.
Specifically, the rule is: results which match the query as a prefix of the result text should rank above results which do not.
I believe we now always get this right on the client side. However, WMF has at least one case (described in T8510) where we do not get it right on the server side, and thus the user sees the wrong result.
The remaining issue is that if "platypus" matches more than 100 results, the result "Platypus Playground" may not appear in the result set at all, beacuse there are 100 copies of "AAA Platypus 1", "AAA Platypus 2", etc., first. So even though the client will apply the correct sort, it doesn't have the result the user wants and can't show it to them.
To fix this, split the server-side query into two phases:
- In the first phase, the "prefix" phase, we find results that **start with** "platypus".
- In the second phase, the "content" phase, we find results that contain "platypus" anywhere.
We skip the "prefix" phase if the user has not typed a query (for example, in the browse view).
Test Plan:
This is a lot of stuff, but the new ranking here puts projects which start with "w" at the top of the list. Lower down the list, you can see some projects which contain "w" but do not appear at the top (like "Serious Work").
{F1913931}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T8510
Differential Revision: https://secure.phabricator.com/D16838
2016-11-10 07:24:15 -08:00
|
|
|
public function withNamePrefixes(array $prefixes) {
|
|
|
|
|
$this->namePrefixes = $prefixes;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 11:49:07 -07:00
|
|
|
public function withNameTokens(array $tokens) {
|
|
|
|
|
$this->nameTokens = array_values($tokens);
|
2014-07-17 16:35:54 -07:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
public function withIcons(array $icons) {
|
|
|
|
|
$this->icons = $icons;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withColors(array $colors) {
|
|
|
|
|
$this->colors = $colors;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 07:01:27 -08:00
|
|
|
public function withParentProjectPHIDs($parent_phids) {
|
|
|
|
|
$this->parentPHIDs = $parent_phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withAncestorProjectPHIDs($ancestor_phids) {
|
|
|
|
|
$this->ancestorPHIDs = $ancestor_phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withIsMilestone($is_milestone) {
|
|
|
|
|
$this->isMilestone = $is_milestone;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 03:12:20 -08:00
|
|
|
public function withHasSubprojects($has_subprojects) {
|
|
|
|
|
$this->hasSubprojects = $has_subprojects;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 07:01:27 -08:00
|
|
|
public function withDepthBetween($min, $max) {
|
|
|
|
|
$this->minDepth = $min;
|
|
|
|
|
$this->maxDepth = $max;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 10:57:13 -08:00
|
|
|
public function withMilestoneNumberBetween($min, $max) {
|
|
|
|
|
$this->minMilestoneNumber = $min;
|
|
|
|
|
$this->maxMilestoneNumber = $max;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-26 07:29:03 -08:00
|
|
|
public function withSubtypes(array $subtypes) {
|
|
|
|
|
$this->subtypes = $subtypes;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-17 16:29:35 -08:00
|
|
|
public function needMembers($need_members) {
|
|
|
|
|
$this->needMembers = $need_members;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
public function needAncestorMembers($need_ancestor_members) {
|
|
|
|
|
$this->needAncestorMembers = $need_ancestor_members;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 12:40:57 -07:00
|
|
|
public function needWatchers($need_watchers) {
|
|
|
|
|
$this->needWatchers = $need_watchers;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
public function needImages($need_images) {
|
|
|
|
|
$this->needImages = $need_images;
|
2013-10-06 17:07:20 -07:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-22 11:19:03 -07:00
|
|
|
public function needSlugs($need_slugs) {
|
|
|
|
|
$this->needSlugs = $need_slugs;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:21:48 -07:00
|
|
|
public function newResultObject() {
|
|
|
|
|
return new PhabricatorProject();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 19:07:28 -07:00
|
|
|
protected function getDefaultOrderVector() {
|
|
|
|
|
return array('name');
|
2012-08-08 17:10:10 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:21:48 -07:00
|
|
|
public function getBuiltinOrders() {
|
2015-04-11 19:07:28 -07:00
|
|
|
return array(
|
2015-06-08 12:21:48 -07:00
|
|
|
'name' => array(
|
|
|
|
|
'vector' => array('name'),
|
|
|
|
|
'name' => pht('Name'),
|
|
|
|
|
),
|
|
|
|
|
) + parent::getBuiltinOrders();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getOrderableColumns() {
|
|
|
|
|
return parent::getOrderableColumns() + array(
|
2015-04-11 19:07:28 -07:00
|
|
|
'name' => array(
|
|
|
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
|
|
|
'column' => 'name',
|
|
|
|
|
'reverse' => true,
|
|
|
|
|
'type' => 'string',
|
|
|
|
|
'unique' => true,
|
|
|
|
|
),
|
2016-02-13 08:27:29 -08:00
|
|
|
'milestoneNumber' => array(
|
|
|
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
|
|
|
'column' => 'milestoneNumber',
|
|
|
|
|
'type' => 'int',
|
|
|
|
|
),
|
2018-12-18 12:06:29 -08:00
|
|
|
'status' => array(
|
|
|
|
|
'table' => $this->getPrimaryTableAlias(),
|
|
|
|
|
'column' => 'status',
|
|
|
|
|
'type' => 'int',
|
|
|
|
|
),
|
2015-04-11 19:07:28 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-18 11:44:54 -07:00
|
|
|
protected function newPagingMapFromPartialObject($object) {
|
2015-04-11 19:07:28 -07:00
|
|
|
return array(
|
2019-03-18 11:44:54 -07:00
|
|
|
'id' => (int)$object->getID(),
|
|
|
|
|
'name' => $object->getName(),
|
|
|
|
|
'status' => $object->getStatus(),
|
2015-04-11 19:07:28 -07:00
|
|
|
);
|
2012-08-08 17:10:10 -07:00
|
|
|
}
|
|
|
|
|
|
2015-12-27 02:28:36 -08:00
|
|
|
public function getSlugMap() {
|
|
|
|
|
if ($this->slugMap === null) {
|
|
|
|
|
throw new PhutilInvalidStateException('execute');
|
|
|
|
|
}
|
|
|
|
|
return $this->slugMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function willExecute() {
|
|
|
|
|
$this->slugMap = array();
|
|
|
|
|
$this->slugNormals = array();
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
$this->allSlugs = array();
|
2015-12-27 02:28:36 -08:00
|
|
|
if ($this->slugs) {
|
|
|
|
|
foreach ($this->slugs as $slug) {
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
if (PhabricatorSlug::isValidProjectSlug($slug)) {
|
|
|
|
|
$normal = PhabricatorSlug::normalizeProjectSlug($slug);
|
|
|
|
|
$this->slugNormals[$slug] = $normal;
|
|
|
|
|
$this->allSlugs[$normal] = $normal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: At least for now, we query for the normalized slugs but also
|
|
|
|
|
// for the slugs exactly as entered. This allows older projects with
|
|
|
|
|
// slugs that are no longer valid to continue to work.
|
|
|
|
|
$this->allSlugs[$slug] = $slug;
|
2015-12-27 02:28:36 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-01 11:28:02 -08:00
|
|
|
protected function loadPage() {
|
2015-12-23 03:42:42 -08:00
|
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
|
|
|
}
|
2012-01-17 16:29:35 -08:00
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
protected function willFilterPage(array $projects) {
|
2015-12-23 03:42:51 -08:00
|
|
|
$ancestor_paths = array();
|
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
|
foreach ($project->getAncestorProjectPaths() as $path) {
|
|
|
|
|
$ancestor_paths[$path] = $path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($ancestor_paths) {
|
|
|
|
|
$ancestors = id(new PhabricatorProject())->loadAllWhere(
|
|
|
|
|
'projectPath IN (%Ls)',
|
|
|
|
|
$ancestor_paths);
|
|
|
|
|
} else {
|
|
|
|
|
$ancestors = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$projects = $this->linkProjectGraph($projects, $ancestors);
|
|
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
$viewer_phid = $this->getViewer()->getPHID();
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-27 04:27:58 -08:00
|
|
|
$material_type = PhabricatorProjectMaterializedMemberEdgeType::EDGECONST;
|
2015-12-23 03:42:42 -08:00
|
|
|
$watcher_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST;
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
$types = array();
|
2015-12-27 04:27:58 -08:00
|
|
|
$types[] = $material_type;
|
2015-12-23 03:42:42 -08:00
|
|
|
if ($this->needWatchers) {
|
|
|
|
|
$types[] = $watcher_type;
|
|
|
|
|
}
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
$all_graph = $this->getAllReachableAncestors($projects);
|
|
|
|
|
|
2020-02-03 08:40:57 -08:00
|
|
|
// See T13484. If the graph is damaged (and contains a cycle or an edge
|
|
|
|
|
// pointing at a project which has been destroyed), some of the nodes we
|
|
|
|
|
// started with may be filtered out by reachability tests. If any of the
|
|
|
|
|
// projects we are linking up don't have available ancestors, filter them
|
|
|
|
|
// out.
|
|
|
|
|
|
|
|
|
|
foreach ($projects as $key => $project) {
|
|
|
|
|
$project_phid = $project->getPHID();
|
|
|
|
|
if (!isset($all_graph[$project_phid])) {
|
|
|
|
|
$this->didRejectResult($project);
|
|
|
|
|
unset($projects[$key]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$projects) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-11 12:35:22 -08:00
|
|
|
// NOTE: Although we may not need much information about ancestors, we
|
|
|
|
|
// always need to test if the viewer is a member, because we will return
|
|
|
|
|
// ancestor projects to the policy filter via ExtendedPolicy calls. If
|
|
|
|
|
// we skip populating membership data on a parent, the policy framework
|
|
|
|
|
// will think the user is not a member of the parent project.
|
2016-01-19 09:36:40 -08:00
|
|
|
|
2015-12-23 03:12:20 -08:00
|
|
|
$all_sources = array();
|
2016-11-11 12:35:22 -08:00
|
|
|
foreach ($all_graph as $project) {
|
2016-02-16 10:11:12 -08:00
|
|
|
// For milestones, we need parent members.
|
2015-12-23 03:12:20 -08:00
|
|
|
if ($project->isMilestone()) {
|
2016-02-16 10:11:12 -08:00
|
|
|
$parent_phid = $project->getParentProjectPHID();
|
|
|
|
|
$all_sources[$parent_phid] = $parent_phid;
|
2015-12-23 03:12:20 -08:00
|
|
|
}
|
2016-02-16 10:11:12 -08:00
|
|
|
|
|
|
|
|
$phid = $project->getPHID();
|
2015-12-23 03:12:20 -08:00
|
|
|
$all_sources[$phid] = $phid;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
$edge_query = id(new PhabricatorEdgeQuery())
|
2015-12-23 03:12:20 -08:00
|
|
|
->withSourcePHIDs($all_sources)
|
2015-12-23 03:42:42 -08:00
|
|
|
->withEdgeTypes($types);
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
$need_all_edges =
|
|
|
|
|
$this->needMembers ||
|
|
|
|
|
$this->needWatchers ||
|
|
|
|
|
$this->needAncestorMembers;
|
|
|
|
|
|
2015-12-23 03:42:42 -08:00
|
|
|
// If we only need to know if the viewer is a member, we can restrict
|
|
|
|
|
// the query to just their PHID.
|
2015-12-27 04:15:39 -08:00
|
|
|
$any_edges = true;
|
2016-01-19 09:36:40 -08:00
|
|
|
if (!$need_all_edges) {
|
2015-12-27 04:15:39 -08:00
|
|
|
if ($viewer_phid) {
|
|
|
|
|
$edge_query->withDestinationPHIDs(array($viewer_phid));
|
|
|
|
|
} else {
|
|
|
|
|
// If we don't need members or watchers and don't have a viewer PHID
|
|
|
|
|
// (viewer is logged-out or omnipotent), they'll never be a member
|
|
|
|
|
// so we don't need to issue this query at all.
|
|
|
|
|
$any_edges = false;
|
|
|
|
|
}
|
2015-12-23 03:42:42 -08:00
|
|
|
}
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-27 04:15:39 -08:00
|
|
|
if ($any_edges) {
|
|
|
|
|
$edge_query->execute();
|
|
|
|
|
}
|
2014-05-19 12:40:57 -07:00
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
$membership_projects = array();
|
2016-11-11 12:35:22 -08:00
|
|
|
foreach ($all_graph as $project) {
|
2015-12-23 03:42:42 -08:00
|
|
|
$project_phid = $project->getPHID();
|
|
|
|
|
|
2015-12-23 03:12:20 -08:00
|
|
|
if ($project->isMilestone()) {
|
|
|
|
|
$source_phids = array($project->getParentProjectPHID());
|
|
|
|
|
} else {
|
|
|
|
|
$source_phids = array($project_phid);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 04:15:39 -08:00
|
|
|
if ($any_edges) {
|
|
|
|
|
$member_phids = $edge_query->getDestinationPHIDs(
|
|
|
|
|
$source_phids,
|
2015-12-27 04:27:58 -08:00
|
|
|
array($material_type));
|
2015-12-27 04:15:39 -08:00
|
|
|
} else {
|
|
|
|
|
$member_phids = array();
|
|
|
|
|
}
|
2015-12-23 03:42:42 -08:00
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
if (in_array($viewer_phid, $member_phids)) {
|
|
|
|
|
$membership_projects[$project_phid] = $project;
|
|
|
|
|
}
|
2015-12-23 03:42:42 -08:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
if ($this->needMembers || $this->needAncestorMembers) {
|
2015-12-23 03:42:42 -08:00
|
|
|
$project->attachMemberPHIDs($member_phids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->needWatchers) {
|
|
|
|
|
$watcher_phids = $edge_query->getDestinationPHIDs(
|
2016-02-16 10:11:12 -08:00
|
|
|
array($project_phid),
|
2015-12-23 03:42:42 -08:00
|
|
|
array($watcher_type));
|
|
|
|
|
$project->attachWatcherPHIDs($watcher_phids);
|
|
|
|
|
$project->setIsUserWatcher(
|
|
|
|
|
$viewer_phid,
|
|
|
|
|
in_array($viewer_phid, $watcher_phids));
|
2014-05-19 12:40:57 -07:00
|
|
|
}
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
}
|
2013-10-06 17:07:20 -07:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
// If we loaded ancestor members, we've already populated membership
|
|
|
|
|
// lists above, so we can skip this step.
|
|
|
|
|
if (!$this->needAncestorMembers) {
|
|
|
|
|
$member_graph = $this->getAllReachableAncestors($membership_projects);
|
2015-12-23 03:42:51 -08:00
|
|
|
|
2016-01-19 09:36:40 -08:00
|
|
|
foreach ($all_graph as $phid => $project) {
|
|
|
|
|
$is_member = isset($member_graph[$phid]);
|
|
|
|
|
$project->setIsUserMember($viewer_phid, $is_member);
|
|
|
|
|
}
|
2015-12-23 03:42:51 -08:00
|
|
|
}
|
|
|
|
|
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
return $projects;
|
|
|
|
|
}
|
2013-10-06 17:07:43 -07:00
|
|
|
|
Fix some file policy issues and add a "Query Workspace"
Summary:
Ref T603. Several issues here:
1. Currently, `FileQuery` does not actually respect object attachment edges when doing policy checks. Everything else works fine, but this was missing an `array_keys()`.
2. Once that's fixed, we hit a bunch of recursion issues. For example, when loading a User we load the profile picture, and then that loads the User, and that loads the profile picture, etc.
3. Introduce a "Query Workspace", which holds objects we know we've loaded and know we can see but haven't finished filtering and/or attaching data to. This allows subqueries to look up objects instead of querying for them.
- We can probably generalize this a bit to make a few other queries more efficient. Pholio currently has a similar (but less general) "mock cache". However, it's keyed by ID instead of PHID so it's not easy to reuse this right now.
This is a bit complex for the problem being solved, but I think it's the cleanest approach and I believe the primitive will be useful in the future.
Test Plan: Looked at pastes, macros, mocks and projects as a logged-in and logged-out user.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7309
2013-10-14 14:36:06 -07:00
|
|
|
protected function didFilterPage(array $projects) {
|
2018-03-14 11:20:33 -07:00
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
Migrate project profiles onto projects, and remove ProjectProfile object
Summary:
Ref T4379. Long ago, the "Project" vs "ProjectProfile" split was intended to allow a bunch of special fields on projects without burdening the simple use cases, but CustomField handles that far better and far more generally, and doing this makes using ApplicationTransactions a pain to get right, so get rid of it.
The only remaining field is `profileImagePHID`, which we can just move to the main Project object. This is custom enough that I think it's reasonable not to express it as a custom field.
Test Plan: Created a project, set profile, edited project, viewed in typeahead, ran migration, verified database results.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4379
Differential Revision: https://secure.phabricator.com/D8183
2014-02-10 14:32:14 -08:00
|
|
|
if ($this->needImages) {
|
2018-03-14 11:20:33 -07:00
|
|
|
$need_images = $projects;
|
|
|
|
|
|
|
|
|
|
// First, try to load custom profile images for any projects with custom
|
|
|
|
|
// images.
|
|
|
|
|
$file_phids = array();
|
|
|
|
|
foreach ($need_images as $key => $project) {
|
|
|
|
|
$image_phid = $project->getProfileImagePHID();
|
|
|
|
|
if ($image_phid) {
|
|
|
|
|
$file_phids[$key] = $image_phid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-30 11:19:24 -07:00
|
|
|
if ($file_phids) {
|
|
|
|
|
$files = id(new PhabricatorFileQuery())
|
|
|
|
|
->setParentQuery($this)
|
2018-03-14 11:20:33 -07:00
|
|
|
->setViewer($viewer)
|
2015-06-30 11:19:24 -07:00
|
|
|
->withPHIDs($file_phids)
|
|
|
|
|
->execute();
|
|
|
|
|
$files = mpull($files, null, 'getPHID');
|
2018-03-14 11:20:33 -07:00
|
|
|
|
|
|
|
|
foreach ($file_phids as $key => $image_phid) {
|
|
|
|
|
$file = idx($files, $image_phid);
|
|
|
|
|
if (!$file) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$need_images[$key]->attachProfileImageFile($file);
|
|
|
|
|
unset($need_images[$key]);
|
|
|
|
|
}
|
2015-06-30 11:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 11:20:33 -07:00
|
|
|
// For projects with default images, or projects where the custom image
|
|
|
|
|
// failed to load, load a builtin image.
|
|
|
|
|
if ($need_images) {
|
|
|
|
|
$builtin_map = array();
|
|
|
|
|
$builtins = array();
|
|
|
|
|
foreach ($need_images as $key => $project) {
|
|
|
|
|
$icon = $project->getIcon();
|
|
|
|
|
|
|
|
|
|
$builtin_name = PhabricatorProjectIconSet::getIconImage($icon);
|
|
|
|
|
$builtin_name = 'projects/'.$builtin_name;
|
|
|
|
|
|
|
|
|
|
$builtin = id(new PhabricatorFilesOnDiskBuiltinFile())
|
|
|
|
|
->setName($builtin_name);
|
|
|
|
|
|
|
|
|
|
$builtin_key = $builtin->getBuiltinFileKey();
|
|
|
|
|
|
|
|
|
|
$builtins[] = $builtin;
|
|
|
|
|
$builtin_map[$key] = $builtin_key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$builtin_files = PhabricatorFile::loadBuiltins(
|
|
|
|
|
$viewer,
|
|
|
|
|
$builtins);
|
|
|
|
|
|
|
|
|
|
foreach ($need_images as $key => $project) {
|
|
|
|
|
$builtin_key = $builtin_map[$key];
|
|
|
|
|
$builtin_file = $builtin_files[$builtin_key];
|
|
|
|
|
$project->attachProfileImageFile($builtin_file);
|
2013-10-06 17:07:20 -07:00
|
|
|
}
|
|
|
|
|
}
|
2012-01-17 16:29:35 -08:00
|
|
|
}
|
|
|
|
|
|
2015-12-27 02:28:36 -08:00
|
|
|
$this->loadSlugs($projects);
|
2014-05-22 11:19:03 -07:00
|
|
|
|
2012-01-17 16:29:35 -08:00
|
|
|
return $projects;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
2012-01-17 16:29:35 -08:00
|
|
|
|
2012-02-07 14:59:38 -08:00
|
|
|
if ($this->status != self::STATUS_ANY) {
|
|
|
|
|
switch ($this->status) {
|
|
|
|
|
case self::STATUS_OPEN:
|
|
|
|
|
case self::STATUS_ACTIVE:
|
2012-08-07 18:02:05 -07:00
|
|
|
$filter = array(
|
|
|
|
|
PhabricatorProjectStatus::STATUS_ACTIVE,
|
|
|
|
|
);
|
2012-02-07 14:59:38 -08:00
|
|
|
break;
|
2012-08-07 18:02:05 -07:00
|
|
|
case self::STATUS_CLOSED:
|
2012-02-07 14:59:38 -08:00
|
|
|
case self::STATUS_ARCHIVED:
|
2012-08-07 18:02:05 -07:00
|
|
|
$filter = array(
|
|
|
|
|
PhabricatorProjectStatus::STATUS_ARCHIVED,
|
|
|
|
|
);
|
2012-02-07 14:59:38 -08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Exception(
|
2015-05-22 17:27:56 +10:00
|
|
|
pht(
|
|
|
|
|
"Unknown project status '%s'!",
|
|
|
|
|
$this->status));
|
2012-02-07 14:59:38 -08:00
|
|
|
}
|
2012-08-07 18:02:05 -07:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.status IN (%Ld)',
|
2012-08-07 18:02:05 -07:00
|
|
|
$filter);
|
2012-02-07 14:59:38 -08:00
|
|
|
}
|
|
|
|
|
|
2016-02-06 12:40:31 -08:00
|
|
|
if ($this->statuses !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.status IN (%Ls)',
|
2016-02-06 12:40:31 -08:00
|
|
|
$this->statuses);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->ids !== null) {
|
2012-01-17 16:29:35 -08:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.id IN (%Ld)',
|
2012-01-17 16:29:35 -08:00
|
|
|
$this->ids);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->phids !== null) {
|
2012-01-17 16:29:35 -08:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.phid IN (%Ls)',
|
2012-01-17 16:29:35 -08:00
|
|
|
$this->phids);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->memberPHIDs !== null) {
|
2012-08-07 18:02:05 -07:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2012-08-11 07:05:01 -07:00
|
|
|
'e.dst IN (%Ls)',
|
2012-08-07 18:02:05 -07:00
|
|
|
$this->memberPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 11:37:01 -08:00
|
|
|
if ($this->watcherPHIDs !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'w.dst IN (%Ls)',
|
|
|
|
|
$this->watcherPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->slugs !== null) {
|
2013-03-08 07:12:24 -08:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2014-05-22 11:19:03 -07:00
|
|
|
'slug.slug IN (%Ls)',
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
$this->allSlugs);
|
2013-03-08 07:12:24 -08:00
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->names !== null) {
|
2013-10-25 10:16:39 -07:00
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.name IN (%Ls)',
|
2013-10-25 10:16:39 -07:00
|
|
|
$this->names);
|
|
|
|
|
}
|
|
|
|
|
|
Separate sever-side typeahead queries into "prefix" and "content" phases
Summary:
Ref T8510. When users type "platypus" into a typeahead, they want "Platypus Playground" to be a higher-ranked match than "AAA Platypus", even though the latter is alphabetically first.
Specifically, the rule is: results which match the query as a prefix of the result text should rank above results which do not.
I believe we now always get this right on the client side. However, WMF has at least one case (described in T8510) where we do not get it right on the server side, and thus the user sees the wrong result.
The remaining issue is that if "platypus" matches more than 100 results, the result "Platypus Playground" may not appear in the result set at all, beacuse there are 100 copies of "AAA Platypus 1", "AAA Platypus 2", etc., first. So even though the client will apply the correct sort, it doesn't have the result the user wants and can't show it to them.
To fix this, split the server-side query into two phases:
- In the first phase, the "prefix" phase, we find results that **start with** "platypus".
- In the second phase, the "content" phase, we find results that contain "platypus" anywhere.
We skip the "prefix" phase if the user has not typed a query (for example, in the browse view).
Test Plan:
This is a lot of stuff, but the new ranking here puts projects which start with "w" at the top of the list. Lower down the list, you can see some projects which contain "w" but do not appear at the top (like "Serious Work").
{F1913931}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T8510
Differential Revision: https://secure.phabricator.com/D16838
2016-11-10 07:24:15 -08:00
|
|
|
if ($this->namePrefixes) {
|
|
|
|
|
$parts = array();
|
|
|
|
|
foreach ($this->namePrefixes as $name_prefix) {
|
|
|
|
|
$parts[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.name LIKE %>',
|
Separate sever-side typeahead queries into "prefix" and "content" phases
Summary:
Ref T8510. When users type "platypus" into a typeahead, they want "Platypus Playground" to be a higher-ranked match than "AAA Platypus", even though the latter is alphabetically first.
Specifically, the rule is: results which match the query as a prefix of the result text should rank above results which do not.
I believe we now always get this right on the client side. However, WMF has at least one case (described in T8510) where we do not get it right on the server side, and thus the user sees the wrong result.
The remaining issue is that if "platypus" matches more than 100 results, the result "Platypus Playground" may not appear in the result set at all, beacuse there are 100 copies of "AAA Platypus 1", "AAA Platypus 2", etc., first. So even though the client will apply the correct sort, it doesn't have the result the user wants and can't show it to them.
To fix this, split the server-side query into two phases:
- In the first phase, the "prefix" phase, we find results that **start with** "platypus".
- In the second phase, the "content" phase, we find results that contain "platypus" anywhere.
We skip the "prefix" phase if the user has not typed a query (for example, in the browse view).
Test Plan:
This is a lot of stuff, but the new ranking here puts projects which start with "w" at the top of the list. Lower down the list, you can see some projects which contain "w" but do not appear at the top (like "Serious Work").
{F1913931}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T8510
Differential Revision: https://secure.phabricator.com/D16838
2016-11-10 07:24:15 -08:00
|
|
|
$name_prefix);
|
|
|
|
|
}
|
2018-11-15 05:53:34 -08:00
|
|
|
$where[] = qsprintf($conn, '%LO', $parts);
|
Separate sever-side typeahead queries into "prefix" and "content" phases
Summary:
Ref T8510. When users type "platypus" into a typeahead, they want "Platypus Playground" to be a higher-ranked match than "AAA Platypus", even though the latter is alphabetically first.
Specifically, the rule is: results which match the query as a prefix of the result text should rank above results which do not.
I believe we now always get this right on the client side. However, WMF has at least one case (described in T8510) where we do not get it right on the server side, and thus the user sees the wrong result.
The remaining issue is that if "platypus" matches more than 100 results, the result "Platypus Playground" may not appear in the result set at all, beacuse there are 100 copies of "AAA Platypus 1", "AAA Platypus 2", etc., first. So even though the client will apply the correct sort, it doesn't have the result the user wants and can't show it to them.
To fix this, split the server-side query into two phases:
- In the first phase, the "prefix" phase, we find results that **start with** "platypus".
- In the second phase, the "content" phase, we find results that contain "platypus" anywhere.
We skip the "prefix" phase if the user has not typed a query (for example, in the browse view).
Test Plan:
This is a lot of stuff, but the new ranking here puts projects which start with "w" at the top of the list. Lower down the list, you can see some projects which contain "w" but do not appear at the top (like "Serious Work").
{F1913931}
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T8510
Differential Revision: https://secure.phabricator.com/D16838
2016-11-10 07:24:15 -08:00
|
|
|
}
|
|
|
|
|
|
2014-08-12 08:04:38 -07:00
|
|
|
if ($this->icons !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.icon IN (%Ls)',
|
2014-08-12 08:04:38 -07:00
|
|
|
$this->icons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->colors !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.color IN (%Ls)',
|
2014-08-12 08:04:38 -07:00
|
|
|
$this->colors);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 07:01:27 -08:00
|
|
|
if ($this->parentPHIDs !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.parentProjectPHID IN (%Ls)',
|
2015-12-23 07:01:27 -08:00
|
|
|
$this->parentPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->ancestorPHIDs !== null) {
|
|
|
|
|
$ancestor_paths = queryfx_all(
|
|
|
|
|
$conn,
|
|
|
|
|
'SELECT projectPath, projectDepth FROM %T WHERE phid IN (%Ls)',
|
|
|
|
|
id(new PhabricatorProject())->getTableName(),
|
|
|
|
|
$this->ancestorPHIDs);
|
|
|
|
|
if (!$ancestor_paths) {
|
|
|
|
|
throw new PhabricatorEmptyQueryException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sql = array();
|
|
|
|
|
foreach ($ancestor_paths as $ancestor_path) {
|
|
|
|
|
$sql[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'(project.projectPath LIKE %> AND project.projectDepth > %d)',
|
2015-12-23 07:01:27 -08:00
|
|
|
$ancestor_path['projectPath'],
|
|
|
|
|
$ancestor_path['projectDepth']);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 09:32:52 -08:00
|
|
|
$where[] = qsprintf($conn, '%LO', $sql);
|
2015-12-23 07:01:27 -08:00
|
|
|
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.parentProjectPHID IS NOT NULL');
|
2015-12-23 07:01:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->isMilestone !== null) {
|
|
|
|
|
if ($this->isMilestone) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.milestoneNumber IS NOT NULL');
|
2015-12-23 07:01:27 -08:00
|
|
|
} else {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.milestoneNumber IS NULL');
|
2015-12-23 07:01:27 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 10:57:13 -08:00
|
|
|
|
2015-12-23 03:12:20 -08:00
|
|
|
if ($this->hasSubprojects !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.hasSubprojects = %d',
|
2015-12-23 03:12:20 -08:00
|
|
|
(int)$this->hasSubprojects);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-23 07:01:27 -08:00
|
|
|
if ($this->minDepth !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.projectDepth >= %d',
|
2015-12-23 07:01:27 -08:00
|
|
|
$this->minDepth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->maxDepth !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.projectDepth <= %d',
|
2015-12-23 07:01:27 -08:00
|
|
|
$this->maxDepth);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 10:57:13 -08:00
|
|
|
if ($this->minMilestoneNumber !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.milestoneNumber >= %d',
|
2016-02-12 10:57:13 -08:00
|
|
|
$this->minMilestoneNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->maxMilestoneNumber !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.milestoneNumber <= %d',
|
2016-02-12 10:57:13 -08:00
|
|
|
$this->maxMilestoneNumber);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-26 07:29:03 -08:00
|
|
|
if ($this->subtypes !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'project.subtype IN (%Ls)',
|
2019-01-26 07:29:03 -08:00
|
|
|
$this->subtypes);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
return $where;
|
2011-12-16 17:08:18 -08:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
protected function shouldGroupQueryResultRows() {
|
2016-02-17 11:37:01 -08:00
|
|
|
if ($this->memberPHIDs || $this->watcherPHIDs || $this->nameTokens) {
|
2015-06-08 12:20:53 -07:00
|
|
|
return true;
|
2012-08-07 18:02:05 -07:00
|
|
|
}
|
2020-07-09 10:42:42 -07:00
|
|
|
|
|
|
|
|
if ($this->slugs) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
return parent::shouldGroupQueryResultRows();
|
2012-08-07 18:02:05 -07:00
|
|
|
}
|
2011-12-16 17:08:18 -08:00
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
|
$joins = parent::buildJoinClauseParts($conn);
|
2012-08-07 18:02:05 -07:00
|
|
|
|
2014-07-17 16:35:54 -07:00
|
|
|
if ($this->memberPHIDs !== null) {
|
2011-12-16 17:08:18 -08:00
|
|
|
$joins[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'JOIN %T e ON e.src = project.phid AND e.type = %d',
|
2012-08-11 07:05:01 -07:00
|
|
|
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
|
2015-12-27 04:27:58 -08:00
|
|
|
PhabricatorProjectMaterializedMemberEdgeType::EDGECONST);
|
2011-12-16 17:08:18 -08:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 11:37:01 -08:00
|
|
|
if ($this->watcherPHIDs !== null) {
|
|
|
|
|
$joins[] = qsprintf(
|
|
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'JOIN %T w ON w.src = project.phid AND w.type = %d',
|
2016-02-17 11:37:01 -08:00
|
|
|
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
|
|
|
|
|
PhabricatorObjectHasWatcherEdgeType::EDGECONST);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 16:35:54 -07:00
|
|
|
if ($this->slugs !== null) {
|
2014-05-22 11:19:03 -07:00
|
|
|
$joins[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'JOIN %T slug on slug.projectPHID = project.phid',
|
2014-05-22 11:19:03 -07:00
|
|
|
id(new PhabricatorProjectSlug())->getTableName());
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 11:49:07 -07:00
|
|
|
if ($this->nameTokens !== null) {
|
2017-08-30 11:08:50 -07:00
|
|
|
$name_tokens = $this->getNameTokensForQuery($this->nameTokens);
|
|
|
|
|
foreach ($name_tokens as $key => $token) {
|
2015-04-15 11:49:07 -07:00
|
|
|
$token_table = 'token_'.$key;
|
|
|
|
|
$joins[] = qsprintf(
|
2015-06-08 12:20:53 -07:00
|
|
|
$conn,
|
2019-08-15 12:00:16 -07:00
|
|
|
'JOIN %T %T ON %T.projectID = project.id AND %T.token LIKE %>',
|
2015-04-15 11:49:07 -07:00
|
|
|
PhabricatorProject::TABLE_DATASOURCE_TOKEN,
|
|
|
|
|
$token_table,
|
|
|
|
|
$token_table,
|
|
|
|
|
$token_table,
|
|
|
|
|
$token);
|
2014-07-17 16:35:54 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 12:20:53 -07:00
|
|
|
return $joins;
|
2011-12-16 17:08:18 -08:00
|
|
|
}
|
|
|
|
|
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-21 17:20:27 -07:00
|
|
|
public function getQueryApplicationClass() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorProjectApplication';
|
Lock policy queries to their applications
Summary:
While we mostly have reasonable effective object accessibility when you lock a user out of an application, it's primarily enforced at the controller level. Users can still, e.g., load the handles of objects they can't actually see. Instead, lock the queries to the applications so that you can, e.g., never load a revision if you don't have access to Differential.
This has several parts:
- For PolicyAware queries, provide an application class name method.
- If the query specifies a class name and the user doesn't have permission to use it, fail the entire query unconditionally.
- For handles, simplify query construction and count all the PHIDs as "restricted" so we get a UI full of "restricted" instead of "unknown" handles.
Test Plan:
- Added a unit test to verify I got all the class names right.
- Browsed around, logged in/out as a normal user with public policies on and off.
- Browsed around, logged in/out as a restricted user with public policies on and off. With restrictions, saw all traces of restricted apps removed or restricted.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Differential Revision: https://secure.phabricator.com/D7367
2013-10-21 17:20:27 -07:00
|
|
|
}
|
|
|
|
|
|
2015-04-11 19:00:53 -07:00
|
|
|
protected function getPrimaryTableAlias() {
|
2019-08-15 12:00:16 -07:00
|
|
|
return 'project';
|
2014-02-10 14:31:34 -08:00
|
|
|
}
|
|
|
|
|
|
2015-12-23 03:42:51 -08:00
|
|
|
private function linkProjectGraph(array $projects, array $ancestors) {
|
|
|
|
|
$ancestor_map = mpull($ancestors, null, 'getPHID');
|
|
|
|
|
$projects_map = mpull($projects, null, 'getPHID');
|
|
|
|
|
|
|
|
|
|
$all_map = $projects_map + $ancestor_map;
|
|
|
|
|
|
|
|
|
|
$done = array();
|
|
|
|
|
foreach ($projects as $key => $project) {
|
|
|
|
|
$seen = array($project->getPHID() => true);
|
|
|
|
|
|
|
|
|
|
if (!$this->linkProject($project, $all_map, $done, $seen)) {
|
|
|
|
|
$this->didRejectResult($project);
|
|
|
|
|
unset($projects[$key]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($project->getAncestorProjects() as $ancestor) {
|
|
|
|
|
$seen[$ancestor->getPHID()] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $projects;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function linkProject($project, array $all, array $done, array $seen) {
|
|
|
|
|
$parent_phid = $project->getParentProjectPHID();
|
|
|
|
|
|
|
|
|
|
// This project has no parent, so just attach `null` and return.
|
|
|
|
|
if (!$parent_phid) {
|
|
|
|
|
$project->attachParentProject(null);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This project has a parent, but it failed to load.
|
|
|
|
|
if (empty($all[$parent_phid])) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test for graph cycles. If we encounter one, we're going to hide the
|
|
|
|
|
// entire cycle since we can't meaningfully resolve it.
|
|
|
|
|
if (isset($seen[$parent_phid])) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$seen[$parent_phid] = true;
|
|
|
|
|
|
|
|
|
|
$parent = $all[$parent_phid];
|
|
|
|
|
$project->attachParentProject($parent);
|
|
|
|
|
|
|
|
|
|
if (!empty($done[$parent_phid])) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->linkProject($parent, $all, $done, $seen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getAllReachableAncestors(array $projects) {
|
|
|
|
|
$ancestors = array();
|
|
|
|
|
|
|
|
|
|
$seen = mpull($projects, null, 'getPHID');
|
|
|
|
|
|
|
|
|
|
$stack = $projects;
|
|
|
|
|
while ($stack) {
|
|
|
|
|
$project = array_pop($stack);
|
|
|
|
|
|
|
|
|
|
$phid = $project->getPHID();
|
|
|
|
|
$ancestors[$phid] = $project;
|
|
|
|
|
|
|
|
|
|
$parent_phid = $project->getParentProjectPHID();
|
|
|
|
|
if (!$parent_phid) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($seen[$parent_phid])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$seen[$parent_phid] = true;
|
|
|
|
|
$stack[] = $project->getParentProject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ancestors;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 02:28:36 -08:00
|
|
|
private function loadSlugs(array $projects) {
|
|
|
|
|
// Build a map from primary slugs to projects.
|
|
|
|
|
$primary_map = array();
|
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
|
$primary_slug = $project->getPrimarySlug();
|
|
|
|
|
if ($primary_slug === null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$primary_map[$primary_slug] = $project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Link up all of the queried slugs which correspond to primary
|
|
|
|
|
// slugs. If we can link up everything from this (no slugs were queried,
|
|
|
|
|
// or only primary slugs were queried) we don't need to load anything
|
|
|
|
|
// else.
|
|
|
|
|
$unknown = $this->slugNormals;
|
|
|
|
|
foreach ($unknown as $input => $normal) {
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
if (isset($primary_map[$input])) {
|
|
|
|
|
$match = $input;
|
|
|
|
|
} else if (isset($primary_map[$normal])) {
|
|
|
|
|
$match = $normal;
|
|
|
|
|
} else {
|
2015-12-27 02:28:36 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->slugMap[$input] = array(
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
'slug' => $match,
|
|
|
|
|
'projectPHID' => $primary_map[$match]->getPHID(),
|
2015-12-27 02:28:36 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
unset($unknown[$input]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we need slugs, we have to load everything.
|
|
|
|
|
// If we still have some queried slugs which we haven't mapped, we only
|
|
|
|
|
// need to look for them.
|
|
|
|
|
// If we've mapped everything, we don't have to do any work.
|
|
|
|
|
$project_phids = mpull($projects, 'getPHID');
|
|
|
|
|
if ($this->needSlugs) {
|
|
|
|
|
$slugs = id(new PhabricatorProjectSlug())->loadAllWhere(
|
|
|
|
|
'projectPHID IN (%Ls)',
|
|
|
|
|
$project_phids);
|
|
|
|
|
} else if ($unknown) {
|
|
|
|
|
$slugs = id(new PhabricatorProjectSlug())->loadAllWhere(
|
|
|
|
|
'projectPHID IN (%Ls) AND slug IN (%Ls)',
|
|
|
|
|
$project_phids,
|
|
|
|
|
$unknown);
|
|
|
|
|
} else {
|
|
|
|
|
$slugs = array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Link up any slugs we were not able to link up earlier.
|
|
|
|
|
$extra_map = mpull($slugs, 'getProjectPHID', 'getSlug');
|
|
|
|
|
foreach ($unknown as $input => $normal) {
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
if (isset($extra_map[$input])) {
|
|
|
|
|
$match = $input;
|
|
|
|
|
} else if (isset($extra_map[$normal])) {
|
|
|
|
|
$match = $normal;
|
|
|
|
|
} else {
|
2015-12-27 02:28:36 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->slugMap[$input] = array(
|
Allow older, invalid project tags to continue to function
Summary:
Ref T10168.
Around October 12, T9551 made project hashtags stricter and prevented them from containing characters like comma (`,`).
Around December 27, D14888 changed how hashtags queries work so that the query does normalization instead of requiring the caller to normalize.
After the Dec 27 change, projects from before Oct 12 with now-invalid hashtags will no longer load when queried directly by hashtag, because the page queries for `old,[silly]hash,,tag` or whatever, it gets normalized into `old_silly_hash_tag`, and then there are no hits.
Instead, at least for now, query by both the exact raw text and the normalized hashtag. This should keep older stuff working until we can give users more support for migrating forward.
Test Plan:
- Forced a project to have a bogus hahstag.
- Before patch: clicking its tag 404'd.
- After patch: clicking its tag now works.
- Visited a project by alternate hashtag.
- Visited a project by denormalized hashtag and alternate hashtag (e.g., capital letters instead of lowercase letters), saw it redirect/normalize properly.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T10168
Differential Revision: https://secure.phabricator.com/D15047
2016-01-18 07:36:28 -08:00
|
|
|
'slug' => $match,
|
|
|
|
|
'projectPHID' => $extra_map[$match],
|
2015-12-27 02:28:36 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
unset($unknown[$input]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->needSlugs) {
|
|
|
|
|
$slug_groups = mgroup($slugs, 'getProjectPHID');
|
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
|
$project_slugs = idx($slug_groups, $project->getPHID(), array());
|
|
|
|
|
$project->attachSlugs($project_slugs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-30 11:08:50 -07:00
|
|
|
private function getNameTokensForQuery(array $tokens) {
|
|
|
|
|
// When querying for projects by name, only actually search for the five
|
|
|
|
|
// longest tokens. MySQL can get grumpy with a large number of JOINs
|
|
|
|
|
// with LIKEs and queries for more than 5 tokens are essentially never
|
|
|
|
|
// legitimate searches for projects, but users copy/pasting nonsense.
|
|
|
|
|
// See also PHI47.
|
|
|
|
|
|
|
|
|
|
$length_map = array();
|
|
|
|
|
foreach ($tokens as $token) {
|
|
|
|
|
$length_map[$token] = strlen($token);
|
|
|
|
|
}
|
|
|
|
|
arsort($length_map);
|
|
|
|
|
|
|
|
|
|
$length_map = array_slice($length_map, 0, 5, true);
|
|
|
|
|
|
|
|
|
|
return array_keys($length_map);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-16 17:08:18 -08:00
|
|
|
}
|