-
-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Spatie\Backup\Commands; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class ListCommand extends Command | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'backup:list'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'List all backups'; | ||
|
||
public function fire() | ||
{ | ||
$path = config('laravel-backup.destination.path'); | ||
$collection = new Collection(); | ||
|
||
foreach ($this->getTargetFileSystems() as $filesystem) { | ||
$disk = Storage::disk($filesystem); | ||
|
||
foreach ($disk->files($path) as $file) { | ||
$collection->push([ | ||
'filesystem' => $filesystem, | ||
'name' => $file, | ||
'lastModified' => $disk->lastModified($file), | ||
]); | ||
} | ||
} | ||
|
||
$rows = $collection | ||
->sortByDesc('lastModified') | ||
->filter(function ($value) { | ||
return ends_with($value['name'], '.zip'); | ||
}) | ||
->map(function ($value) { | ||
$lastModified = Carbon::createFromTimestamp($value['lastModified']); | ||
|
||
$value['lastModified'] = $lastModified; | ||
$value['age'] = $lastModified->diffForHumans(); | ||
|
||
return $value; | ||
}); | ||
|
||
$this->table(['Filesystem', 'Filename', 'Created at', 'Age'], $rows); | ||
} | ||
|
||
/** | ||
* Get the filesystems to where the database should be dumped. | ||
* | ||
* @return array | ||
*/ | ||
protected function getTargetFileSystems() | ||
{ | ||
$fileSystems = config('laravel-backup.destination.filesystem'); | ||
|
||
if (is_array($fileSystems)) { | ||
return $fileSystems; | ||
} | ||
|
||
return [$fileSystems]; | ||
} | ||
|
||
} |