From 71b71511199ff697185ee67a278cd4bf37d5c383 Mon Sep 17 00:00:00 2001 From: Julius Fischer Date: Wed, 24 Feb 2016 11:21:55 +0100 Subject: [PATCH] add list command --- src/BackupServiceProvider.php | 9 ++++- src/Commands/ListCommand.php | 76 +++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/Commands/ListCommand.php diff --git a/src/BackupServiceProvider.php b/src/BackupServiceProvider.php index 6376a858..56c5c974 100644 --- a/src/BackupServiceProvider.php +++ b/src/BackupServiceProvider.php @@ -40,7 +40,13 @@ function ($app) { } ); - $this->commands(['command.backup:run', 'command.backup:clean']); + $this->app['command.backup:list'] = $this->app->share( + function ($app) { + return new Commands\ListCommand(); + } + ); + + $this->commands(['command.backup:run', 'command.backup:clean', 'command.backup:list']); } /** @@ -53,6 +59,7 @@ public function provides() return [ 'command.backup:run', 'command.backup:clean', + 'command.backup:list', ]; } } diff --git a/src/Commands/ListCommand.php b/src/Commands/ListCommand.php new file mode 100644 index 00000000..87209eb9 --- /dev/null +++ b/src/Commands/ListCommand.php @@ -0,0 +1,76 @@ +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]; + } + +}