Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/query/PhabricatorProjectQuery.php
Show First 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | if ($this->status != self::STATUS_ANY) { | ||||
default: | default: | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
"Unknown project status '%s'!", | "Unknown project status '%s'!", | ||||
$this->status)); | $this->status)); | ||||
} | } | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'status IN (%Ld)', | 'project.status IN (%Ld)', | ||||
$filter); | $filter); | ||||
} | } | ||||
if ($this->statuses !== null) { | if ($this->statuses !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'status IN (%Ls)', | 'project.status IN (%Ls)', | ||||
$this->statuses); | $this->statuses); | ||||
} | } | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'id IN (%Ld)', | 'project.id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'phid IN (%Ls)', | 'project.phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->memberPHIDs !== null) { | if ($this->memberPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'e.dst IN (%Ls)', | 'e.dst IN (%Ls)', | ||||
$this->memberPHIDs); | $this->memberPHIDs); | ||||
Show All 11 Lines | if ($this->slugs !== null) { | ||||
$conn, | $conn, | ||||
'slug.slug IN (%Ls)', | 'slug.slug IN (%Ls)', | ||||
$this->allSlugs); | $this->allSlugs); | ||||
} | } | ||||
if ($this->names !== null) { | if ($this->names !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'name IN (%Ls)', | 'project.name IN (%Ls)', | ||||
$this->names); | $this->names); | ||||
} | } | ||||
if ($this->namePrefixes) { | if ($this->namePrefixes) { | ||||
$parts = array(); | $parts = array(); | ||||
foreach ($this->namePrefixes as $name_prefix) { | foreach ($this->namePrefixes as $name_prefix) { | ||||
$parts[] = qsprintf( | $parts[] = qsprintf( | ||||
$conn, | $conn, | ||||
'name LIKE %>', | 'project.name LIKE %>', | ||||
$name_prefix); | $name_prefix); | ||||
} | } | ||||
$where[] = qsprintf($conn, '%LO', $parts); | $where[] = qsprintf($conn, '%LO', $parts); | ||||
} | } | ||||
if ($this->icons !== null) { | if ($this->icons !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'icon IN (%Ls)', | 'project.icon IN (%Ls)', | ||||
$this->icons); | $this->icons); | ||||
} | } | ||||
if ($this->colors !== null) { | if ($this->colors !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'color IN (%Ls)', | 'project.color IN (%Ls)', | ||||
$this->colors); | $this->colors); | ||||
} | } | ||||
if ($this->parentPHIDs !== null) { | if ($this->parentPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'parentProjectPHID IN (%Ls)', | 'project.parentProjectPHID IN (%Ls)', | ||||
$this->parentPHIDs); | $this->parentPHIDs); | ||||
} | } | ||||
if ($this->ancestorPHIDs !== null) { | if ($this->ancestorPHIDs !== null) { | ||||
$ancestor_paths = queryfx_all( | $ancestor_paths = queryfx_all( | ||||
$conn, | $conn, | ||||
'SELECT projectPath, projectDepth FROM %T WHERE phid IN (%Ls)', | 'SELECT projectPath, projectDepth FROM %T WHERE phid IN (%Ls)', | ||||
id(new PhabricatorProject())->getTableName(), | id(new PhabricatorProject())->getTableName(), | ||||
$this->ancestorPHIDs); | $this->ancestorPHIDs); | ||||
if (!$ancestor_paths) { | if (!$ancestor_paths) { | ||||
throw new PhabricatorEmptyQueryException(); | throw new PhabricatorEmptyQueryException(); | ||||
} | } | ||||
$sql = array(); | $sql = array(); | ||||
foreach ($ancestor_paths as $ancestor_path) { | foreach ($ancestor_paths as $ancestor_path) { | ||||
$sql[] = qsprintf( | $sql[] = qsprintf( | ||||
$conn, | $conn, | ||||
'(projectPath LIKE %> AND projectDepth > %d)', | '(project.projectPath LIKE %> AND project.projectDepth > %d)', | ||||
$ancestor_path['projectPath'], | $ancestor_path['projectPath'], | ||||
$ancestor_path['projectDepth']); | $ancestor_path['projectDepth']); | ||||
} | } | ||||
$where[] = qsprintf($conn, '%LO', $sql); | $where[] = qsprintf($conn, '%LO', $sql); | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'parentProjectPHID IS NOT NULL'); | 'project.parentProjectPHID IS NOT NULL'); | ||||
} | } | ||||
if ($this->isMilestone !== null) { | if ($this->isMilestone !== null) { | ||||
if ($this->isMilestone) { | if ($this->isMilestone) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'milestoneNumber IS NOT NULL'); | 'project.milestoneNumber IS NOT NULL'); | ||||
} else { | } else { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'milestoneNumber IS NULL'); | 'project.milestoneNumber IS NULL'); | ||||
} | } | ||||
} | } | ||||
if ($this->hasSubprojects !== null) { | if ($this->hasSubprojects !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'hasSubprojects = %d', | 'project.hasSubprojects = %d', | ||||
(int)$this->hasSubprojects); | (int)$this->hasSubprojects); | ||||
} | } | ||||
if ($this->minDepth !== null) { | if ($this->minDepth !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'projectDepth >= %d', | 'project.projectDepth >= %d', | ||||
$this->minDepth); | $this->minDepth); | ||||
} | } | ||||
if ($this->maxDepth !== null) { | if ($this->maxDepth !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'projectDepth <= %d', | 'project.projectDepth <= %d', | ||||
$this->maxDepth); | $this->maxDepth); | ||||
} | } | ||||
if ($this->minMilestoneNumber !== null) { | if ($this->minMilestoneNumber !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'milestoneNumber >= %d', | 'project.milestoneNumber >= %d', | ||||
$this->minMilestoneNumber); | $this->minMilestoneNumber); | ||||
} | } | ||||
if ($this->maxMilestoneNumber !== null) { | if ($this->maxMilestoneNumber !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'milestoneNumber <= %d', | 'project.milestoneNumber <= %d', | ||||
$this->maxMilestoneNumber); | $this->maxMilestoneNumber); | ||||
} | } | ||||
if ($this->subtypes !== null) { | if ($this->subtypes !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'subtype IN (%Ls)', | 'project.subtype IN (%Ls)', | ||||
$this->subtypes); | $this->subtypes); | ||||
} | } | ||||
return $where; | return $where; | ||||
} | } | ||||
protected function shouldGroupQueryResultRows() { | protected function shouldGroupQueryResultRows() { | ||||
if ($this->memberPHIDs || $this->watcherPHIDs || $this->nameTokens) { | if ($this->memberPHIDs || $this->watcherPHIDs || $this->nameTokens) { | ||||
return true; | return true; | ||||
} | } | ||||
return parent::shouldGroupQueryResultRows(); | return parent::shouldGroupQueryResultRows(); | ||||
} | } | ||||
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | ||||
$joins = parent::buildJoinClauseParts($conn); | $joins = parent::buildJoinClauseParts($conn); | ||||
if ($this->memberPHIDs !== null) { | if ($this->memberPHIDs !== null) { | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn, | $conn, | ||||
'JOIN %T e ON e.src = p.phid AND e.type = %d', | 'JOIN %T e ON e.src = project.phid AND e.type = %d', | ||||
PhabricatorEdgeConfig::TABLE_NAME_EDGE, | PhabricatorEdgeConfig::TABLE_NAME_EDGE, | ||||
PhabricatorProjectMaterializedMemberEdgeType::EDGECONST); | PhabricatorProjectMaterializedMemberEdgeType::EDGECONST); | ||||
} | } | ||||
if ($this->watcherPHIDs !== null) { | if ($this->watcherPHIDs !== null) { | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn, | $conn, | ||||
'JOIN %T w ON w.src = p.phid AND w.type = %d', | 'JOIN %T w ON w.src = project.phid AND w.type = %d', | ||||
PhabricatorEdgeConfig::TABLE_NAME_EDGE, | PhabricatorEdgeConfig::TABLE_NAME_EDGE, | ||||
PhabricatorObjectHasWatcherEdgeType::EDGECONST); | PhabricatorObjectHasWatcherEdgeType::EDGECONST); | ||||
} | } | ||||
if ($this->slugs !== null) { | if ($this->slugs !== null) { | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn, | $conn, | ||||
'JOIN %T slug on slug.projectPHID = p.phid', | 'JOIN %T slug on slug.projectPHID = project.phid', | ||||
id(new PhabricatorProjectSlug())->getTableName()); | id(new PhabricatorProjectSlug())->getTableName()); | ||||
} | } | ||||
if ($this->nameTokens !== null) { | if ($this->nameTokens !== null) { | ||||
$name_tokens = $this->getNameTokensForQuery($this->nameTokens); | $name_tokens = $this->getNameTokensForQuery($this->nameTokens); | ||||
foreach ($name_tokens as $key => $token) { | foreach ($name_tokens as $key => $token) { | ||||
$token_table = 'token_'.$key; | $token_table = 'token_'.$key; | ||||
$joins[] = qsprintf( | $joins[] = qsprintf( | ||||
$conn, | $conn, | ||||
'JOIN %T %T ON %T.projectID = p.id AND %T.token LIKE %>', | 'JOIN %T %T ON %T.projectID = project.id AND %T.token LIKE %>', | ||||
PhabricatorProject::TABLE_DATASOURCE_TOKEN, | PhabricatorProject::TABLE_DATASOURCE_TOKEN, | ||||
$token_table, | $token_table, | ||||
$token_table, | $token_table, | ||||
$token_table, | $token_table, | ||||
$token); | $token); | ||||
} | } | ||||
} | } | ||||
return $joins; | return $joins; | ||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorProjectApplication'; | return 'PhabricatorProjectApplication'; | ||||
} | } | ||||
protected function getPrimaryTableAlias() { | protected function getPrimaryTableAlias() { | ||||
return 'p'; | return 'project'; | ||||
} | } | ||||
private function linkProjectGraph(array $projects, array $ancestors) { | private function linkProjectGraph(array $projects, array $ancestors) { | ||||
$ancestor_map = mpull($ancestors, null, 'getPHID'); | $ancestor_map = mpull($ancestors, null, 'getPHID'); | ||||
$projects_map = mpull($projects, null, 'getPHID'); | $projects_map = mpull($projects, null, 'getPHID'); | ||||
$all_map = $projects_map + $ancestor_map; | $all_map = $projects_map + $ancestor_map; | ||||
▲ Show 20 Lines • Show All 177 Lines • Show Last 20 Lines |