Skip to content

Commit 516cf86

Browse files
committed
returns RPs on ocs request
1 parent 1a8bd2e commit 516cf86

File tree

6 files changed

+196
-170
lines changed

6 files changed

+196
-170
lines changed

appinfo/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'ocs' => [
66
['name' => 'Local#getSettings', 'url' => '/settings', 'verb' => 'GET'],
77
['name' => 'Local#setSettings', 'url' => '/settings', 'verb' => 'PUT'],
8-
['name' => 'Local#getRestoringPoint', 'url' => '/rp', 'verb' => 'GET'],
8+
['name' => 'Local#getRestoringPoints', 'url' => '/rp', 'verb' => 'GET'],
99
['name' => 'Local#getExternalFolder', 'url' => '/external', 'verb' => 'GET'],
1010
['name' => 'Local#setExternalFolder', 'url' => '/external', 'verb' => 'POST'],
1111
['name' => 'Local#initAction', 'url' => '/action/{type}/{param}', 'verb' => 'POST']

lib/Command/ExternalAdd.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,6 @@ protected function configure() {
105105
* @return int
106106
*/
107107
protected function execute(InputInterface $input, OutputInterface $output): int {
108-
109-
110-
// $storages = array_map(function (StorageConfig $storageConfig) use ($user) {
111-
// try {
112-
// $this->prepareStorageConfig($storageConfig, $user);
113-
// return $this->constructStorage($storageConfig);
114-
// } catch (\Exception $e) {
115-
// // propagate exception into filesystem
116-
// return new FailedStorage(['exception' => $e]);
117-
// }
118-
// }, $storageConfigs);
119-
120-
121108
$storageId = (int)$input->getArgument('storage_id');
122109
$root = $input->getArgument('root');
123110

lib/Command/PointList.php

Lines changed: 23 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,12 @@
3434

3535
use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException;
3636
use ArtificialOwl\MySmallPhpTools\Exceptions\SignatureException;
37-
use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc23\TNC23Deserialize;
38-
use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools;
37+
use ArtificialOwl\MySmallPhpTools\Traits\TStringTools;
3938
use OC\Core\Command\Base;
40-
use OCA\Backup\Exceptions\ExternalFolderNotFoundException;
41-
use OCA\Backup\Exceptions\RemoteInstanceException;
42-
use OCA\Backup\Exceptions\RemoteInstanceNotFoundException;
43-
use OCA\Backup\Exceptions\RemoteResourceNotFoundException;
44-
use OCA\Backup\Model\ExternalFolder;
45-
use OCA\Backup\Model\RemoteInstance;
4639
use OCA\Backup\Model\RestoringHealth;
4740
use OCA\Backup\Model\RestoringPoint;
48-
use OCA\Backup\Service\ExternalFolderService;
49-
use OCA\Backup\Service\PointService;
50-
use OCA\Backup\Service\RemoteService;
41+
use OCA\Backup\Service\CronService;
42+
use OCA\Backup\Service\OutputService;
5143
use OCA\Backup\Service\RemoteStreamService;
5244
use Symfony\Component\Console\Helper\Table;
5345
use Symfony\Component\Console\Input\InputInterface;
@@ -64,18 +56,14 @@
6456
class PointList extends Base {
6557

6658

67-
use TArrayTools;
68-
use TNC23Deserialize;
59+
use TStringTools;
6960

7061

71-
/** @var PointService */
72-
private $pointService;
62+
/** @var CronService */
63+
private $cronService;
7364

74-
/** @var RemoteService */
75-
private $remoteService;
76-
77-
/** @var ExternalFolderService */
78-
private $externalFolderService;
65+
/** @var OutputService */
66+
private $outputService;
7967

8068
/** @var RemoteStreamService */
8169
private $remoteStreamService;
@@ -84,20 +72,17 @@ class PointList extends Base {
8472
/**
8573
* PointList constructor.
8674
*
87-
* @param PointService $pointService
88-
* @param RemoteService $remoteService
89-
* @param ExternalFolderService $externalFolderService
75+
* @param OutputService $outputService
76+
* @param CronService $cronService
9077
* @param RemoteStreamService $remoteStreamService
9178
*/
9279
public function __construct(
93-
PointService $pointService,
94-
RemoteService $remoteService,
95-
ExternalFolderService $externalFolderService,
80+
OutputService $outputService,
81+
CronService $cronService,
9682
RemoteStreamService $remoteStreamService
9783
) {
98-
$this->pointService = $pointService;
99-
$this->remoteService = $remoteService;
100-
$this->externalFolderService = $externalFolderService;
84+
$this->outputService = $outputService;
85+
$this->cronService = $cronService;
10186
$this->remoteStreamService = $remoteStreamService;
10287

10388
parent::__construct();
@@ -132,8 +117,8 @@ protected function configure() {
132117
* @return int
133118
*/
134119
protected function execute(InputInterface $input, OutputInterface $output): int {
135-
$rp = $this->getRPFromInstances(
136-
$output,
120+
$this->outputService->setOutput($output);
121+
$rp = $this->cronService->getRPFromInstances(
137122
$input->getOption('local'),
138123
$input->getOption('remote'),
139124
$input->getOption('external')
@@ -151,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
151136
foreach ($rp as $pointId => $item) {
152137
$fresh = true;
153138
foreach ($item as $instance => $data) {
154-
$point = $data['rp'];
139+
$point = $data['point'];
155140
$issue = $data['issue'];
156141

157142
/** @var RestoringPoint $point */
@@ -199,122 +184,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
199184
}
200185

201186

202-
/**
203-
* @param OutputInterface $output
204-
* @param bool $local
205-
* @param string $remote
206-
* @param string $external
207-
*
208-
* @return array
209-
*/
210-
private function getRPFromInstances(
211-
OutputInterface $output,
212-
bool $local,
213-
string $remote,
214-
string $external
215-
): array {
216-
if ($local) {
217-
$instances = [RemoteInstance::LOCAL];
218-
} else if ($remote !== '') {
219-
$instances = ['remote:' . $remote];
220-
} else if ($external !== '') {
221-
$instances = ['external:' . $external];
222-
} else {
223-
$instances = array_merge(
224-
[RemoteInstance::LOCAL],
225-
array_map(
226-
function (RemoteInstance $remoteInstance): string {
227-
return 'remote:' . $remoteInstance->getInstance();
228-
}, $this->remoteService->getOutgoing()
229-
),
230-
array_map(
231-
function (ExternalFolder $externalFolder): string {
232-
return 'external:' . $externalFolder->getStorageId();
233-
}, $this->externalFolderService->getAll()
234-
)
235-
);
236-
}
237-
238-
$points = $dates = [];
239-
foreach ($instances as $instance) {
240-
$output->writeln('- retreiving data from <info>' . $instance . '</info>');
241-
242-
$list = [];
243-
try {
244-
if ($instance === RemoteInstance::LOCAL) {
245-
$list = $this->pointService->getLocalRestoringPoints();
246-
} else {
247-
248-
[$source, $id] = explode(':', $instance, 2);
249-
if ($source === 'remote') {
250-
$list = $this->remoteService->getRestoringPoints($id);
251-
} else if ($source === 'external') {
252-
try {
253-
$external = $this->externalFolderService->getByStorageId((int)$id);
254-
$list = $this->externalFolderService->getRestoringPoints($external);
255-
} catch (ExternalFolderNotFoundException $e) {
256-
}
257-
}
258-
}
259-
} catch (RemoteInstanceException
260-
| RemoteInstanceNotFoundException
261-
| RemoteResourceNotFoundException $e) {
262-
continue;
263-
}
264-
265-
foreach ($list as $item) {
266-
$output->writeln(' > found RestoringPoint <info>' . $item->getId() . '</info>');
267-
if (!array_key_exists($item->getId(), $points)) {
268-
$points[$item->getId()] = [];
269-
}
270-
271-
$issue = '';
272-
if ($instance !== RemoteInstance::LOCAL) {
273-
$storedDate = $this->getInt($item->getId(), $dates);
274-
if ($storedDate > 0 && $storedDate !== $item->getDate()) {
275-
$output->writeln(' <error>! different date</error>');
276-
$issue = 'different date';
277-
}
278-
279-
try {
280-
$this->remoteStreamService->verifyPoint($item);
281-
} catch (SignatoryException | SignatureException $e) {
282-
$output->writeln(' <error>! cannot confirm integrity</error>');
283-
$issue = 'cannot confirm integrity';
284-
}
285-
}
286-
287-
$points[$item->getId()][$instance] = [
288-
'rp' => $item,
289-
'issue' => $issue
290-
];
291-
292-
$dates[$item->getId()] = $item->getDate();
293-
}
294-
}
295-
296-
return $this->orderByDate($points, $dates);
297-
}
298-
299-
300-
/**
301-
* @param array $points
302-
* @param array $dates
303-
*
304-
* @return array
305-
*/
306-
private function orderByDate(array $points, array $dates): array {
307-
asort($dates);
308-
309-
$result = [];
310-
foreach ($dates as $pointId => $date) {
311-
$result[$pointId] = $points[$pointId];
312-
}
313-
314-
return $result;
315-
}
316-
317-
318187
/**
319188
* @param RestoringPoint $point
320189
*
@@ -325,9 +194,10 @@ private function displayStyleHealth(RestoringPoint $point): string {
325194
return 'not checked';
326195
}
327196

328-
$status = $point->getHealth()->getStatus();
329197
$embed = '';
330-
switch ($status) {
198+
$health = $point->getHealth();
199+
$def = RestoringHealth::$DEF[$health->getStatus()];
200+
switch ($health->getStatus()) {
331201
case RestoringHealth::STATUS_ISSUE:
332202
$embed = 'error';
333203
break;
@@ -336,10 +206,12 @@ private function displayStyleHealth(RestoringPoint $point): string {
336206
break;
337207
case RestoringHealth::STATUS_OK:
338208
$embed = 'info';
209+
210+
$def = $this->getDateDiff($health->getChecked(), time(), true) . ' ago';
339211
break;
340212
}
341213

342-
return '<' . $embed . '>' . RestoringHealth::$DEF[$status] . '</' . $embed . '>';
214+
return '<' . $embed . '>' . $def . '</' . $embed . '>';
343215
}
344216

345217
}

lib/Controller/LocalController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ public function initAction(string $type, string $param = ''): DataResponse {
150150
/**
151151
* @return DataResponse
152152
*/
153-
public function getRestoringPoint(): DataResponse {
154-
$points = $this->pointService->getLocalRestoringPoints();
155-
153+
public function getRestoringPoints(): DataResponse {
154+
$points =$this->cronService->getRPFromInstances();
156155
return new DataResponse($points);
157156
}
158157

0 commit comments

Comments
 (0)