94 lines
2.6 KiB
PHP
94 lines
2.6 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 Media\Classes\MediaLibrary;
|
|
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;
|
|
|
|
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, 'update' => $this->option('update', false)]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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');
|
|
if (!$this->option('update')) {
|
|
Storage::deleteDirectory('uploads/public/c'.$this->option('folder'));
|
|
}
|
|
$this->resize($this->option('folder'));
|
|
return;
|
|
}
|
|
|
|
if (!$this->option('update')) {
|
|
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],
|
|
['update', 'u', InputOption::VALUE_NONE, 'Just update missing files', null],
|
|
];
|
|
}
|
|
}
|