From 6b0ab3182c294d856de38d0be20457600f81fb5a Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sun, 31 Oct 2021 21:12:16 +0100 Subject: [PATCH] Fixed: Clean folder when deleting single folder --- console/ResizeMake.php | 1 + tests/ResizeMakeTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/console/ResizeMake.php b/console/ResizeMake.php index a5fc73c..04c7bdd 100644 --- a/console/ResizeMake.php +++ b/console/ResizeMake.php @@ -51,6 +51,7 @@ class ResizeMake extends Command if ($this->option('folder')) { throw_unless(in_array($this->option('folder'), array_column(Setting::get('folders'), 'folder')), Exception::class, 'Folder not found'); + Storage::deleteDirectory('uploads/public/c'.$this->option('folder')); $this->resize($this->option('folder')); return; } diff --git a/tests/ResizeMakeTest.php b/tests/ResizeMakeTest.php index c38c697..37a2ddb 100644 --- a/tests/ResizeMakeTest.php +++ b/tests/ResizeMakeTest.php @@ -63,4 +63,19 @@ class ResizeMakeTest extends TestCase $this->assertFileCount(1, 'pages'); } + public function testCleanSingleFolderBeforeResizing() + { + Setting::set('folders', [ + ['folder' => '/pages'], + ['folder' => 'otherdir'], + ]); + Setting::set('sizes', []); + Setting::set('breakpoints', []); + Storage::put('uploads/public/c/pages/test-100x100.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get()); + + Artisan::call('resize:make', ['-f' => '/pages']); + + $this->assertFileCount(0, 'pages'); + } + }