1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Backup\Commands; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
use Illuminate\Support\Facades\Storage; |
9
|
|
|
|
10
|
|
|
class ListCommand extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The console command name. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $name = 'backup:list'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'List all backups'; |
25
|
|
|
|
26
|
|
|
public function fire() |
27
|
|
|
{ |
28
|
|
|
$path = config('laravel-backup.destination.path'); |
29
|
|
|
$collection = new Collection(); |
30
|
|
|
|
31
|
|
|
foreach ($this->getTargetFileSystems() as $filesystem) { |
32
|
|
|
$disk = Storage::disk($filesystem); |
33
|
|
|
|
34
|
|
|
foreach ($disk->files($path) as $file) { |
35
|
|
|
$collection->push([ |
36
|
|
|
'filesystem' => $filesystem, |
37
|
|
|
'name' => $file, |
38
|
|
|
'lastModified' => $disk->lastModified($file), |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$rows = $collection |
44
|
|
|
->sortByDesc('lastModified') |
45
|
|
|
->filter(function ($value) { |
46
|
|
|
return ends_with($value['name'], '.zip'); |
47
|
|
|
}) |
48
|
|
|
->map(function ($value) { |
49
|
|
|
$lastModified = Carbon::createFromTimestamp($value['lastModified']); |
50
|
|
|
|
51
|
|
|
$value['lastModified'] = $lastModified; |
52
|
|
|
$value['age'] = $lastModified->diffForHumans(); |
53
|
|
|
|
54
|
|
|
return $value; |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
$this->table(['Filesystem', 'Filename', 'Created at', 'Age'], $rows); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get the filesystems to where the database should be dumped. |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
protected function getTargetFileSystems() |
66
|
|
|
{ |
67
|
|
|
$fileSystems = config('laravel-backup.destination.filesystem'); |
68
|
|
|
|
69
|
|
|
if (is_array($fileSystems)) { |
70
|
|
|
return $fileSystems; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return [$fileSystems]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|