1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace phpbu\App\Result; |
4
|
|
|
|
5
|
|
|
use phpbu\App\Cli\Statistics; |
6
|
|
|
use phpbu\App\Event; |
7
|
|
|
use phpbu\App\Listener; |
8
|
|
|
use phpbu\App\Result; |
9
|
|
|
use phpbu\App\Util; |
10
|
|
|
use SebastianBergmann\Environment\Console; |
11
|
|
|
use SebastianBergmann\Environment\Runtime; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Default app output. |
15
|
|
|
* |
16
|
|
|
* Heavily 'inspired' by Sebastian Bergmann's phpunit PHPUnit_TextUI_ResultPrinter. |
17
|
|
|
* |
18
|
|
|
* @package phpbu |
19
|
|
|
* @subpackage Result |
20
|
|
|
* @author Sebastian Feldmann <[email protected]> |
21
|
|
|
* @copyright Sebastian Feldmann <[email protected]> |
22
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
23
|
|
|
* @link http://phpbu.de/ |
24
|
|
|
* @since Class available since Release 1.0.0 |
25
|
|
|
*/ |
26
|
|
|
class PrinterCli implements Listener |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Verbose output |
30
|
|
|
* |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
protected $verbose = false; |
34
|
|
|
/** |
35
|
|
|
* Output with colors |
36
|
|
|
* |
37
|
|
|
* @var bool |
38
|
|
|
*/ |
39
|
|
|
protected $colors = false; |
40
|
|
|
/** |
41
|
|
|
* Is debug active |
42
|
|
|
* |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
protected $debug = false; |
46
|
|
|
/** |
47
|
|
|
* Amount of executed backups |
48
|
|
|
* |
49
|
|
|
* @var integer |
50
|
|
|
*/ |
51
|
|
|
private $numBackups = 0; |
52
|
|
|
/** |
53
|
|
|
* Amount of executed checks |
54
|
|
|
* |
55
|
|
|
* @var integer |
56
|
|
|
*/ |
57
|
|
|
private $numChecks = 0; |
58
|
|
|
/** |
59
|
|
|
* Amount of executed crypts |
60
|
|
|
* |
61
|
|
|
* @var integer |
62
|
|
|
*/ |
63
|
|
|
private $numCrypts = 0; |
64
|
|
|
/** |
65
|
|
|
* Amount of executed Syncs |
66
|
|
|
* |
67
|
|
|
* @var integer |
68
|
|
|
*/ |
69
|
|
|
private $numSyncs = 0; |
70
|
|
|
/** |
71
|
|
|
* Amount of executed Cleanups |
72
|
|
|
* |
73
|
|
|
* @var integer |
74
|
|
|
*/ |
75
|
|
|
private $numCleanups = 0; |
76
|
|
|
/** |
77
|
|
|
* Console |
78
|
|
|
* |
79
|
|
|
* @var \SebastianBergmann\Environment\Console |
80
|
|
|
*/ |
81
|
|
|
private $console; |
82
|
|
|
/** |
83
|
|
|
* PHP Runtime |
84
|
|
|
* |
85
|
|
|
* @var \SebastianBergmann\Environment\Runtime |
86
|
|
|
*/ |
87
|
|
|
private $runtime; |
88
|
|
|
/** |
89
|
|
|
* @var Event\Check\Failed[] |
90
|
|
|
*/ |
91
|
|
|
private $failedChecks; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Constructor |
95
|
|
|
* |
96
|
|
|
* @param bool $verbose |
97
|
|
|
* @param bool $colors |
98
|
|
|
* @param bool $debug |
99
|
|
|
* @throws \InvalidArgumentException |
100
|
|
|
*/ |
101
|
|
|
public function __construct(bool $verbose = false, bool $colors = false, bool $debug = false) |
102
|
|
|
{ |
103
|
|
|
$this->console = new Console; |
104
|
|
|
$this->runtime = new Runtime; |
105
|
|
|
$this->debug = $debug; |
106
|
|
|
$this->verbose = $verbose; |
107
|
|
|
$this->colors = $colors && $this->console->hasColorSupport(); |
108
|
|
|
} |
109
|
3 |
|
|
110
|
|
|
/** |
111
|
|
|
* Returns an array of event names this subscriber wants to listen to. |
112
|
3 |
|
* |
113
|
|
|
* The array keys are event names and the value can be: |
114
|
|
|
* |
115
|
|
|
* * The method name to call (priority defaults to 0) |
116
|
|
|
* * An array composed of the method name to call and the priority |
117
|
|
|
* * An array of arrays composed of the method names to call and respective |
118
|
|
|
* priorities, or 0 if unset |
119
|
|
|
* |
120
|
|
|
* @return array The event names to listen to |
121
|
|
|
*/ |
122
|
|
|
public static function getSubscribedEvents(): array |
123
|
|
|
{ |
124
|
|
|
return [ |
125
|
|
|
'phpbu.debug' => 'onDebug', |
126
|
|
|
'phpbu.warning' => 'onWarning', |
127
|
|
|
'phpbu.app_start' => 'onPhpbuStart', |
128
|
|
|
'phpbu.backup_start' => 'onBackupStart', |
129
|
|
|
'phpbu.backup_failed' => 'onBackupFailed', |
130
|
|
|
'phpbu.backup_end' => 'onBackupEnd', |
131
|
|
|
'phpbu.check_start' => 'onCheckStart', |
132
|
|
|
'phpbu.check_failed' => 'onCheckFailed', |
133
|
|
|
'phpbu.check_end' => 'onCheckEnd', |
134
|
|
|
'phpbu.crypt_start' => 'onCryptStart', |
135
|
|
|
'phpbu.crypt_skipped' => 'onCryptSkipped', |
136
|
|
|
'phpbu.crypt_failed' => 'onCryptFailed', |
137
|
|
|
'phpbu.crypt_end' => 'onCryptEnd', |
138
|
|
|
'phpbu.sync_start' => 'onSyncStart', |
139
|
|
|
'phpbu.sync_skipped' => 'onSyncSkipped', |
140
|
|
|
'phpbu.sync_failed' => 'onSyncFailed', |
141
|
|
|
'phpbu.sync_end' => 'onSyncEnd', |
142
|
|
|
'phpbu.cleanup_start' => 'onCleanupStart', |
143
|
|
|
'phpbu.cleanup_skipped' => 'onCleanupSkipped', |
144
|
29 |
|
'phpbu.cleanup_failed' => 'onCleanupFailed', |
145
|
|
|
'phpbu.cleanup_end' => 'onCleanupEnd', |
146
|
29 |
|
'phpbu.app_end' => 'onPhpbuEnd', |
147
|
29 |
|
]; |
148
|
29 |
|
} |
149
|
29 |
|
|
150
|
29 |
|
/** |
151
|
29 |
|
* phpbu start event. |
152
|
|
|
* |
153
|
|
|
* @param \phpbu\App\Event\App\Start $event |
154
|
|
|
*/ |
155
|
|
|
public function onPhpbuStart(Event\App\Start $event): void |
156
|
|
|
{ |
157
|
|
|
$configuration = $event->getConfiguration(); |
158
|
2 |
|
if ($this->verbose) { |
159
|
|
|
$this->write( |
160
|
2 |
|
'Runtime: '.$this->runtime->getNameWithVersion().PHP_EOL. |
161
|
2 |
|
'Configuration: '.$configuration->getFilename().PHP_EOL. |
162
|
1 |
|
PHP_EOL |
163
|
1 |
|
); |
164
|
1 |
|
} |
165
|
1 |
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
2 |
|
* Writes a buffer. |
169
|
|
|
* |
170
|
|
|
* @param string $buffer |
171
|
|
|
*/ |
172
|
|
|
public function write($buffer): void |
173
|
|
|
{ |
174
|
|
|
if (PHP_SAPI != 'cli') { |
175
|
3 |
|
$buffer = htmlspecialchars($buffer); |
176
|
|
|
} |
177
|
3 |
|
echo $buffer; |
178
|
3 |
|
} |
179
|
2 |
|
|
180
|
2 |
|
/** |
181
|
|
|
* Backup start event. |
182
|
3 |
|
* |
183
|
|
|
* @param \phpbu\App\Event\Backup\Start $event |
184
|
|
|
*/ |
185
|
|
|
public function onBackupStart(Event\Backup\Start $event): void |
186
|
|
|
{ |
187
|
|
|
$this->numBackups++; |
188
|
|
|
if ($this->debug) { |
189
|
1 |
|
$backup = $event->getConfiguration(); |
190
|
|
|
$this->writeWithAsterisk('backup: ['.$backup->getSource()->type.'] '); |
191
|
1 |
|
} |
192
|
1 |
|
} |
193
|
|
|
|
194
|
1 |
|
/** |
195
|
|
|
* Writes a buffer with Ansible like asterisk decoration. |
196
|
|
|
* |
197
|
|
|
* @param string $buffer |
198
|
|
|
*/ |
199
|
|
|
protected function writeWithAsterisk($buffer): void |
200
|
|
|
{ |
201
|
2 |
|
$this->write(Util\Cli::formatWithAsterisk($buffer)); |
202
|
|
|
} |
203
|
2 |
|
|
204
|
1 |
|
/** |
205
|
|
|
* Backup failed event. |
206
|
2 |
|
* |
207
|
|
|
* @param \phpbu\App\Event\Backup\Failed $event |
208
|
|
|
*/ |
209
|
|
|
public function onBackupFailed(Event\Backup\Failed $event): void |
|
|
|
|
210
|
|
|
{ |
211
|
|
|
if ($this->debug) { |
212
|
|
|
$this->writeWithColor('fg-white, bg-red, bold', 'failed'.PHP_EOL); |
213
|
3 |
|
} |
214
|
|
|
} |
215
|
3 |
|
|
216
|
3 |
|
/** |
217
|
2 |
|
* Writes a buffer out with a color sequence if colors are enabled. |
218
|
2 |
|
* |
219
|
2 |
|
* @param string $color |
220
|
|
|
* @param string $buffer |
221
|
3 |
|
* @author Sebastian Bergmann <[email protected]> |
222
|
|
|
*/ |
223
|
|
|
protected function writeWithColor($color, $buffer): void |
224
|
|
|
{ |
225
|
|
|
if ($this->colors) { |
226
|
|
|
$buffer = Util\Cli::formatWithColor($color, $buffer); |
227
|
|
|
} |
228
|
1 |
|
$this->write($buffer.PHP_EOL); |
229
|
|
|
} |
230
|
1 |
|
|
231
|
1 |
|
/** |
232
|
|
|
* Backup end event. |
233
|
1 |
|
* |
234
|
|
|
* @param \phpbu\App\Event\Backup\End $event |
235
|
|
|
*/ |
236
|
|
|
public function onBackupEnd(Event\Backup\End $event): void |
|
|
|
|
237
|
|
|
{ |
238
|
|
|
if ($this->debug) { |
239
|
|
|
$this->writeWithColor('fg-black, bg-green', 'ok'.PHP_EOL); |
240
|
2 |
|
} |
241
|
|
|
} |
242
|
2 |
|
|
243
|
1 |
|
/** |
244
|
|
|
* Check start event. |
245
|
2 |
|
* |
246
|
|
|
* @param \phpbu\App\Event\Check\Start $event |
247
|
|
|
*/ |
248
|
|
|
public function onCheckStart(Event\Check\Start $event): void |
249
|
|
|
{ |
250
|
|
|
$this->numChecks++; |
251
|
|
|
if ($this->debug) { |
252
|
4 |
|
$check = $event->getConfiguration(); |
253
|
|
|
$this->writeWithAsterisk('check: ['.$check->type.'] '); |
254
|
4 |
|
$this->write('checking: ['.$check->value.'] '); |
255
|
4 |
|
} |
256
|
3 |
|
} |
257
|
3 |
|
|
258
|
|
|
/** |
259
|
4 |
|
* Check failed event. |
260
|
|
|
* |
261
|
|
|
* @param \phpbu\App\Event\Check\Failed $event |
262
|
|
|
*/ |
263
|
|
|
public function onCheckFailed(Event\Check\Failed $event): void |
264
|
|
|
{ |
265
|
|
|
$this->failedChecks[] = $event; |
266
|
1 |
|
|
267
|
|
|
if ($this->debug) { |
268
|
1 |
|
$this->writeWithColor('fg-white, bg-red, bold', 'failed'.PHP_EOL); |
269
|
1 |
|
} |
270
|
|
|
} |
271
|
1 |
|
|
272
|
|
|
/** |
273
|
|
|
* Check end event. |
274
|
|
|
* |
275
|
|
|
* @param \phpbu\App\Event\Check\End $event |
276
|
|
|
*/ |
277
|
|
|
public function onCheckEnd(Event\Check\End $event): void |
|
|
|
|
278
|
1 |
|
{ |
279
|
|
|
if ($this->debug) { |
280
|
1 |
|
$this->writeWithColor('fg-black, bg-green', 'ok'.PHP_EOL); |
281
|
1 |
|
} |
282
|
|
|
} |
283
|
1 |
|
|
284
|
|
|
/** |
285
|
|
|
* Crypt start event. |
286
|
|
|
* |
287
|
|
|
* @param \phpbu\App\Event\Crypt\Start $event |
288
|
|
|
*/ |
289
|
|
|
public function onCryptStart(Event\Crypt\Start $event): void |
290
|
2 |
|
{ |
291
|
|
|
$this->numCrypts++; |
292
|
2 |
|
if ($this->debug) { |
293
|
1 |
|
$crypt = $event->getConfiguration(); |
294
|
|
|
$this->writeWithAsterisk('crypt: ['.$crypt->type.'] '); |
295
|
2 |
|
} |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Crypt skipped event. |
300
|
|
|
* |
301
|
|
|
* @param \phpbu\App\Event\Crypt\Skipped $event |
302
|
4 |
|
*/ |
303
|
|
|
public function onCryptSkipped(Event\Crypt\Skipped $event): void |
|
|
|
|
304
|
4 |
|
{ |
305
|
4 |
|
if ($this->debug) { |
306
|
3 |
|
$this->writeWithColor('fg-black, bg-yellow', 'skipped'.PHP_EOL); |
307
|
3 |
|
} |
308
|
|
|
} |
309
|
4 |
|
|
310
|
|
|
/** |
311
|
|
|
* Crypt failed event. |
312
|
|
|
* |
313
|
|
|
* @param \phpbu\App\Event\Crypt\Failed $event |
314
|
|
|
*/ |
315
|
|
|
public function onCryptFailed(Event\Crypt\Failed $event): void |
|
|
|
|
316
|
1 |
|
{ |
317
|
|
|
if ($this->debug) { |
318
|
1 |
|
$this->writeWithColor('fg-white, bg-red, bold', 'failed'.PHP_EOL); |
319
|
1 |
|
} |
320
|
|
|
} |
321
|
1 |
|
|
322
|
|
|
/** |
323
|
|
|
* Crypt end event. |
324
|
|
|
* |
325
|
|
|
* @param \phpbu\App\Event\Crypt\End $event |
326
|
|
|
*/ |
327
|
|
|
public function onCryptEnd(Event\Crypt\End $event): void |
|
|
|
|
328
|
1 |
|
{ |
329
|
|
|
if ($this->debug) { |
330
|
1 |
|
$this->writeWithColor('fg-black, bg-green', 'ok'.PHP_EOL); |
331
|
1 |
|
} |
332
|
|
|
} |
333
|
1 |
|
|
334
|
|
|
/** |
335
|
|
|
* Sync start event. |
336
|
|
|
* |
337
|
|
|
* @param \phpbu\App\Event\Sync\Start $event |
338
|
|
|
*/ |
339
|
|
|
public function onSyncStart(Event\Sync\Start $event): void |
340
|
2 |
|
{ |
341
|
|
|
$this->numSyncs++; |
342
|
2 |
|
if ($this->debug) { |
343
|
1 |
|
$sync = $event->getConfiguration(); |
344
|
|
|
$this->writeWithAsterisk('sync: ['.$sync->type.'] '); |
345
|
2 |
|
} |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Sync skipped event. |
350
|
|
|
* |
351
|
|
|
* @param \phpbu\App\Event\Sync\Skipped $event |
352
|
4 |
|
*/ |
353
|
|
|
public function onSyncSkipped(Event\Sync\Skipped $event): void |
|
|
|
|
354
|
4 |
|
{ |
355
|
4 |
|
if ($this->debug) { |
356
|
3 |
|
$this->writeWithColor('fg-black, bg-yellow', 'skipped'.PHP_EOL); |
357
|
3 |
|
} |
358
|
|
|
} |
359
|
4 |
|
|
360
|
|
|
/** |
361
|
|
|
* Sync failed event. |
362
|
|
|
* |
363
|
|
|
* @param \phpbu\App\Event\Sync\Failed $event |
364
|
|
|
*/ |
365
|
|
|
public function onSyncFailed(Event\Sync\Failed $event): void |
|
|
|
|
366
|
1 |
|
{ |
367
|
|
|
if ($this->debug) { |
368
|
1 |
|
$this->writeWithColor('fg-white, bg-red, bold', 'failed'.PHP_EOL); |
369
|
1 |
|
} |
370
|
|
|
} |
371
|
1 |
|
|
372
|
|
|
/** |
373
|
|
|
* Sync end event. |
374
|
|
|
* |
375
|
|
|
* @param \phpbu\App\Event\Sync\End $event |
376
|
|
|
*/ |
377
|
|
|
public function onSyncEnd(Event\Sync\End $event): void |
|
|
|
|
378
|
1 |
|
{ |
379
|
|
|
if ($this->debug) { |
380
|
1 |
|
$this->writeWithColor('fg-black, bg-green', 'ok'.PHP_EOL); |
381
|
1 |
|
} |
382
|
|
|
} |
383
|
1 |
|
|
384
|
|
|
/** |
385
|
|
|
* Cleanup start event. |
386
|
|
|
* |
387
|
|
|
* @param \phpbu\App\Event\Cleanup\Start $event |
388
|
|
|
*/ |
389
|
|
|
public function onCleanupStart(Event\Cleanup\Start $event): void |
390
|
2 |
|
{ |
391
|
|
|
$this->numCleanups++; |
392
|
2 |
|
if ($this->debug) { |
393
|
1 |
|
$cleanup = $event->getConfiguration(); |
394
|
|
|
$this->writeWithAsterisk('cleanup: ['.$cleanup->type.'] '); |
395
|
2 |
|
} |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Cleanup skipped event. |
400
|
|
|
* |
401
|
|
|
* @param \phpbu\App\Event\Cleanup\Skipped $event |
402
|
1 |
|
*/ |
403
|
|
|
public function onCleanupSkipped(Event\Cleanup\Skipped $event): void |
|
|
|
|
404
|
1 |
|
{ |
405
|
1 |
|
if ($this->debug) { |
406
|
|
|
$this->writeWithColor('fg-black, bg-yellow', 'skipped'.PHP_EOL); |
407
|
1 |
|
} |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Cleanup failed event. |
412
|
|
|
* |
413
|
|
|
* @param \phpbu\App\Event\Cleanup\Failed $event |
414
|
1 |
|
*/ |
415
|
|
|
public function onCleanupFailed(Event\Cleanup\Failed $event): void |
|
|
|
|
416
|
1 |
|
{ |
417
|
1 |
|
if ($this->debug) { |
418
|
1 |
|
$this->writeWithColor('fg-white, bg-red, bold', 'failed'.PHP_EOL); |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Cleanup end event. |
424
|
|
|
* |
425
|
5 |
|
* @param \phpbu\App\Event\Cleanup\End $event |
426
|
|
|
*/ |
427
|
5 |
|
public function onCleanupEnd(Event\Cleanup\End $event): void |
|
|
|
|
428
|
5 |
|
{ |
429
|
|
|
if ($this->debug) { |
430
|
5 |
|
$this->writeWithColor('fg-black, bg-green', 'ok'.PHP_EOL); |
431
|
3 |
|
} |
432
|
3 |
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
5 |
|
* Debugging. |
436
|
5 |
|
* |
437
|
|
|
* @param \phpbu\App\Event\Debug $event |
438
|
|
|
*/ |
439
|
|
|
public function onDebug(Event\Debug $event): void |
440
|
|
|
{ |
441
|
5 |
|
if ($this->debug) { |
442
|
|
|
$this->write($event->getMessage().PHP_EOL); |
443
|
5 |
|
} |
444
|
5 |
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Warnings. |
448
|
|
|
* |
449
|
|
|
* @param \phpbu\App\Event\Warning $event |
450
|
|
|
*/ |
451
|
5 |
|
public function onWarning(Event\Warning $event): void |
452
|
|
|
{ |
453
|
|
|
$this->writeWithColor('fg-black, bg-yellow', $event->getMessage().PHP_EOL); |
454
|
5 |
|
} |
455
|
1 |
|
|
456
|
1 |
|
/** |
457
|
1 |
|
* phpbu end event. |
458
|
1 |
|
* |
459
|
1 |
|
* @param \phpbu\App\Event\App\End $event |
460
|
1 |
|
*/ |
461
|
1 |
|
public function onPhpbuEnd(Event\App\End $event): void |
462
|
|
|
{ |
463
|
|
|
$result = $event->getResult(); |
464
|
|
|
$this->printResult($result); |
465
|
5 |
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* Prints a result summary. |
469
|
|
|
* |
470
|
|
|
* @param \phpbu\App\Result $result |
471
|
|
|
*/ |
472
|
3 |
|
public function printResult(Result $result): void |
473
|
|
|
{ |
474
|
3 |
|
$this->printHeader(); |
475
|
3 |
|
$this->printErrors($result); |
476
|
1 |
|
$this->printFailedChecks($result); |
477
|
1 |
|
|
478
|
1 |
|
if ($this->verbose) { |
479
|
|
|
foreach ($result->getBackups() as $backup) { |
480
|
2 |
|
$this->printBackupVerbose($backup); |
481
|
1 |
|
} |
482
|
1 |
|
} |
483
|
1 |
|
$this->printFooter($result); |
484
|
|
|
} |
485
|
|
|
|
486
|
1 |
|
/** |
487
|
1 |
|
* Prints the result header with memory usage info. |
488
|
1 |
|
*/ |
489
|
|
|
protected function printHeader(): void |
490
|
|
|
{ |
491
|
3 |
|
$this->write(Statistics::resourceUsage().PHP_EOL.PHP_EOL); |
492
|
3 |
|
} |
493
|
3 |
|
|
494
|
3 |
|
/** |
495
|
3 |
|
* Print error information. |
496
|
3 |
|
* |
497
|
3 |
|
* @param \phpbu\App\Result $result |
498
|
3 |
|
*/ |
499
|
3 |
|
protected function printErrors(Result $result): void |
500
|
3 |
|
{ |
501
|
3 |
|
/* @var $e \Exception */ |
502
|
|
|
foreach ($result->getErrors() as $e) { |
503
|
3 |
|
$this->write( |
504
|
3 |
|
sprintf( |
505
|
3 |
|
"Exception '%s' with message '%s'\nin %s:%d\n\n", |
506
|
3 |
|
get_class($e), |
507
|
3 |
|
$e->getMessage(), |
508
|
3 |
|
$e->getFile(), |
509
|
3 |
|
$e->getLine() |
510
|
|
|
) |
511
|
3 |
|
); |
512
|
3 |
|
} |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Print information on failed checks. |
517
|
|
|
* |
518
|
|
|
* @param \phpbu\App\Result $result |
519
|
5 |
|
*/ |
520
|
|
|
protected function printFailedChecks(Result $result): void |
|
|
|
|
521
|
5 |
|
{ |
522
|
2 |
|
foreach ($this->failedChecks as $failedCheck) { |
523
|
2 |
|
/** @var \phpbu\App\Configuration\Backup\Check $configuration */ |
524
|
2 |
|
$configuration = $failedCheck->getConfiguration(); |
525
|
|
|
$this->write( |
526
|
3 |
|
sprintf( |
527
|
1 |
|
"Check %s (%s) FAILED \n\n", |
528
|
1 |
|
$configuration->type, |
529
|
1 |
|
$configuration->value |
530
|
1 |
|
) |
531
|
1 |
|
); |
532
|
1 |
|
} |
533
|
1 |
|
} |
534
|
1 |
|
|
535
|
1 |
|
/** |
536
|
1 |
|
* Prints verbose backup information. |
537
|
1 |
|
* |
538
|
1 |
|
* @param \phpbu\App\Result\Backup $backup |
539
|
1 |
|
*/ |
540
|
1 |
|
protected function printBackupVerbose(Result\Backup $backup): void |
541
|
|
|
{ |
542
|
|
|
$this->write(sprintf('backup %s: ', $backup->getName())); |
543
|
2 |
|
if ($backup->allOk()) { |
544
|
1 |
|
$this->writeWithColor( |
545
|
1 |
|
'fg-green', |
546
|
1 |
|
'OK' |
547
|
1 |
|
); |
548
|
1 |
|
} elseif ($backup->okButSkipsOrFails()) { |
549
|
1 |
|
$this->writeWithColor( |
550
|
1 |
|
'fg-yellow', |
551
|
1 |
|
'OK, but skipped or failed Crypts, Syncs or Cleanups!' |
552
|
1 |
|
); |
553
|
1 |
|
} else { |
554
|
1 |
|
$this->writeWithColor( |
555
|
1 |
|
'fg-red', |
556
|
|
|
'FAILED' |
557
|
|
|
); |
558
|
|
|
} |
559
|
1 |
|
$chExecuted = str_pad($backup->checkCount(), 8, ' ', STR_PAD_LEFT); |
560
|
1 |
|
$chFailed = str_pad($backup->checkCountFailed(), 6, ' ', STR_PAD_LEFT); |
561
|
1 |
|
$crExecuted = str_pad($backup->cryptCount(), 8, ' ', STR_PAD_LEFT); |
562
|
1 |
|
$crSkipped = str_pad($backup->cryptCountSkipped(), 7, ' ', STR_PAD_LEFT); |
563
|
1 |
|
$crFailed = str_pad($backup->cryptCountFailed(), 6, ' ', STR_PAD_LEFT); |
564
|
1 |
|
$syExecuted = str_pad($backup->syncCount(), 8, ' ', STR_PAD_LEFT); |
565
|
1 |
|
$sySkipped = str_pad($backup->syncCountSkipped(), 7, ' ', STR_PAD_LEFT); |
566
|
1 |
|
$syFailed = str_pad($backup->syncCountFailed(), 6, ' ', STR_PAD_LEFT); |
567
|
1 |
|
$clExecuted = str_pad($backup->cleanupCount(), 8, ' ', STR_PAD_LEFT); |
568
|
1 |
|
$clSkipped = str_pad($backup->cleanupCountSkipped(), 7, ' ', STR_PAD_LEFT); |
569
|
1 |
|
$clFailed = str_pad($backup->cleanupCountFailed(), 6, ' ', STR_PAD_LEFT); |
570
|
1 |
|
|
571
|
1 |
|
$out = PHP_EOL.' | executed | skipped | failed |'.PHP_EOL |
572
|
1 |
|
.'----------+----------+---------+--------+'.PHP_EOL |
573
|
|
|
.' checks | '.$chExecuted.' | | '.$chFailed.' |'.PHP_EOL |
574
|
|
|
.' crypts | '.$crExecuted.' | '.$crSkipped.' | '.$crFailed.' |'.PHP_EOL |
575
|
|
|
.' syncs | '.$syExecuted.' | '.$sySkipped.' | '.$syFailed.' |'.PHP_EOL |
576
|
5 |
|
.' cleanups | '.$clExecuted.' | '.$clSkipped.' | '.$clFailed.' |'.PHP_EOL |
577
|
|
|
.'----------+----------+---------+--------+'.PHP_EOL.PHP_EOL; |
578
|
|
|
|
579
|
|
|
$this->write($out); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
/** |
583
|
|
|
* Prints 'OK' or 'FAILURE' footer. |
584
|
|
|
* |
585
|
18 |
|
* @param Result $result |
586
|
|
|
*/ |
587
|
18 |
|
protected function printFooter(Result $result): void |
588
|
1 |
|
{ |
589
|
|
|
if (count($result->getBackups()) === 0) { |
590
|
18 |
|
$this->writeWithColor( |
591
|
18 |
|
'fg-yellow', |
592
|
|
|
'No backups executed!' |
593
|
|
|
); |
594
|
|
|
} elseif ($result->allOk()) { |
595
|
|
|
$this->writeWithColor( |
596
|
|
|
'fg-green', |
597
|
|
|
sprintf( |
598
|
13 |
|
'OK (%d %s, %d %s, %d %s, %d %s, %d %s)'.PHP_EOL, |
599
|
|
|
count($result->getBackups()), |
600
|
13 |
|
Util\Str::appendPluralS('backup', count($result->getBackups())), |
601
|
13 |
|
$this->numChecks, |
602
|
|
|
Util\Str::appendPluralS('check', $this->numChecks), |
603
|
|
|
$this->numCrypts, |
604
|
|
|
Util\Str::appendPluralS('crypt', $this->numCrypts), |
605
|
|
|
$this->numSyncs, |
606
|
|
|
Util\Str::appendPluralS('sync', $this->numSyncs), |
607
|
|
|
$this->numCleanups, |
608
|
20 |
|
Util\Str::appendPluralS('cleanup', $this->numCleanups) |
609
|
|
|
) |
610
|
20 |
|
); |
611
|
|
|
} elseif ($result->backupOkButSkipsOrFails()) { |
612
|
|
|
$this->writeWithColor( |
613
|
20 |
|
'fg-yellow', |
614
|
20 |
|
sprintf( |
615
|
|
|
"WARNING, skipped|failed Crypts, Syncs or Cleanups!".PHP_EOL. |
616
|
|
|
'Backups: %d, Crypts: %d|%d, Syncs: %d|%d, Cleanups: %d|%d '.PHP_EOL, |
617
|
|
|
count($result->getBackups()), |
618
|
|
|
$result->cryptsSkippedCount(), |
619
|
|
|
$result->cryptsFailedCount(), |
620
|
|
|
$result->syncsSkippedCount(), |
621
|
|
|
$result->syncsFailedCount(), |
622
|
|
|
$result->cleanupsSkippedCount(), |
623
|
|
|
$result->cleanupsFailedCount() |
624
|
|
|
) |
625
|
|
|
); |
626
|
|
|
} else { |
627
|
|
|
$this->writeWithColor( |
628
|
|
|
'fg-red', |
629
|
|
|
sprintf( |
630
|
|
|
"FAILURE!".PHP_EOL. |
631
|
|
|
'Backups: %d, ' |
632
|
|
|
.'failed Checks: %d, ' |
633
|
|
|
.'failed Crypts: %d, ' |
634
|
|
|
.'failed Syncs: %d, ' |
635
|
|
|
.'failed Cleanups: %d.'.PHP_EOL, |
636
|
|
|
count($result->getBackups()), |
637
|
|
|
$result->checksFailedCount(), |
638
|
|
|
$result->cryptsFailedCount(), |
639
|
|
|
$result->syncsFailedCount(), |
640
|
|
|
$result->cleanupsFailedCount() |
641
|
|
|
) |
642
|
|
|
); |
643
|
|
|
} |
644
|
|
|
} |
645
|
|
|
} |
646
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.