Add option to resize a single folder
This commit is contained in:
parent
d5fecfea1a
commit
8013f66b42
|
@ -3,6 +3,7 @@
|
|||
use Aweos\Resizer\Classes\CacheManager;
|
||||
use Aweos\Resizer\Classes\ResizeJob;
|
||||
use Aweos\Resizer\Models\Setting;
|
||||
use Exception;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Illuminate\Console\Command;
|
||||
|
@ -47,6 +48,13 @@ class ResizeMake extends Command
|
|||
{
|
||||
$this->media = MediaLibrary::instance();
|
||||
ProgressBar::setFormatDefinition('custom', '%current%/%max% %bar% -- %message% (%size%)');
|
||||
|
||||
if ($this->option('folder')) {
|
||||
throw_unless(in_array($this->option('folder'), array_column(Setting::get('folders'), 'folder')), Exception::class, 'Folder not found');
|
||||
$this->resize($this->option('folder'));
|
||||
return;
|
||||
}
|
||||
|
||||
Storage::deleteDirectory('uploads/public/c');
|
||||
$cacheManager->flush();
|
||||
|
||||
|
@ -61,7 +69,9 @@ class ResizeMake extends Command
|
|||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,6 +80,8 @@ class ResizeMake extends Command
|
|||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [];
|
||||
return [
|
||||
['folder', 'f', InputOption::VALUE_OPTIONAL, 'Just resize for specific subfolders', null]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Aweos\Resizer\Tests\MediaTest;
|
||||
namespace Aweos\Resizer\Tests;
|
||||
|
||||
use Aweos\Resizer\Models\Setting;
|
||||
use Aweos\Resizer\Tests\TestCase;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Aweos\Resizer\Tests\MediaTest;
|
||||
namespace Aweos\Resizer\Tests;
|
||||
|
||||
use Aweos\Resizer\Classes\CacheManager;
|
||||
use Aweos\Resizer\Classes\TagGenerator;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Aweos\Resizer\Tests\MediaTest;
|
||||
namespace Aweos\Resizer\Tests;
|
||||
|
||||
use Aweos\Resizer\Models\Setting;
|
||||
use Aweos\Resizer\Tests\TestCase;
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Aweos\Resizer\Tests;
|
||||
|
||||
use Artisan;
|
||||
use Aweos\Resizer\Models\Setting;
|
||||
use Aweos\Resizer\Tests\TestCase;
|
||||
use Cache;
|
||||
use Event;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Storage;
|
||||
|
||||
class ResizeMakeTest extends TestCase
|
||||
{
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Storage::fake('local');
|
||||
}
|
||||
|
||||
public function testItCanRunResizeMakeCommandOnAllFolders()
|
||||
{
|
||||
Setting::set('folders', [['folder' => 'pages']]);
|
||||
Setting::set('sizes', []);
|
||||
Setting::set('breakpoints', []);
|
||||
$this->media->put('pages/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||||
|
||||
Artisan::call('resize:make');
|
||||
|
||||
$this->assertFileCount(1, 'pages');
|
||||
}
|
||||
|
||||
public function testItDeletesOtherFilesBeforeResizingAll()
|
||||
{
|
||||
Setting::set('folders', [['folder' => 'pages']]);
|
||||
Setting::set('sizes', []);
|
||||
Setting::set('breakpoints', []);
|
||||
Storage::put('uploads/public/c/otherdir/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||||
|
||||
Artisan::call('resize:make');
|
||||
|
||||
$this->assertFileCount(0, 'otherdir');
|
||||
}
|
||||
|
||||
public function testOnlyResizeASingleFolder()
|
||||
{
|
||||
Setting::set('folders', [
|
||||
['folder' => 'pages'],
|
||||
['folder' => 'otherdir'],
|
||||
]);
|
||||
Setting::set('sizes', []);
|
||||
Setting::set('breakpoints', []);
|
||||
$this->media->put('pages/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||||
Storage::put('uploads/public/c/pages/test-100x100.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||||
$this->media->put('otherdir/test.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||||
Storage::put('uploads/public/c/otherdir/test-100x100.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||||
Storage::put('uploads/public/c/otherdir/test-200x200.jpg', UploadedFile::fake()->image('test.jpg', 100, 100)->get());
|
||||
|
||||
Artisan::call('resize:make', ['-f' => 'pages']);
|
||||
|
||||
$this->assertFileCount(2, 'otherdir');
|
||||
$this->assertFileCount(1, 'pages');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Aweos\Resizer\Tests\MediaTest;
|
||||
namespace Aweos\Resizer\Tests;
|
||||
|
||||
use Aweos\Resizer\Models\Setting;
|
||||
use Aweos\Resizer\Tests\TestCase;
|
||||
|
|
Loading…
Reference in New Issue