X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/c31e6a03ce3d45df2d79399820bbbfc7df7fe2b8..refs/pull/2522/head:/app/Console/Commands/CleanupImages.php diff --git a/app/Console/Commands/CleanupImages.php b/app/Console/Commands/CleanupImages.php index 310a7bb24..93ca367a2 100644 --- a/app/Console/Commands/CleanupImages.php +++ b/app/Console/Commands/CleanupImages.php @@ -2,8 +2,9 @@ namespace BookStack\Console\Commands; -use BookStack\Services\ImageService; +use BookStack\Uploads\ImageService; use Illuminate\Console\Command; +use Symfony\Component\Console\Output\OutputInterface; class CleanupImages extends Command { @@ -13,8 +14,8 @@ class CleanupImages extends Command * @var string */ protected $signature = 'bookstack:cleanup-images - {--a|all : Include images that are used in page revisions} - {--f|force : Actually run the deletions} + {--a|all : Also delete images that are only used in old revisions} + {--f|force : Actually run the deletions, Defaults to a dry-run} '; /** @@ -29,7 +30,7 @@ class CleanupImages extends Command /** * Create a new command instance. - * @param ImageService $imageService + * @param \BookStack\Uploads\ImageService $imageService */ public function __construct(ImageService $imageService) { @@ -48,21 +49,37 @@ class CleanupImages extends Command $dryRun = $this->option('force') ? false : true; if (!$dryRun) { - $proceed = $this->confirm('This operation is destructive and is not guaranteed to be fully accurate. Ensure you have a backup of your images. Are you sure you want to proceed?'); + $proceed = $this->confirm("This operation is destructive and is not guaranteed to be fully accurate.\nEnsure you have a backup of your images.\nAre you sure you want to proceed?"); if (!$proceed) { return; } } - $deleteCount = $this->imageService->deleteUnusedImages($checkRevisions, ['gallery', 'drawio'], $dryRun); + $deleted = $this->imageService->deleteUnusedImages($checkRevisions, $dryRun); + $deleteCount = count($deleted); if ($dryRun) { $this->comment('Dry run, No images have been deleted'); $this->comment($deleteCount . ' images found that would have been deleted'); + $this->showDeletedImages($deleted); $this->comment('Run with -f or --force to perform deletions'); return; } + $this->showDeletedImages($deleted); $this->comment($deleteCount . ' images deleted'); } + + protected function showDeletedImages($paths) + { + if ($this->getOutput()->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL) { + return; + } + if (count($paths) > 0) { + $this->line('Images to delete:'); + } + foreach ($paths as $path) { + $this->line($path); + } + } }