Rev 290 | Ir a la última revisión | 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\UserMapper;use LeadersLinked\Mapper\CompanyMapper;use LeadersLinked\Mapper\CompanyUserMapper;use LeadersLinked\Model\User;use LeadersLinked\Model\UserType;use LeadersLinked\Model\CompanyUser;use Laminas\Mvc\I18n\Translator;use LeadersLinked\Cache\CacheInterface;use LeadersLinked\Library\S3Files;use LeadersLinked\Mapper\FeedMapper;use LeadersLinked\Library\Storage;class SendDataToS3Command 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();}private function getDirContents($dir, &$results = array()) {$files = scandir($dir);foreach ($files as $key => $value) {$path = realpath($dir . DIRECTORY_SEPARATOR . $value);if (!is_dir($path)) {$results[] = $path;} else if ($value != "." && $value != "..") {$this->getDirContents($path, $results);$results[] = $path;}}return $results;}protected function execute(InputInterface $input, OutputInterface $output) : int{$output->writeln('Inicializando el S3');$storage = Storage::getInstance($this->config);$paths = [$this->config['leaderslinked.fullpath.chat'] => $this->config['leaderslinked.minio.fullpath_chat'],$this->config['leaderslinked.fullpath.group'] => $this->config['leaderslinked.minio.fullpath_group'],$this->config['leaderslinked.fullpath.user'] => $this->config['leaderslinked.minio.fullpath_user'],$this->config['leaderslinked.fullpath.image'] => $this->config['leaderslinked.minio.fullpath_image'],$this->config['leaderslinked.fullpath.job'] => $this->config['leaderslinked.minio.fullpath_job'],$this->config['leaderslinked.fullpath.company'] => $this->config['leaderslinked.minio.fullpath_company'],$this->config['leaderslinked.fullpath.feed'] => $this->config['leaderslinked.minio.fullpath_feed'],$this->config['leaderslinked.fullpath.post'] => $this->config['leaderslinked.minio.fullpath_post'],$this->config['leaderslinked.fullpath.microlearning_topic'] => $this->config['leaderslinked.minio.fullpath_microlearning_topic'],$this->config['leaderslinked.fullpath.microlearning_capsule'] => $this->config['leaderslinked.minio.fullpath_microlearning_capsule'],$this->config['leaderslinked.fullpath.microlearning_slide'] => $this->config['leaderslinked.minio.fullpath_microlearning_slide'],$this->config['leaderslinked.fullpath.job_description'] => $this->config['leaderslinked.minio.fullpath_job_description'],$this->config['leaderslinked.fullpath.self_evaluation'] => $this->config['leaderslinked.minio.fullpath_self_evaluation'],$this->config['leaderslinked.fullpath.performance_evaluation'] => $this->config['leaderslinked.minio.fullpath_performance_evaluation'],$this->config['leaderslinked.fullpath.recruitment_selection'] => $this->config['leaderslinked.minio.fullpath_recruitment_selection'],$this->config['leaderslinked.fullpath.planning_objectives_and_goals'] => $this->config['leaderslinked.minio.fullpath_planning_objectives_and_goals'],$this->config['leaderslinked.fullpath.message'] => $this->config['leaderslinked.minio.fullpath_message'],$this->config['leaderslinked.fullpath.survey'] => $this->config['leaderslinked.minio.fullpath_survey'],$this->config['leaderslinked.fullpath.network'] => $this->config['leaderslinked.minio.fullpath_network'],$this->config['leaderslinked.fullpath.daily_pulse'] => $this->config['leaderslinked.minio.fullpath_daily_pulse'],$this->config['leaderslinked.fullpath.engagement_reward'] => $this->config['leaderslinked.minio.fullpath_engagement_reward'],$this->config['leaderslinked.fullpath.knowledge_area'] => $this->config['leaderslinked.minio.fullpath_knowledge_area'],$this->config['leaderslinked.fullpath.my_coach'] => $this->config['leaderslinked.minio.fullpath_my_coach'],];$output->writeln('Leyendo el directorio de storage ');$directory = 'data/storage';$records = $this->getDirContents($directory);foreach($records as $filepath){if(!file_exists($filepath)) {continue;}if(is_dir($filepath) || !is_readable($filepath)) {continue;}$s = explode('data/storage', $filepath);$s3Filename = basename($filepath);$s3Filepath = $s[1];$s3Filepath = trim(str_replace('/' . $s3Filename, '', $s3Filepath));foreach($paths as $key => $value){$key = str_replace('data/storage', '', $key);$s3Filepath = str_replace($key, $value . '/', $s3Filepath );}if(empty($s3Filepath)) {$filename = $s3Filename;} else {$filename = $s3Filepath . '/' . $s3Filename;}$output->writeln('Comprobando el archivo : ' . $filename);if($storage->objectExist($filename)) {$output->writeln('Existe el archivo en el S3 : ' . $filename);} else {$output->writeln('Grabando el archivo : ' . $filename);$storage->putObject($filename, $filepath);}}$output->writeln('Fin del proceso');return 0;}}