mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-04 20:01:00 +01:00
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
This commit is contained in:
parent
be4024c9c2
commit
79abe6653e
7 changed files with 57 additions and 34 deletions
|
@ -176,11 +176,26 @@ final class PhabricatorRepositoryPullLocalDaemon
|
||||||
* @task pull
|
* @task pull
|
||||||
*/
|
*/
|
||||||
protected function loadRepositories(array $names) {
|
protected function loadRepositories(array $names) {
|
||||||
if (!count($names)) {
|
$query = id(new PhabricatorRepositoryQuery())
|
||||||
return id(new PhabricatorRepository())->loadAll();
|
->setViewer($this->getViewer());
|
||||||
} else {
|
|
||||||
return PhabricatorRepository::loadAllByPHIDOrCallsign($names);
|
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) {
|
public function discoverRepository(PhabricatorRepository $repository) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementDeleteWorkflow
|
||||||
$this
|
$this
|
||||||
->setName('delete')
|
->setName('delete')
|
||||||
->setExamples('**delete** __repository__ ...')
|
->setExamples('**delete** __repository__ ...')
|
||||||
->setSynopsis('Delete __repository__, named by callsign or PHID.')
|
->setSynopsis('Delete __repository__, named by callsign.')
|
||||||
->setArguments(
|
->setArguments(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -22,12 +22,11 @@ final class PhabricatorRepositoryManagementDeleteWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$names = $args->getArg('repos');
|
$repos = $this->loadRepositories($args, 'repos');
|
||||||
$repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names);
|
|
||||||
|
|
||||||
if (!$repos) {
|
if (!$repos) {
|
||||||
throw new PhutilArgumentUsageException(
|
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();
|
$console = PhutilConsole::getConsole();
|
||||||
|
|
|
@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow
|
||||||
$this
|
$this
|
||||||
->setName('discover')
|
->setName('discover')
|
||||||
->setExamples('**discover** [__options__] __repository__ ...')
|
->setExamples('**discover** [__options__] __repository__ ...')
|
||||||
->setSynopsis('Discover __repository__, named by callsign or PHID.')
|
->setSynopsis('Discover __repository__, named by callsign.')
|
||||||
->setArguments(
|
->setArguments(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -27,12 +27,11 @@ final class PhabricatorRepositoryManagementDiscoverWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$names = $args->getArg('repos');
|
$repos = $this->loadRepositories($args, 'repos');
|
||||||
$repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names);
|
|
||||||
|
|
||||||
if (!$repos) {
|
if (!$repos) {
|
||||||
throw new PhutilArgumentUsageException(
|
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();
|
$console = PhutilConsole::getConsole();
|
||||||
|
|
|
@ -7,7 +7,7 @@ final class PhabricatorRepositoryManagementPullWorkflow
|
||||||
$this
|
$this
|
||||||
->setName('pull')
|
->setName('pull')
|
||||||
->setExamples('**pull** __repository__ ...')
|
->setExamples('**pull** __repository__ ...')
|
||||||
->setSynopsis('Pull __repository__, named by callsign or PHID.')
|
->setSynopsis('Pull __repository__, named by callsign.')
|
||||||
->setArguments(
|
->setArguments(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
|
@ -22,12 +22,11 @@ final class PhabricatorRepositoryManagementPullWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$names = $args->getArg('repos');
|
$repos = $this->loadRepositories($args, 'repos');
|
||||||
$repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names);
|
|
||||||
|
|
||||||
if (!$repos) {
|
if (!$repos) {
|
||||||
throw new PhutilArgumentUsageException(
|
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();
|
$console = PhutilConsole::getConsole();
|
||||||
|
|
|
@ -7,4 +7,28 @@ abstract class PhabricatorRepositoryManagementWorkflow
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -451,24 +451,6 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
||||||
return 'r'.$this->getCallsign().$short_identifier;
|
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 )------------------------------------------ */
|
/* -( Repository URI Management )------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,9 @@ abstract class PhabricatorDaemon extends PhutilDaemon {
|
||||||
LiskDAO::closeAllConnections();
|
LiskDAO::closeAllConnections();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getViewer() {
|
||||||
|
return PhabricatorUser::getOmnipotentUser();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue