76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php namespace Aweos\Resizer\Console;
|
|
|
|
use Aweos\Resizer\Classes\CacheManager;
|
|
use Aweos\Resizer\Classes\ResizeJob;
|
|
use Aweos\Resizer\Models\Setting;
|
|
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%)');
|
|
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 [];
|
|
}
|
|
}
|