Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/query/DiffusionSymbolQuery.php
| Show All 10 Lines | |||||
| */ | */ | ||||
| final class DiffusionSymbolQuery extends PhabricatorOffsetPagedQuery { | final class DiffusionSymbolQuery extends PhabricatorOffsetPagedQuery { | ||||
| private $viewer; | private $viewer; | ||||
| private $context; | private $context; | ||||
| private $namePrefix; | private $namePrefix; | ||||
| private $name; | private $name; | ||||
| private $projectIDs; | private $repositoryPHIDs; | ||||
| private $language; | private $language; | ||||
| private $type; | private $type; | ||||
| private $needPaths; | private $needPaths; | ||||
| private $needArcanistProject; | |||||
| private $needRepositories; | private $needRepositories; | ||||
| /* -( Configuring the Query )---------------------------------------------- */ | /* -( Configuring the Query )---------------------------------------------- */ | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| Show All 34 Lines | public function setNamePrefix($name_prefix) { | ||||
| $this->namePrefix = $name_prefix; | $this->namePrefix = $name_prefix; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function setProjectIDs(array $project_ids) { | public function withRepositoryPHIDs(array $repository_phids) { | ||||
| $this->projectIDs = $project_ids; | $this->repositoryPHIDs = $repository_phids; | ||||
epriestley: Maybe modernize to `with...` while the method name is changing anyway. | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function setLanguage($language) { | public function setLanguage($language) { | ||||
| Show All 18 Lines | public function needPaths($need_paths) { | ||||
| $this->needPaths = $need_paths; | $this->needPaths = $need_paths; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * @task config | * @task config | ||||
| */ | */ | ||||
| public function needArcanistProjects($need_arcanist_projects) { | |||||
| $this->needArcanistProjects = $need_arcanist_projects; | |||||
| return $this; | |||||
| } | |||||
| /** | |||||
| * @task config | |||||
| */ | |||||
| public function needRepositories($need_repositories) { | public function needRepositories($need_repositories) { | ||||
| $this->needRepositories = $need_repositories; | $this->needRepositories = $need_repositories; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /* -( Executing the Query )------------------------------------------------ */ | /* -( Executing the Query )------------------------------------------------ */ | ||||
| /** | /** | ||||
| * @task exec | * @task exec | ||||
| */ | */ | ||||
| public function execute() { | public function execute() { | ||||
| if ($this->name && $this->namePrefix) { | if ($this->name && $this->namePrefix) { | ||||
| throw new Exception( | throw new Exception( | ||||
| 'You can not set both a name and a name prefix!'); | pht('You can not set both a name and a name prefix!')); | ||||
| } else if (!$this->name && !$this->namePrefix) { | } else if (!$this->name && !$this->namePrefix) { | ||||
| throw new Exception( | throw new Exception( | ||||
| 'You must set a name or a name prefix!'); | pht('You must set a name or a name prefix!')); | ||||
| } | } | ||||
| $symbol = new PhabricatorRepositorySymbol(); | $symbol = new PhabricatorRepositorySymbol(); | ||||
| $conn_r = $symbol->establishConnection('r'); | $conn_r = $symbol->establishConnection('r'); | ||||
| $data = queryfx_all( | $data = queryfx_all( | ||||
| $conn_r, | $conn_r, | ||||
| 'SELECT * FROM %T %Q %Q %Q', | 'SELECT * FROM %T %Q %Q %Q', | ||||
| $symbol->getTableName(), | $symbol->getTableName(), | ||||
| $this->buildWhereClause($conn_r), | $this->buildWhereClause($conn_r), | ||||
| $this->buildOrderClause($conn_r), | $this->buildOrderClause($conn_r), | ||||
| $this->buildLimitClause($conn_r)); | $this->buildLimitClause($conn_r)); | ||||
| $symbols = $symbol->loadAllFromArray($data); | $symbols = $symbol->loadAllFromArray($data); | ||||
| if ($symbols) { | if ($symbols) { | ||||
| if ($this->needPaths) { | if ($this->needPaths) { | ||||
| $this->loadPaths($symbols); | $this->loadPaths($symbols); | ||||
| } | } | ||||
| if ($this->needArcanistProjects || $this->needRepositories) { | |||||
| $this->loadArcanistProjects($symbols); | |||||
| } | |||||
| if ($this->needRepositories) { | if ($this->needRepositories) { | ||||
| $this->loadRepositories($symbols); | $this->loadRepositories($symbols); | ||||
| } | } | ||||
| } | } | ||||
| return $symbols; | return $symbols; | ||||
| } | } | ||||
| Show All 34 Lines | protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
| if ($this->namePrefix) { | if ($this->namePrefix) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'symbolName LIKE %>', | 'symbolName LIKE %>', | ||||
| $this->namePrefix); | $this->namePrefix); | ||||
| } | } | ||||
| if ($this->projectIDs) { | if ($this->repositoryPHIDs) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'arcanistProjectID IN (%Ld)', | 'repositoryPHID IN (%Ls)', | ||||
| $this->projectIDs); | $this->repositoryPHIDs); | ||||
| } | } | ||||
| if ($this->language) { | if ($this->language) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'symbolLanguage = %s', | 'symbolLanguage = %s', | ||||
| $this->language); | $this->language); | ||||
| } | } | ||||
| Show All 24 Lines | foreach ($symbols as $symbol) { | ||||
| $symbol->attachPath(idx($path_map, $symbol->getPathID())); | $symbol->attachPath(idx($path_map, $symbol->getPathID())); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * @task internal | * @task internal | ||||
| */ | */ | ||||
| private function loadArcanistProjects(array $symbols) { | |||||
| assert_instances_of($symbols, 'PhabricatorRepositorySymbol'); | |||||
| $projects = id(new PhabricatorRepositoryArcanistProject())->loadAllWhere( | |||||
| 'id IN (%Ld)', | |||||
| mpull($symbols, 'getArcanistProjectID')); | |||||
| foreach ($symbols as $symbol) { | |||||
| $project = idx($projects, $symbol->getArcanistProjectID()); | |||||
| $symbol->attachArcanistProject($project); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * @task internal | |||||
| */ | |||||
| private function loadRepositories(array $symbols) { | private function loadRepositories(array $symbols) { | ||||
| assert_instances_of($symbols, 'PhabricatorRepositorySymbol'); | assert_instances_of($symbols, 'PhabricatorRepositorySymbol'); | ||||
| $projects = mpull($symbols, 'getArcanistProject'); | |||||
| $projects = array_filter($projects); | |||||
| $repo_ids = mpull($projects, 'getRepositoryID'); | |||||
| $repo_ids = array_filter($repo_ids); | |||||
| if ($repo_ids) { | |||||
| $repos = id(new PhabricatorRepositoryQuery()) | $repos = id(new PhabricatorRepositoryQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->viewer) | ||||
| ->withIDs($repo_ids) | ->withPHIDs(mpull($symbols, 'getRepositoryPHID')) | ||||
| ->execute(); | ->execute(); | ||||
| } else { | $repos = mpull($repos, null, 'getPHID'); | ||||
| $repos = array(); | |||||
| } | |||||
Done Inline ActionsShould be RepositoryQuery epriestley: Should be RepositoryQuery | |||||
| foreach ($symbols as $symbol) { | foreach ($symbols as $symbol) { | ||||
| $proj = $symbol->getArcanistProject(); | $repository = idx($repos, $symbol->getRepositoryPHID()); | ||||
| if ($proj) { | $symbol->attachRepository($repository); | ||||
| $symbol->attachRepository(idx($repos, $proj->getRepositoryID())); | |||||
| } else { | |||||
| $symbol->attachRepository(null); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
Maybe modernize to with... while the method name is changing anyway.