Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added progress bar for clear command #1623

Merged
merged 6 commits into from
Feb 10, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Commands/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -31,9 +31,18 @@ public function handle()
return;
}

$this->getMediaItems()->each->delete();
$mediaItems = $this->getMediaItems();

$progressBar = $this->output->createProgressBar($mediaItems->count());

$mediaItems->each(function ($media) use ($progressBar) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typehint the $media parameter.

$media->delete();
$progressBar->advance();
});

$progressBar->finish();

$this->info('All done!');
$this->info("\nAll done!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove that \n?

}

public function getMediaItems() : Collection
Expand Down