diff --git a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php index f4c96b09c9..503b4a7bc0 100644 --- a/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php +++ b/src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php @@ -176,11 +176,26 @@ final class PhabricatorRepositoryPullLocalDaemon * @task pull */ protected function loadRepositories(array $names) { - if (!count($names)) { - return id(new PhabricatorRepository())->loadAll(); - } else { - return PhabricatorRepository::loadAllByPHIDOrCallsign($names); + $query = id(new PhabricatorRepositoryQuery()) + ->setViewer($this->getViewer()); + + if ($names) { + $query->withCallsigns($names); } + + $repos = $query->execute(); + + if ($names) { + $by_callsign = mpull($repos, null, 'getCallsign'); + foreach ($names as $name) { + if (empty($by_callsign[$name])) { + throw new Exception( + "No repository exists with callsign '{$name}'!"); + } + } + } + + return $repos; } public function discoverRepository(PhabricatorRepository $repository) { diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php index 3f19697165..111bd6e100 100644 --- a/src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php @@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementDeleteWorkflow $this ->setName('delete') ->setExamples('**delete** __repository__ ...') - ->setSynopsis('Delete __repository__, named by callsign or PHID.') + ->setSynopsis('Delete __repository__, named by callsign.') ->setArguments( array( array( @@ -22,12 +22,11 @@ final class PhabricatorRepositoryManagementDeleteWorkflow } public function execute(PhutilArgumentParser $args) { - $names = $args->getArg('repos'); - $repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names); + $repos = $this->loadRepositories($args, 'repos'); if (!$repos) { throw new PhutilArgumentUsageException( - "Specify one or more repositories to delete, by callsign or PHID."); + "Specify one or more repositories to delete, by callsign."); } $console = PhutilConsole::getConsole(); diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php index f77ea47b50..8a6067dadd 100644 --- a/src/applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php @@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow $this ->setName('discover') ->setExamples('**discover** [__options__] __repository__ ...') - ->setSynopsis('Discover __repository__, named by callsign or PHID.') + ->setSynopsis('Discover __repository__, named by callsign.') ->setArguments( array( array( @@ -27,12 +27,11 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow } public function execute(PhutilArgumentParser $args) { - $names = $args->getArg('repos'); - $repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names); + $repos = $this->loadRepositories($args, 'repos'); if (!$repos) { throw new PhutilArgumentUsageException( - "Specify one or more repositories to discover, by callsign or PHID."); + "Specify one or more repositories to discover, by callsign."); } $console = PhutilConsole::getConsole(); diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php index b3149503f4..5945e4c35e 100644 --- a/src/applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php @@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementPullWorkflow $this ->setName('pull') ->setExamples('**pull** __repository__ ...') - ->setSynopsis('Pull __repository__, named by callsign or PHID.') + ->setSynopsis('Pull __repository__, named by callsign.') ->setArguments( array( array( @@ -22,12 +22,11 @@ final class PhabricatorRepositoryManagementPullWorkflow } public function execute(PhutilArgumentParser $args) { - $names = $args->getArg('repos'); - $repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names); + $repos = $this->loadRepositories($args, 'repos'); if (!$repos) { throw new PhutilArgumentUsageException( - "Specify one or more repositories to pull, by callsign or PHID."); + "Specify one or more repositories to pull, by callsign."); } $console = PhutilConsole::getConsole(); diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementWorkflow.php index 4c85e8d49a..e6192906ff 100644 --- a/src/applications/repository/management/PhabricatorRepositoryManagementWorkflow.php +++ b/src/applications/repository/management/PhabricatorRepositoryManagementWorkflow.php @@ -7,4 +7,28 @@ abstract class PhabricatorRepositoryManagementWorkflow return true; } + protected function loadRepositories(PhutilArgumentParser $args, $param) { + $callsigns = $args->getArg($param); + + if (!$callsigns) { + return null; + } + + $repos = id(new PhabricatorRepositoryQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withCallsigns($callsigns) + ->execute(); + + $repos = mpull($repos, null, 'getCallsign'); + foreach ($callsigns as $callsign) { + if (empty($repos[$callsign])) { + throw new PhutilArgumentUsageException( + "No repository with callsign '{$callsign}' exists!"); + } + } + + return $repos; + } + + } diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 7a5df61611..e6b0225189 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -451,24 +451,6 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO return 'r'.$this->getCallsign().$short_identifier; } - public static function loadAllByPHIDOrCallsign(array $names) { - // TODO: (T603) Get rid of this. - - $repositories = array(); - foreach ($names as $name) { - $repo = id(new PhabricatorRepository())->loadOneWhere( - 'phid = %s OR callsign = %s', - $name, - $name); - if (!$repo) { - throw new Exception( - "No repository with PHID or callsign '{$name}' exists!"); - } - $repositories[$repo->getID()] = $repo; - } - return $repositories; - } - /* -( Repository URI Management )------------------------------------------ */ diff --git a/src/infrastructure/daemon/PhabricatorDaemon.php b/src/infrastructure/daemon/PhabricatorDaemon.php index 8a82da76ed..b68518b07d 100644 --- a/src/infrastructure/daemon/PhabricatorDaemon.php +++ b/src/infrastructure/daemon/PhabricatorDaemon.php @@ -14,4 +14,9 @@ abstract class PhabricatorDaemon extends PhutilDaemon { LiskDAO::closeAllConnections(); return; } + + public function getViewer() { + return PhabricatorUser::getOmnipotentUser(); + } + }