Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/query/PhabricatorProjectQuery.php
<?php | <?php | ||||
final class PhabricatorProjectQuery | final class PhabricatorProjectQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $memberPHIDs; | private $memberPHIDs; | ||||
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; | ||||
private $colors; | private $colors; | ||||
private $ancestorPHIDs; | private $ancestorPHIDs; | ||||
private $parentPHIDs; | private $parentPHIDs; | ||||
private $isMilestone; | private $isMilestone; | ||||
private $hasSubprojects; | private $hasSubprojects; | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | if ($this->slugMap === null) { | ||||
throw new PhutilInvalidStateException('execute'); | throw new PhutilInvalidStateException('execute'); | ||||
} | } | ||||
return $this->slugMap; | return $this->slugMap; | ||||
} | } | ||||
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; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | if ($this->memberPHIDs !== null) { | ||||
'e.dst IN (%Ls)', | 'e.dst IN (%Ls)', | ||||
$this->memberPHIDs); | $this->memberPHIDs); | ||||
} | } | ||||
if ($this->slugs !== null) { | if ($this->slugs !== null) { | ||||
$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) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'name IN (%Ls)', | 'name IN (%Ls)', | ||||
$this->names); | $this->names); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | private function loadSlugs(array $projects) { | ||||
} | } | ||||
// Link up all of the queried slugs which correspond to primary | // Link up all of the queried slugs which correspond to primary | ||||
// slugs. If we can link up everything from this (no slugs were queried, | // 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 | // or only primary slugs were queried) we don't need to load anything | ||||
// 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]); | ||||
} | } | ||||
// If we need slugs, we have to load everything. | // If we need slugs, we have to load everything. | ||||
// If we still have some queried slugs which we haven't mapped, we only | // If we still have some queried slugs which we haven't mapped, we only | ||||
// need to look for them. | // need to look for them. | ||||
Show All 10 Lines | if ($this->needSlugs) { | ||||
$unknown); | $unknown); | ||||
} else { | } else { | ||||
$slugs = array(); | $slugs = array(); | ||||
} | } | ||||
// 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]); | ||||
} | } | ||||
if ($this->needSlugs) { | if ($this->needSlugs) { | ||||
$slug_groups = mgroup($slugs, 'getProjectPHID'); | $slug_groups = mgroup($slugs, 'getProjectPHID'); | ||||
foreach ($projects as $project) { | foreach ($projects as $project) { | ||||
$project_slugs = idx($slug_groups, $project->getPHID(), array()); | $project_slugs = idx($slug_groups, $project->getPHID(), array()); | ||||
$project->attachSlugs($project_slugs); | $project->attachSlugs($project_slugs); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |