34
34
35
35
use ArtificialOwl \MySmallPhpTools \Exceptions \SignatoryException ;
36
36
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 ;
39
38
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 ;
46
39
use OCA \Backup \Model \RestoringHealth ;
47
40
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 ;
51
43
use OCA \Backup \Service \RemoteStreamService ;
52
44
use Symfony \Component \Console \Helper \Table ;
53
45
use Symfony \Component \Console \Input \InputInterface ;
64
56
class PointList extends Base {
65
57
66
58
67
- use TArrayTools;
68
- use TNC23Deserialize;
59
+ use TStringTools;
69
60
70
61
71
- /** @var PointService */
72
- private $ pointService ;
62
+ /** @var CronService */
63
+ private $ cronService ;
73
64
74
- /** @var RemoteService */
75
- private $ remoteService ;
76
-
77
- /** @var ExternalFolderService */
78
- private $ externalFolderService ;
65
+ /** @var OutputService */
66
+ private $ outputService ;
79
67
80
68
/** @var RemoteStreamService */
81
69
private $ remoteStreamService ;
@@ -84,20 +72,17 @@ class PointList extends Base {
84
72
/**
85
73
* PointList constructor.
86
74
*
87
- * @param PointService $pointService
88
- * @param RemoteService $remoteService
89
- * @param ExternalFolderService $externalFolderService
75
+ * @param OutputService $outputService
76
+ * @param CronService $cronService
90
77
* @param RemoteStreamService $remoteStreamService
91
78
*/
92
79
public function __construct (
93
- PointService $ pointService ,
94
- RemoteService $ remoteService ,
95
- ExternalFolderService $ externalFolderService ,
80
+ OutputService $ outputService ,
81
+ CronService $ cronService ,
96
82
RemoteStreamService $ remoteStreamService
97
83
) {
98
- $ this ->pointService = $ pointService ;
99
- $ this ->remoteService = $ remoteService ;
100
- $ this ->externalFolderService = $ externalFolderService ;
84
+ $ this ->outputService = $ outputService ;
85
+ $ this ->cronService = $ cronService ;
101
86
$ this ->remoteStreamService = $ remoteStreamService ;
102
87
103
88
parent ::__construct ();
@@ -132,8 +117,8 @@ protected function configure() {
132
117
* @return int
133
118
*/
134
119
protected function execute (InputInterface $ input , OutputInterface $ output ): int {
135
- $ rp = $ this ->getRPFromInstances (
136
- $ output ,
120
+ $ this ->outputService -> setOutput ( $ output );
121
+ $ rp = $ this -> cronService -> getRPFromInstances (
137
122
$ input ->getOption ('local ' ),
138
123
$ input ->getOption ('remote ' ),
139
124
$ input ->getOption ('external ' )
@@ -151,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
151
136
foreach ($ rp as $ pointId => $ item ) {
152
137
$ fresh = true ;
153
138
foreach ($ item as $ instance => $ data ) {
154
- $ point = $ data ['rp ' ];
139
+ $ point = $ data ['point ' ];
155
140
$ issue = $ data ['issue ' ];
156
141
157
142
/** @var RestoringPoint $point */
@@ -199,122 +184,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
199
184
}
200
185
201
186
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
-
318
187
/**
319
188
* @param RestoringPoint $point
320
189
*
@@ -325,9 +194,10 @@ private function displayStyleHealth(RestoringPoint $point): string {
325
194
return 'not checked ' ;
326
195
}
327
196
328
- $ status = $ point ->getHealth ()->getStatus ();
329
197
$ embed = '' ;
330
- switch ($ status ) {
198
+ $ health = $ point ->getHealth ();
199
+ $ def = RestoringHealth::$ DEF [$ health ->getStatus ()];
200
+ switch ($ health ->getStatus ()) {
331
201
case RestoringHealth::STATUS_ISSUE :
332
202
$ embed = 'error ' ;
333
203
break ;
@@ -336,10 +206,12 @@ private function displayStyleHealth(RestoringPoint $point): string {
336
206
break ;
337
207
case RestoringHealth::STATUS_OK :
338
208
$ embed = 'info ' ;
209
+
210
+ $ def = $ this ->getDateDiff ($ health ->getChecked (), time (), true ) . ' ago ' ;
339
211
break ;
340
212
}
341
213
342
- return '< ' . $ embed . '> ' . RestoringHealth:: $ DEF [ $ status ] . '</ ' . $ embed . '> ' ;
214
+ return '< ' . $ embed . '> ' . $ def . '</ ' . $ embed . '> ' ;
343
215
}
344
216
345
217
}
0 commit comments