64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
class GenerateMediaFiles extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'media:generate {amount?} {--user=} {--width=} {--height=} {--category=}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Generate media files';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$args = [
|
|
'imageCategory' => $this->option('category'),
|
|
'imageHeight' => (int)$this->option('height'),
|
|
'imageWidth' => (int)$this->option('width'),
|
|
'userId' => $this->option('user')
|
|
];
|
|
$args = collect($args)->filter(function($value, $key){
|
|
return $value !== null && $value !== 0;
|
|
})->all();
|
|
|
|
$amount = $this->argument('amount');
|
|
if(!$amount) $amount = 1;
|
|
|
|
try {
|
|
for($i = 0; $i < $amount; $i++) {
|
|
$mediaFile = app(\App\Services\MediaFileFactoryService::class)->create($args);
|
|
$this->info("Media file {$mediaFile->id} is generated");
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
|
|
}
|
|
}
|