oc-resizer-plugin/console/ResizeMake.php

74 lines
1.8 KiB
PHP
Raw Normal View History

2019-09-17 23:14:29 +02:00
<?php namespace Aweos\Resizer\Console;
2021-09-06 02:31:27 +02:00
use Aweos\Resizer\Classes\ResizeJob;
2019-09-17 23:14:29 +02:00
use Aweos\Resizer\Models\Setting;
2021-09-06 02:31:27 +02:00
use GuzzleHttp\Client;
2019-09-17 23:14:29 +02:00
use GuzzleHttp\Exception\ClientException;
2021-09-06 02:31:27 +02:00
use Illuminate\Console\Command;
2019-09-17 23:14:29 +02:00
use October\Rain\Database\Attach\Resizer;
2021-09-06 02:31:27 +02:00
use Queue;
use Storage;
2019-09-17 23:14:29 +02:00
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
2021-09-06 02:31:27 +02:00
use Symfony\Component\Console\Input\InputOption;
use System\Classes\MediaLibrary;
2019-09-17 23:14:29 +02:00
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';
2021-09-06 02:31:27 +02:00
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]);
}
2019-09-17 23:14:29 +02:00
}
}
/**
* Execute the console command.
* @return void
*/
public function handle()
{
$this->media = MediaLibrary::instance();
ProgressBar::setFormatDefinition('custom', '%current%/%max% %bar% -- %message% (%size%)');
2021-09-06 02:31:27 +02:00
Storage::deleteDirectory('uploads/public/c');
2019-09-17 23:14:29 +02:00
2021-09-06 02:31:27 +02:00
foreach (Setting::get('folders') as $folder) {
$this->resize($folder['folder']);
2019-09-17 23:14:29 +02:00
}
}
/**
* Get the console command arguments.
* @return array
*/
protected function getArguments()
{
return [];
}
/**
* Get the console command options.
* @return array
*/
protected function getOptions()
{
return [];
}
}