if (!$dryRun) {
$this->warn("This operation is destructive and is not guaranteed to be fully accurate.\nEnsure you have a backup of your images.\n");
- $proceed = $this->confirm("Are you sure you want to proceed?");
+ $proceed = !$this->input->isInteractive() || $this->confirm("Are you sure you want to proceed?");
if (!$proceed) {
return 0;
}
if ($dryRun) {
$this->comment('Dry run, no images have been deleted');
- $this->comment($deleteCount . ' images found that would have been deleted');
+ $this->comment($deleteCount . ' image(s) found that would have been deleted');
$this->showDeletedImages($deleted);
$this->comment('Run with -f or --force to perform deletions');
}
$this->showDeletedImages($deleted);
- $this->comment($deleteCount . ' images deleted');
+ $this->comment("{$deleteCount} image(s) deleted");
+
return 0;
}
}
if (count($paths) > 0) {
- $this->line('Images to delete:');
+ $this->line('Image(s) to delete:');
}
foreach ($paths as $path) {
$this->artisan('bookstack:cleanup-images -v')
->expectsOutput('Dry run, no images have been deleted')
- ->expectsOutput('1 images found that would have been deleted')
+ ->expectsOutput('1 image(s) found that would have been deleted')
->expectsOutputToContain($image->path)
->assertExitCode(0);
$this->artisan('bookstack:cleanup-images --force')
->expectsOutputToContain('This operation is destructive and is not guaranteed to be fully accurate')
->expectsConfirmation('Are you sure you want to proceed?', 'yes')
- ->expectsOutput('1 images deleted')
+ ->expectsOutput('1 image(s) deleted')
->assertExitCode(0);
$this->assertDatabaseMissing('images', ['id' => $image->id]);
$this->assertDatabaseHas('images', ['id' => $image->id]);
}
+
+ public function test_command_force_no_interaction_run()
+ {
+ $page = $this->entities->page();
+ $image = Image::factory()->create(['uploaded_to' => $page->id]);
+
+ $this->artisan('bookstack:cleanup-images --force --no-interaction')
+ ->expectsOutputToContain('This operation is destructive and is not guaranteed to be fully accurate')
+ ->expectsOutput('1 image(s) deleted')
+ ->assertExitCode(0);
+
+ $this->assertDatabaseMissing('images', ['id' => $image->id]);
+ }
}