@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove PhabricatorRepository::loadAllByPHIDOrCallsign()

Summary: Ref T603. Move to real Query classes.

Test Plan:
- Ran `phd debug pull X` (where `X` does not match a repository).
- Ran `phd debug pull Y` (where `Y` does match a repository).
- Ran `phd debug pull`.
- Ran `repository pull`.
- Ran `repository pull X`.
- Ran `repository pull Y`.
- Ran `repository discover`.
- Ran `repository delete`.
- Ran `grep`.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7137

+57 -34
+19 -4
src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
··· 176 176 * @task pull 177 177 */ 178 178 protected function loadRepositories(array $names) { 179 - if (!count($names)) { 180 - return id(new PhabricatorRepository())->loadAll(); 181 - } else { 182 - return PhabricatorRepository::loadAllByPHIDOrCallsign($names); 179 + $query = id(new PhabricatorRepositoryQuery()) 180 + ->setViewer($this->getViewer()); 181 + 182 + if ($names) { 183 + $query->withCallsigns($names); 184 + } 185 + 186 + $repos = $query->execute(); 187 + 188 + if ($names) { 189 + $by_callsign = mpull($repos, null, 'getCallsign'); 190 + foreach ($names as $name) { 191 + if (empty($by_callsign[$name])) { 192 + throw new Exception( 193 + "No repository exists with callsign '{$name}'!"); 194 + } 195 + } 183 196 } 197 + 198 + return $repos; 184 199 } 185 200 186 201 public function discoverRepository(PhabricatorRepository $repository) {
+3 -4
src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php
··· 7 7 $this 8 8 ->setName('delete') 9 9 ->setExamples('**delete** __repository__ ...') 10 - ->setSynopsis('Delete __repository__, named by callsign or PHID.') 10 + ->setSynopsis('Delete __repository__, named by callsign.') 11 11 ->setArguments( 12 12 array( 13 13 array( ··· 22 22 } 23 23 24 24 public function execute(PhutilArgumentParser $args) { 25 - $names = $args->getArg('repos'); 26 - $repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names); 25 + $repos = $this->loadRepositories($args, 'repos'); 27 26 28 27 if (!$repos) { 29 28 throw new PhutilArgumentUsageException( 30 - "Specify one or more repositories to delete, by callsign or PHID."); 29 + "Specify one or more repositories to delete, by callsign."); 31 30 } 32 31 33 32 $console = PhutilConsole::getConsole();
+3 -4
src/applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php
··· 7 7 $this 8 8 ->setName('discover') 9 9 ->setExamples('**discover** [__options__] __repository__ ...') 10 - ->setSynopsis('Discover __repository__, named by callsign or PHID.') 10 + ->setSynopsis('Discover __repository__, named by callsign.') 11 11 ->setArguments( 12 12 array( 13 13 array( ··· 27 27 } 28 28 29 29 public function execute(PhutilArgumentParser $args) { 30 - $names = $args->getArg('repos'); 31 - $repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names); 30 + $repos = $this->loadRepositories($args, 'repos'); 32 31 33 32 if (!$repos) { 34 33 throw new PhutilArgumentUsageException( 35 - "Specify one or more repositories to discover, by callsign or PHID."); 34 + "Specify one or more repositories to discover, by callsign."); 36 35 } 37 36 38 37 $console = PhutilConsole::getConsole();
+3 -4
src/applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php
··· 7 7 $this 8 8 ->setName('pull') 9 9 ->setExamples('**pull** __repository__ ...') 10 - ->setSynopsis('Pull __repository__, named by callsign or PHID.') 10 + ->setSynopsis('Pull __repository__, named by callsign.') 11 11 ->setArguments( 12 12 array( 13 13 array( ··· 22 22 } 23 23 24 24 public function execute(PhutilArgumentParser $args) { 25 - $names = $args->getArg('repos'); 26 - $repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names); 25 + $repos = $this->loadRepositories($args, 'repos'); 27 26 28 27 if (!$repos) { 29 28 throw new PhutilArgumentUsageException( 30 - "Specify one or more repositories to pull, by callsign or PHID."); 29 + "Specify one or more repositories to pull, by callsign."); 31 30 } 32 31 33 32 $console = PhutilConsole::getConsole();
+24
src/applications/repository/management/PhabricatorRepositoryManagementWorkflow.php
··· 7 7 return true; 8 8 } 9 9 10 + protected function loadRepositories(PhutilArgumentParser $args, $param) { 11 + $callsigns = $args->getArg($param); 12 + 13 + if (!$callsigns) { 14 + return null; 15 + } 16 + 17 + $repos = id(new PhabricatorRepositoryQuery()) 18 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 19 + ->withCallsigns($callsigns) 20 + ->execute(); 21 + 22 + $repos = mpull($repos, null, 'getCallsign'); 23 + foreach ($callsigns as $callsign) { 24 + if (empty($repos[$callsign])) { 25 + throw new PhutilArgumentUsageException( 26 + "No repository with callsign '{$callsign}' exists!"); 27 + } 28 + } 29 + 30 + return $repos; 31 + } 32 + 33 + 10 34 }
-18
src/applications/repository/storage/PhabricatorRepository.php
··· 451 451 return 'r'.$this->getCallsign().$short_identifier; 452 452 } 453 453 454 - public static function loadAllByPHIDOrCallsign(array $names) { 455 - // TODO: (T603) Get rid of this. 456 - 457 - $repositories = array(); 458 - foreach ($names as $name) { 459 - $repo = id(new PhabricatorRepository())->loadOneWhere( 460 - 'phid = %s OR callsign = %s', 461 - $name, 462 - $name); 463 - if (!$repo) { 464 - throw new Exception( 465 - "No repository with PHID or callsign '{$name}' exists!"); 466 - } 467 - $repositories[$repo->getID()] = $repo; 468 - } 469 - return $repositories; 470 - } 471 - 472 454 /* -( Repository URI Management )------------------------------------------ */ 473 455 474 456
+5
src/infrastructure/daemon/PhabricatorDaemon.php
··· 14 14 LiskDAO::closeAllConnections(); 15 15 return; 16 16 } 17 + 18 + public function getViewer() { 19 + return PhabricatorUser::getOmnipotentUser(); 20 + } 21 + 17 22 }