Skip to content

Commit 902691f

Browse files
committed
listing remote instances
1 parent b8165fd commit 902691f

File tree

5 files changed

+61
-7
lines changed

5 files changed

+61
-7
lines changed

lib/Command/RemoteList.php

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@
3232
namespace OCA\Backup\Command;
3333

3434

35+
use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException;
36+
use ArtificialOwl\MySmallPhpTools\Exceptions\SignatureException;
3537
use OC\Core\Command\Base;
38+
use OCA\Backup\Db\RemoteRequest;
39+
use OCA\Backup\Model\RemoteInstance;
40+
use OCA\Backup\Service\RemoteStreamService;
41+
use Symfony\Component\Console\Helper\Table;
3642
use Symfony\Component\Console\Input\InputInterface;
43+
use Symfony\Component\Console\Output\ConsoleOutput;
3744
use Symfony\Component\Console\Output\OutputInterface;
3845

3946

@@ -45,7 +52,16 @@
4552
class RemoteList extends Base {
4653

4754

48-
public function __construct() {
55+
/** @var RemoteRequest */
56+
private $remoteRequest;
57+
58+
/** @var RemoteStreamService */
59+
private $remoteStreamService;
60+
61+
62+
public function __construct(RemoteRequest $remoteRequest, RemoteStreamService $remoteStreamService) {
63+
$this->remoteRequest = $remoteRequest;
64+
$this->remoteStreamService = $remoteStreamService;
4965

5066
parent::__construct();
5167
}
@@ -67,10 +83,39 @@ protected function configure() {
6783
* @return int
6884
*/
6985
protected function execute(InputInterface $input, OutputInterface $output): int {
70-
86+
$output = new ConsoleOutput();
87+
$output = $output->section();
88+
$table = new Table($output);
89+
$table->setHeaders(
90+
['Address', 'Stored Uid', 'Current Uid', 'Href', 'Incoming data', 'Outgoing data']
91+
);
92+
$table->render();
93+
94+
foreach ($this->remoteRequest->getAll() as $remoteInstance) {
95+
96+
$color = 'error';
97+
/** @var RemoteInstance $current */
98+
try {
99+
$current = $this->remoteStreamService->retrieveSignatory($remoteInstance->getId());
100+
if ($remoteInstance->getUid(true) === $current->getUid(true)) {
101+
$color = 'info';
102+
}
103+
} catch (SignatoryException | SignatureException $e) {
104+
}
105+
106+
$table->appendRow(
107+
[
108+
$remoteInstance->getInstance(),
109+
$remoteInstance->getUid(true),
110+
'<' . $color . '>' . $current->getUid(true) . '</' . $color . '>',
111+
$remoteInstance->getId(),
112+
($remoteInstance->isIncoming() ? '<info>yes</info>' : '<comment>no</comment'),
113+
($remoteInstance->isOutgoing() ? '<info>yes</info>' : '<comment>no</comment')
114+
]
115+
);
116+
}
71117

72118
return 0;
73119
}
74120

75121
}
76-

lib/Db/RemoteRequest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ public function update(RemoteInstance $remote) {
8585
}
8686

8787

88+
/**
89+
* @return RemoteInstance[]
90+
*/
91+
public function getAll(): array {
92+
$qb = $this->getRemoteSelectSql();
93+
94+
return $this->getItemsFromRequest($qb);
95+
}
96+
97+
8898
/**
8999
* @param int $dbId
90100
*
@@ -137,6 +147,5 @@ public function insertOrUpdate(RemoteInstance $remoteInstance): void {
137147
}
138148
}
139149

140-
141150
}
142151

lib/Handlers/WebfingerHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
/**
4949
* Class WebfingerHandler
5050
*
51-
* @package OCA\Circles\Handlers
51+
* @package OCA\Backup\Handlers
5252
*/
5353
class WebfingerHandler implements IHandler {
5454

lib/Model/RemoteInstance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
/**
4444
* Class AppService
4545
*
46-
* @package OCA\Circles\Model
46+
* @package OCA\Backup\Model
4747
*/
4848
class RemoteInstance extends NC23Signatory implements INC22QueryRow, JsonSerializable {
4949

lib/Service/RemoteStreamService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function getAppSignatory(bool $generate = true, string $confirmKey = ''):
122122

123123

124124
/**
125-
* Reset the Signatory (and the Identity) for the Circles app.
125+
*
126126
*/
127127
public function resetAppSignatory(): void {
128128
try {

0 commit comments

Comments
 (0)