1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

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
This commit is contained in:
epriestley 2016-01-18 07:36:28 -08:00
parent 2144d877ee
commit 10ef973735

View file

@ -9,6 +9,7 @@ final class PhabricatorProjectQuery
private $slugs; private $slugs;
private $slugNormals; private $slugNormals;
private $slugMap; private $slugMap;
private $allSlugs;
private $names; private $names;
private $nameTokens; private $nameTokens;
private $icons; private $icons;
@ -169,10 +170,19 @@ final class PhabricatorProjectQuery
protected function willExecute() { protected function willExecute() {
$this->slugMap = array(); $this->slugMap = array();
$this->slugNormals = array(); $this->slugNormals = array();
$this->allSlugs = array();
if ($this->slugs) { if ($this->slugs) {
foreach ($this->slugs as $slug) { foreach ($this->slugs as $slug) {
if (PhabricatorSlug::isValidProjectSlug($slug)) {
$normal = PhabricatorSlug::normalizeProjectSlug($slug); $normal = PhabricatorSlug::normalizeProjectSlug($slug);
$this->slugNormals[$slug] = $normal; $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;
} }
} }
} }
@ -380,7 +390,7 @@ final class PhabricatorProjectQuery
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'slug.slug IN (%Ls)', 'slug.slug IN (%Ls)',
$this->slugNormals); $this->allSlugs);
} }
if ($this->names !== null) { if ($this->names !== null) {
@ -625,13 +635,17 @@ final class PhabricatorProjectQuery
// else. // else.
$unknown = $this->slugNormals; $unknown = $this->slugNormals;
foreach ($unknown as $input => $normal) { foreach ($unknown as $input => $normal) {
if (!isset($primary_map[$normal])) { if (isset($primary_map[$input])) {
$match = $input;
} else if (isset($primary_map[$normal])) {
$match = $normal;
} else {
continue; continue;
} }
$this->slugMap[$input] = array( $this->slugMap[$input] = array(
'slug' => $normal, 'slug' => $match,
'projectPHID' => $primary_map[$normal]->getPHID(), 'projectPHID' => $primary_map[$match]->getPHID(),
); );
unset($unknown[$input]); unset($unknown[$input]);
@ -658,13 +672,17 @@ final class PhabricatorProjectQuery
// Link up any slugs we were not able to link up earlier. // Link up any slugs we were not able to link up earlier.
$extra_map = mpull($slugs, 'getProjectPHID', 'getSlug'); $extra_map = mpull($slugs, 'getProjectPHID', 'getSlug');
foreach ($unknown as $input => $normal) { foreach ($unknown as $input => $normal) {
if (!isset($extra_map[$normal])) { if (isset($extra_map[$input])) {
$match = $input;
} else if (isset($extra_map[$normal])) {
$match = $normal;
} else {
continue; continue;
} }
$this->slugMap[$input] = array( $this->slugMap[$input] = array(
'slug' => $normal, 'slug' => $match,
'projectPHID' => $extra_map[$normal], 'projectPHID' => $extra_map[$match],
); );
unset($unknown[$input]); unset($unknown[$input]);