Proyectos de Subversion LeadersLinked - Services

Rev

Rev 333 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
283 www 1
<?php
345 www 2
declare(strict_types = 1);
283 www 3
namespace LeadersLinked\Command;
4
 
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Mapper\UserMapper;
11
use LeadersLinked\Mapper\CompanyMapper;
12
use LeadersLinked\Mapper\CompanyUserMapper;
13
use LeadersLinked\Model\User;
14
use LeadersLinked\Model\UserType;
15
use LeadersLinked\Model\CompanyUser;
16
use Laminas\Mvc\I18n\Translator;
17
use LeadersLinked\Cache\CacheInterface;
18
use LeadersLinked\Mapper\FeedMapper;
19
use LeadersLinked\Library\Storage;
20
 
21
class SendDataToS3Command extends Command
22
{
345 www 23
 
283 www 24
    /**
25
     *
26
     * @var \Laminas\Db\Adapter\AdapterInterface
27
     */
28
    private $adapter;
345 www 29
 
283 www 30
    /**
31
     *
32
     * @var \LeadersLinked\Cache\CacheInterface
33
     */
34
    private $cache;
35
 
36
    /**
37
     *
38
     * @var \Laminas\Log\LoggerInterface
39
     */
40
    private $logger;
41
 
42
    /**
43
     *
44
     * @var array
45
     */
46
    private $config;
345 www 47
 
283 www 48
    /**
345 www 49
     *
283 www 50
     * @var \Laminas\Mvc\I18n\Translator
51
     */
52
    private $translator;
345 www 53
 
283 www 54
    /**
55
     *
56
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
57
     * @param \LeadersLinked\Cache\CacheInterface $cache
345 www 58
     * @param
59
     *            \Laminas\Log\LoggerInterface
283 www 60
     * @param array $config
61
     * @param \Laminas\Mvc\I18n\Translator $translator
62
     */
345 www 63
    public function __construct($adapter, $cache, $logger, $config, $translator)
283 www 64
    {
345 www 65
        $this->adapter = $adapter;
66
        $this->cache = $cache;
67
        $this->logger = $logger;
68
        $this->config = $config;
69
        $this->translator = $translator;
70
 
283 www 71
        parent::__construct();
72
    }
73
 
345 www 74
    private function getDirContents($dir, &$results = array())
75
    {
283 www 76
        $files = scandir($dir);
345 www 77
 
283 www 78
        foreach ($files as $key => $value) {
79
            $path = realpath($dir . DIRECTORY_SEPARATOR . $value);
345 www 80
            if (! is_dir($path)) {
283 www 81
                $results[] = $path;
82
            } else if ($value != "." && $value != "..") {
83
                $this->getDirContents($path, $results);
84
                $results[] = $path;
85
            }
86
        }
345 www 87
 
283 www 88
        return $results;
89
    }
345 www 90
 
91
    protected function execute(InputInterface $input, OutputInterface $output): int
283 www 92
    {
93
        $output->writeln('Inicializando el S3');
345 www 94
 
333 www 95
        $storage = Storage::getInstance($this->config, $this->adapter);
345 www 96
 
283 www 97
        $paths = [
345 www 98
            $this->config['leaderslinked.fullpath.chat'] => $this->config['leaderslinked.storage.fullpath_chat'],
99
            $this->config['leaderslinked.fullpath.group'] => $this->config['leaderslinked.storage.fullpath_group'],
100
            $this->config['leaderslinked.fullpath.user'] => $this->config['leaderslinked.storage.fullpath_user'],
101
            $this->config['leaderslinked.fullpath.image'] => $this->config['leaderslinked.storage.fullpath_image'],
102
            $this->config['leaderslinked.fullpath.job'] => $this->config['leaderslinked.storage.fullpath_job'],
103
            $this->config['leaderslinked.fullpath.company'] => $this->config['leaderslinked.storage.fullpath_company'],
104
            $this->config['leaderslinked.fullpath.feed'] => $this->config['leaderslinked.storage.fullpath_feed'],
105
            $this->config['leaderslinked.fullpath.post'] => $this->config['leaderslinked.storage.fullpath_post'],
106
            $this->config['leaderslinked.fullpath.microlearning_topic'] => $this->config['leaderslinked.storage.fullpath_microlearning_topic'],
107
            $this->config['leaderslinked.fullpath.microlearning_capsule'] => $this->config['leaderslinked.storage.fullpath_microlearning_capsule'],
108
            $this->config['leaderslinked.fullpath.microlearning_slide'] => $this->config['leaderslinked.storage.fullpath_microlearning_slide'],
109
            $this->config['leaderslinked.fullpath.job_description'] => $this->config['leaderslinked.storage.fullpath_job_description'],
110
            $this->config['leaderslinked.fullpath.self_evaluation'] => $this->config['leaderslinked.storage.fullpath_self_evaluation'],
111
            $this->config['leaderslinked.fullpath.performance_evaluation'] => $this->config['leaderslinked.storage.fullpath_performance_evaluation'],
112
            $this->config['leaderslinked.fullpath.recruitment_selection'] => $this->config['leaderslinked.storage.fullpath_recruitment_selection'],
113
            $this->config['leaderslinked.fullpath.planning_objectives_and_goals'] => $this->config['leaderslinked.storage.fullpath_planning_objectives_and_goals'],
114
            $this->config['leaderslinked.fullpath.message'] => $this->config['leaderslinked.storage.fullpath_message'],
115
            $this->config['leaderslinked.fullpath.survey'] => $this->config['leaderslinked.storage.fullpath_survey'],
116
            $this->config['leaderslinked.fullpath.network'] => $this->config['leaderslinked.storage.fullpath_network'],
117
            $this->config['leaderslinked.fullpath.daily_pulse'] => $this->config['leaderslinked.storage.fullpath_daily_pulse'],
118
            $this->config['leaderslinked.fullpath.engagement_reward'] => $this->config['leaderslinked.storage.fullpath_engagement_reward'],
119
            $this->config['leaderslinked.fullpath.knowledge_area'] => $this->config['leaderslinked.storage.fullpath_knowledge_area'],
120
            $this->config['leaderslinked.fullpath.my_coach'] => $this->config['leaderslinked.storage.fullpath_my_coach']
283 www 121
        ];
122
 
123
        $output->writeln('Leyendo el directorio de storage ');
124
 
125
        $directory = 'data/storage';
126
        $records = $this->getDirContents($directory);
345 www 127
        foreach ($records as $filepath) {
128
 
129
            if (! file_exists($filepath)) {
283 www 130
                continue;
131
            }
345 www 132
 
133
            if (is_dir($filepath) || ! is_readable($filepath)) {
283 www 134
                continue;
135
            }
345 www 136
 
283 www 137
            $s = explode('data/storage', $filepath);
345 www 138
 
283 www 139
            $s3Filename = basename($filepath);
140
            $s3Filepath = $s[1];
141
            $s3Filepath = trim(str_replace('/' . $s3Filename, '', $s3Filepath));
345 www 142
 
143
            foreach ($paths as $key => $value) {
283 www 144
                $key = str_replace('data/storage', '', $key);
345 www 145
                $s3Filepath = str_replace($key, $value . '/', $s3Filepath);
283 www 146
            }
345 www 147
 
148
            if (empty($s3Filepath)) {
149
                $filename = $s3Filename;
283 www 150
            } else {
151
                $filename = $s3Filepath . '/' . $s3Filename;
152
            }
345 www 153
 
154
            echo 'filename = ' . $filename . "\r\n";
155
            echo 'filepath = ' . $filepath . "\r\n";
156
            exit();
157
 
283 www 158
            $output->writeln('Comprobando el archivo : ' . $filename);
345 www 159
 
160
            if ($storage->objectExist($filename)) {
283 www 161
                $output->writeln('Existe el archivo en el S3 : ' . $filename);
162
            } else {
345 www 163
 
283 www 164
                $output->writeln('Grabando el archivo : ' . $filename);
165
                $storage->putObject($filename, $filepath);
166
            }
345 www 167
        }
283 www 168
 
345 www 169
        $output->writeln('Fin del proceso');
283 www 170
 
171
        return 0;
172
    }
173
}