BackupStatuses   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 6
dl 0
loc 79
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A getStatus() 0 4 1
A runBackups() 0 17 3
A clearBackups() 0 19 2
1
<?php namespace Arcanesoft\Backups\Services;
2
3
use Spatie\Backup\BackupDestination\BackupDestinationFactory;
4
use Spatie\Backup\Tasks\Backup\BackupJobFactory;
5
use Spatie\Backup\Tasks\Cleanup\CleanupJob;
6
use Spatie\Backup\Tasks\Monitor\BackupDestinationStatusFactory;
7
8
/**
9
 * Class     BackupStatuses
10
 *
11
 * @package  Arcanesoft\Backups\Services
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class BackupStatuses
15
{
16
    /* -----------------------------------------------------------------
17
     |  Main Methods
18
     | -----------------------------------------------------------------
19
     */
20
21
    /**
22
     * Get all the statuses.
23
     *
24
     * @return \Illuminate\Support\Collection
25
     */
26
    public static function all()
27
    {
28
        return BackupDestinationStatusFactory::createForMonitorConfig(config('laravel-backup.monitorBackups'));
29
    }
30
31
    /**
32
     * Get a status by index.
33
     *
34
     * @param  int  $index
35
     *
36
     * @return \Spatie\Backup\Tasks\Monitor\BackupDestinationStatus|null
37
     */
38
    public static function getStatus($index)
39
    {
40
        return static::all()->get($index);
41
    }
42
43
    /**
44
     * Run the backups.
45
     *
46
     * @param  string|null  $disk
47
     *
48
     * @return bool
49
     */
50
    public static function runBackups($disk = null)
51
    {
52
        try {
53
            $backupJob = BackupJobFactory::createFromArray(config('laravel-backup'));
54
55
            if ( ! is_null($disk)) {
56
                $backupJob->onlyBackupTo($disk);
57
            }
58
59
            $backupJob->run();
60
        }
61
        catch (\Exception $ex) {
62
            return false;
63
        }
64
65
        return true;
66
    }
67
68
    /**
69
     * Clean the backups.
70
     *
71
     * @return bool
72
     */
73
    public static function clearBackups()
74
    {
75
        try {
76
            $config = config('laravel-backup');
77
78
            $backupDestinations = BackupDestinationFactory::createFromArray($config['backup']);
79
80
            $strategy = app($config['cleanup']['strategy']);
81
82
            $disableNotification = false; // TODO: Create a config for this
83
84
            (new CleanupJob($backupDestinations, $strategy, $disableNotification))->run();
85
        }
86
        catch (\Exception $ex) {
87
            return false;
88
        }
89
90
        return true;
91
    }
92
}
93