Skip to content

Commit 79abe66

Browse files
author
epriestley
committed
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
1 parent be4024c commit 79abe66

File tree

7 files changed

+57
-34
lines changed

7 files changed

+57
-34
lines changed

src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,26 @@ public function run() {
176176
* @task pull
177177
*/
178178
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+
}
183196
}
197+
198+
return $repos;
184199
}
185200

186201
public function discoverRepository(PhabricatorRepository $repository) {

src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public function didConstruct() {
77
$this
88
->setName('delete')
99
->setExamples('**delete** __repository__ ...')
10-
->setSynopsis('Delete __repository__, named by callsign or PHID.')
10+
->setSynopsis('Delete __repository__, named by callsign.')
1111
->setArguments(
1212
array(
1313
array(
@@ -22,12 +22,11 @@ public function didConstruct() {
2222
}
2323

2424
public function execute(PhutilArgumentParser $args) {
25-
$names = $args->getArg('repos');
26-
$repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names);
25+
$repos = $this->loadRepositories($args, 'repos');
2726

2827
if (!$repos) {
2928
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.");
3130
}
3231

3332
$console = PhutilConsole::getConsole();

src/applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public function didConstruct() {
77
$this
88
->setName('discover')
99
->setExamples('**discover** [__options__] __repository__ ...')
10-
->setSynopsis('Discover __repository__, named by callsign or PHID.')
10+
->setSynopsis('Discover __repository__, named by callsign.')
1111
->setArguments(
1212
array(
1313
array(
@@ -27,12 +27,11 @@ public function didConstruct() {
2727
}
2828

2929
public function execute(PhutilArgumentParser $args) {
30-
$names = $args->getArg('repos');
31-
$repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names);
30+
$repos = $this->loadRepositories($args, 'repos');
3231

3332
if (!$repos) {
3433
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.");
3635
}
3736

3837
$console = PhutilConsole::getConsole();

src/applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public function didConstruct() {
77
$this
88
->setName('pull')
99
->setExamples('**pull** __repository__ ...')
10-
->setSynopsis('Pull __repository__, named by callsign or PHID.')
10+
->setSynopsis('Pull __repository__, named by callsign.')
1111
->setArguments(
1212
array(
1313
array(
@@ -22,12 +22,11 @@ public function didConstruct() {
2222
}
2323

2424
public function execute(PhutilArgumentParser $args) {
25-
$names = $args->getArg('repos');
26-
$repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names);
25+
$repos = $this->loadRepositories($args, 'repos');
2726

2827
if (!$repos) {
2928
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.");
3130
}
3231

3332
$console = PhutilConsole::getConsole();

src/applications/repository/management/PhabricatorRepositoryManagementWorkflow.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,28 @@ public function isExecutable() {
77
return true;
88
}
99

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+
1034
}

src/applications/repository/storage/PhabricatorRepository.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -451,24 +451,6 @@ public function formatCommitName($commit_identifier) {
451451
return 'r'.$this->getCallsign().$short_identifier;
452452
}
453453

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-
472454
/* -( Repository URI Management )------------------------------------------ */
473455

474456

src/infrastructure/daemon/PhabricatorDaemon.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ protected function willSleep($duration) {
1414
LiskDAO::closeAllConnections();
1515
return;
1616
}
17+
18+
public function getViewer() {
19+
return PhabricatorUser::getOmnipotentUser();
20+
}
21+
1722
}

0 commit comments

Comments
 (0)