3 namespace BookStack\Console\Commands;
5 use BookStack\Services\ImageService;
6 use Illuminate\Console\Command;
8 class CleanupImages extends Command
11 * The name and signature of the console command.
15 protected $signature = 'bookstack:cleanup-images
16 {--a|all : Include images that are used in page revisions}
17 {--f|force : Actually run the deletions}
21 * The console command description.
25 protected $description = 'Cleanup images and drawings';
28 protected $imageService;
31 * Create a new command instance.
32 * @param ImageService $imageService
34 public function __construct(ImageService $imageService)
36 $this->imageService = $imageService;
37 parent::__construct();
41 * Execute the console command.
45 public function handle()
47 $checkRevisions = $this->option('all') ? false : true;
48 $dryRun = $this->option('force') ? false : true;
51 $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?');
57 $deleteCount = $this->imageService->deleteUnusedImages($checkRevisions, ['gallery', 'drawio'], $dryRun);
60 $this->comment('Dry run, No images have been deleted');
61 $this->comment($deleteCount . ' images found that would have been deleted');
62 $this->comment('Run with -f or --force to perform deletions');
66 $this->comment($deleteCount . ' images deleted');