MonitorCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 23 4
1
<?php
2
3
namespace Spatie\Backup\Commands;
4
5
use Spatie\Backup\Events\HealthyBackupWasFound;
6
use Spatie\Backup\Events\UnhealthyBackupWasFound;
7
use Spatie\Backup\Tasks\Monitor\BackupDestinationStatusFactory;
8
9
class MonitorCommand extends BaseCommand
10
{
11
    /** @var string */
12
    protected $signature = 'backup:monitor';
13
14
    /** @var string */
15
    protected $description = 'Monitor the health of all backups.';
16
17
    public function handle()
18
    {
19
        $hasError = false;
20
21
        $statuses = BackupDestinationStatusFactory::createForMonitorConfig(config('backup.monitor_backups'));
22
23
        foreach ($statuses as $backupDestinationStatus) {
24
            $diskName = $backupDestinationStatus->backupDestination()->diskName();
25
26
            if ($backupDestinationStatus->isHealthy()) {
27
                $this->info("The backups on {$diskName} are considered healthy.");
28
                event(new HealthyBackupWasFound($backupDestinationStatus));
29
            } else {
30
                $hasError = true;
31
                $this->error("The backups on {$diskName} are considered unhealthy!");
32
                event(new UnHealthyBackupWasFound($backupDestinationStatus));
33
            }
34
        }
35
36
        if ($hasError) {
37
            return 1;
38
        }
39
    }
40
}
41