From 6c51fe96e1d0ed7b712505da9b340796703bbedb Mon Sep 17 00:00:00 2001 From: Ahmed Fathy Date: Fri, 8 Nov 2019 03:22:34 +0200 Subject: [PATCH 1/5] Added progress bar for clear command --- src/Commands/ClearCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Commands/ClearCommand.php b/src/Commands/ClearCommand.php index aec881e31..858e63da8 100644 --- a/src/Commands/ClearCommand.php +++ b/src/Commands/ClearCommand.php @@ -31,9 +31,18 @@ public function handle() return; } - $this->getMediaItems()->each->delete(); + $mediaItems = $this->getMediaItems(); - $this->info('All done!'); + $progressBar = $this->output->createProgressBar($mediaItems->count()); + + $mediaItems->each(function ($media) use ($progressBar) { + $media->delete(); + $progressBar->advance(); + }); + + $progressBar->finish(); + + $this->info("\nAll done!"); } public function getMediaItems() : Collection From 9ce61f38c9bf9f8f8b3b5a1a5ce903a8a6fe205c Mon Sep 17 00:00:00 2001 From: Ahmed Fathy Date: Fri, 8 Nov 2019 03:31:04 +0200 Subject: [PATCH 2/5] formating --- src/Commands/ClearCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/ClearCommand.php b/src/Commands/ClearCommand.php index 858e63da8..0f0628ffe 100644 --- a/src/Commands/ClearCommand.php +++ b/src/Commands/ClearCommand.php @@ -4,8 +4,8 @@ use Illuminate\Console\Command; use Illuminate\Console\ConfirmableTrait; -use Spatie\MediaLibrary\MediaRepository; use Illuminate\Database\Eloquent\Collection; +use Spatie\MediaLibrary\MediaRepository; class ClearCommand extends Command { From 4461e2c2b01169031a9125b95a98db1c4e8214f8 Mon Sep 17 00:00:00 2001 From: Ahmed Fathy Date: Fri, 8 Nov 2019 11:58:04 +0200 Subject: [PATCH 3/5] Remove \n from done message --- src/Commands/ClearCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/ClearCommand.php b/src/Commands/ClearCommand.php index 0f0628ffe..9ae4cf618 100644 --- a/src/Commands/ClearCommand.php +++ b/src/Commands/ClearCommand.php @@ -42,7 +42,7 @@ public function handle() $progressBar->finish(); - $this->info("\nAll done!"); + $this->info("All done!"); } public function getMediaItems() : Collection From fb6dfe3f2e18e6a69c8cc473e4fb74cf44d0e4ee Mon Sep 17 00:00:00 2001 From: Ahmed Fathy Date: Fri, 8 Nov 2019 11:58:48 +0200 Subject: [PATCH 4/5] Typehint the parameter. --- src/Commands/ClearCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Commands/ClearCommand.php b/src/Commands/ClearCommand.php index 9ae4cf618..1f52642bb 100644 --- a/src/Commands/ClearCommand.php +++ b/src/Commands/ClearCommand.php @@ -6,6 +6,7 @@ use Illuminate\Console\ConfirmableTrait; use Illuminate\Database\Eloquent\Collection; use Spatie\MediaLibrary\MediaRepository; +use Spatie\MediaLibrary\Models\Media; class ClearCommand extends Command { @@ -35,7 +36,7 @@ public function handle() $progressBar = $this->output->createProgressBar($mediaItems->count()); - $mediaItems->each(function ($media) use ($progressBar) { + $mediaItems->each(function (Media $media) use ($progressBar) { $media->delete(); $progressBar->advance(); }); From 25190e7bdef5aa252396638fedb4e458a6bdeb81 Mon Sep 17 00:00:00 2001 From: Ahmed Fathy Date: Fri, 8 Nov 2019 12:00:27 +0200 Subject: [PATCH 5/5] formating --- src/Commands/ClearCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/ClearCommand.php b/src/Commands/ClearCommand.php index 1f52642bb..bf3968e43 100644 --- a/src/Commands/ClearCommand.php +++ b/src/Commands/ClearCommand.php @@ -43,7 +43,7 @@ public function handle() $progressBar->finish(); - $this->info("All done!"); + $this->info('All done!'); } public function getMediaItems() : Collection