]> BookStack Code Mirror - bookstack/commitdiff
Cleanup Command: Allowed running non-interactively
authorDan Brown <redacted>
Thu, 14 Sep 2023 13:17:20 +0000 (14:17 +0100)
committerDan Brown <redacted>
Thu, 14 Sep 2023 13:17:20 +0000 (14:17 +0100)
For #4541

app/Console/Commands/CleanupImagesCommand.php
tests/Commands/CleanupImagesCommandTest.php

index fe924b0f46b79af8c694c37bf98087ae8a0e272b..18e60ff1773be7b9e9abc849006652d2c251f13a 100644 (file)
@@ -35,7 +35,7 @@ class CleanupImagesCommand extends Command
 
         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;
             }
@@ -46,7 +46,7 @@ class CleanupImagesCommand extends Command
 
         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');
 
@@ -54,7 +54,8 @@ class CleanupImagesCommand extends Command
         }
 
         $this->showDeletedImages($deleted);
-        $this->comment($deleteCount . ' images deleted');
+        $this->comment("{$deleteCount} image(s) deleted");
+
         return 0;
     }
 
@@ -65,7 +66,7 @@ class CleanupImagesCommand extends Command
         }
 
         if (count($paths) > 0) {
-            $this->line('Images to delete:');
+            $this->line('Image(s) to delete:');
         }
 
         foreach ($paths as $path) {
index a1a5ab98540e58cebc655f177e052021ef5b4f69..36fd51e968ea4d0e4a56c8c19ebeb1dc04b46aee 100644 (file)
@@ -14,7 +14,7 @@ class CleanupImagesCommandTest extends TestCase
 
         $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);
 
@@ -29,7 +29,7 @@ class CleanupImagesCommandTest extends TestCase
         $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]);
@@ -46,4 +46,17 @@ class CleanupImagesCommandTest extends TestCase
 
         $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]);
+    }
 }