88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php namespace Aweos\Resizer\Console;
|
|
|
|
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;
|
|
use October\Rain\Database\Attach\Resizer;
|
|
use Queue;
|
|
use Storage;
|
|
use Symfony\Component\Console\Helper\ProgressBar;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use System\Classes\MediaLibrary;
|
|
|
|
class ResizeMake extends Command
|
|
{
|
|
public $media = null;
|
|
|
|
/**
|
|
* @var string The console command name.
|
|
*/
|
|
protected $name = 'resize:make';
|
|
|
|
/**
|
|
* @var string The console command description.
|
|
*/
|
|
protected $description = 'Resizes configured images';
|
|
|
|
public function resize(string $folder): void
|
|
{
|
|
foreach ($this->media->listFolderContents($folder) as $item) {
|
|
if ($item->type === 'folder') {
|
|
$this->resize($item->path);
|
|
} else {
|
|
Queue::push(ResizeJob::class, [$item->path]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
* @return void
|
|
*/
|
|
public function handle(CacheManager $cacheManager)
|
|
{
|
|
$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();
|
|
|
|
foreach (Setting::get('folders') as $folder) {
|
|
$this->resize($folder['folder']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the console command arguments.
|
|
* @return array
|
|
*/
|
|
protected function getArguments()
|
|
{
|
|
return [
|
|
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the console command options.
|
|
* @return array
|
|
*/
|
|
protected function getOptions()
|
|
{
|
|
return [
|
|
['folder', 'f', InputOption::VALUE_OPTIONAL, 'Just resize for specific subfolders', null]
|
|
];
|
|
}
|
|
}
|