Rev 345 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types = 1);namespace LeadersLinked\Command;use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Output\OutputInterface;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Log\LoggerInterface;use LeadersLinked\Mapper\VideoConvertMapper;use LeadersLinked\Model\VideoConvert;use Laminas\Mvc\I18n\Translator;use LeadersLinked\Cache\CacheInterface;use LeadersLinked\Library\Storage;class ProcessQueueVideoConvertCommand extends Command{/**** @var \Laminas\Db\Adapter\AdapterInterface*/private $adapter;/**** @var \LeadersLinked\Cache\CacheInterface*/private $cache;/**** @var \Laminas\Log\LoggerInterface*/private $logger;/**** @var array*/private $config;/**** @var \Laminas\Mvc\I18n\Translator*/private $translator;/**** @param \Laminas\Db\Adapter\AdapterInterface $adapter* @param \LeadersLinked\Cache\CacheInterface $cache* @param* \Laminas\Log\LoggerInterface* @param array $config* @param \Laminas\Mvc\I18n\Translator $translator*/public function __construct($adapter, $cache, $logger, $config, $translator){$this->adapter = $adapter;$this->cache = $cache;$this->logger = $logger;$this->config = $config;$this->translator = $translator;parent::__construct();}protected function execute(InputInterface $input, OutputInterface $output): int{$checkExists = true;$videos_procesados = 0;$videos_ignorados = 0;$videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);$videos = $videoConvertMapper->fetchBatch();$storage = Storage::getInstance($this->config, $this->adapter);foreach ($videos as $video) {if ($video->type == VideoConvert::TYPE_FEED) {$targe_path = $storage->getPathFeed();} else if ($video->type == VideoConvert::TYPE_MICRO_LEARNING_SLIDES) {$targe_path = $storage->getPathMicrolearningSlide();} else if ($video->type == VideoConvert::TYPE_MEDIA) {$targe_path = $storage->getPathMedia();} else if ($video->type == VideoConvert::TYPE_HABIT_CONTENT) {$targe_path = $storage->getPathHabitContent();} else {$targe_path = '';}if (empty($targe_path)) {$videos_ignorados ++;$videoConvertMapper->delete($video);continue;}$directory = $storage->getDirectoryFromDisk($targe_path, $video->uuid);$currentfile = $directory . DIRECTORY_SEPARATOR . $video->filename;$posterfile = $directory . DIRECTORY_SEPARATOR . substr($video->filename, 0, strrpos($video->filename, '.')) . '.jpg';if (! file_exists($currentfile)) {$videos_ignorados ++;$videoConvertMapper->delete($video);continue;}$s = explode('.', $video->filename);$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $s[0] . '-tmp.' . $s[1];$newfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $video->filename;if (! @copy($currentfile, $tmpfile)) {$videos_ignorados ++;$videoConvertMapper->delete($video);continue;}if (file_exists($tmpfile)) {if (! file_exists($posterfile)) {\LeadersLinked\Library\Storage::extractPosterFromVideo($tmpfile, $posterfile);}$cmd = "/usr/bin/ffmpeg -y -i $tmpfile -preset medium -crf 24 -codec:v libx264 $newfile";$output->writeln("command : $cmd");exec($cmd);@copy($newfile, $currentfile);@unlink($tmpfile);@unlink($newfile);$videos_procesados ++;$videoConvertMapper->delete($video);} else {$videoConvertMapper->delete($video);$output->writeln("El video no existe : " . $video->filename);$videos_ignorados ++;}}$output->writeln('Videos procesados:' . $videos_procesados);$output->writeln('Videos ignorados:' . $videos_ignorados);$output->writeln('Fin del proceso de la cola de Videos');return 0;}}