Proyectos de Subversion LeadersLinked - Services

Rev

Rev 290 | Ir a la última revisión | | Ultima modificación | Ver Log |

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