Completed
Push — feature/add-cli-installers ( 1b9f9b...f84756 )
by Steven
13:07
created

MagentoProject::showCredentials()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 11
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
1
<?php namespace Magestead\Installers;
2
3
use Magestead\Command\ProcessCommand;
4
use Symfony\Component\Console\Helper\Table;
5
use Symfony\Component\Console\Output\OutputInterface;
6
7
class MagentoProject
8
{
9
    /**
10
     * MagentoProject constructor.
11
     * @param array $options
12
     * @param $projectPath
13
     * @param OutputInterface $output
14
     */
15
    public function __construct(array $options, $projectPath, OutputInterface $output)
16
    {
17
        $output->writeln('<info>Installing Magento with Composer</info>');
18
        $this->composerInstall($projectPath, $output);
19
20
        $output->writeln('<info>Installing Magento Software</info>');
21
        $this->installMagento($options, $projectPath, $output);
22
23
        $output->writeln('<info>Finalising Setup</info>');
24
        $this->finaliseSetup($options, $projectPath, $output);
25
        $this->showCredentials($options, $output);
26
    }
27
28
    /**
29
     * @param array $options
30
     * @param $projectPath
31
     * @param $output
32
     */
33 View Code Duplication
    protected function installMagento(array $options, $projectPath, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $locale = $options['magestead']['apps']['mba_12345']['locale'];
36
        $db_name = $options['magestead']['apps']['mba_12345']['db_name'];
37
        $base_url = $options['magestead']['apps']['mba_12345']['base_url'];
38
        $default_currency = $options['magestead']['apps']['mba_12345']['default_currency'];
39
40
        $install = 'vagrant ssh -c \'cd /var/www/public; php -f install.php -- \
41
--license_agreement_accepted "yes" \
42
--locale "' . $locale . '" \
43
--timezone "Europe/London" \
44
--default_currency "' . $default_currency . '" \
45
--db_host "localhost" \
46
--db_name "' . $db_name . '" \
47
--db_user "magestead" \
48
--db_pass "vagrant" \
49
--session_save "db" \
50
--url "http://' . $base_url . '/" \
51
--use_rewrites "yes" \
52
--skip_url_validation "yes" \
53
--use_secure "no" \
54
--use_secure_admin "no" \
55
--secure_base_url "http://' . $base_url . '/" \
56
--admin_firstname "RichDynamix" \
57
--admin_lastname "Magestead" \
58
--admin_email "[email protected]" \
59
--admin_username "admin" \
60
--admin_password "password123"\' ';
61
62
        new ProcessCommand($install, $projectPath, $output);
63
64
        $this->configureRedis($projectPath);
65
        $this->setPermissions($projectPath, $output);
66
        $this->installMagerun($projectPath, $output);
67
    }
68
69
    /**
70
     * @param $projectPath
71
     * @param OutputInterface $output
72
     */
73
    protected function setPermissions($projectPath, OutputInterface $output)
74
    {
75
        $command = 'vagrant ssh -c \'cd /var/www/public; sudo find . -type f -exec chmod 400 {} \;\'';
76
        $output->writeln('<comment>Setting Files Permissions</comment>');
77
        new ProcessCommand($command, $projectPath, $output);
78
79
        $command = 'vagrant ssh -c \'cd /var/www/public; sudo find . -type d -exec chmod 500 {} \;\'';
80
        $output->writeln('<comment>Setting Folder Permissions</comment>');
81
        new ProcessCommand($command, $projectPath, $output);
82
83
        $command = 'vagrant ssh -c \'cd /var/www/public; sudo find var/ -type f -exec chmod 600 {} \;\'';
84
        $output->writeln('<comment>Setting "var" Files Permissions</comment>');
85
        new ProcessCommand($command, $projectPath, $output);
86
87
        $command = 'vagrant ssh -c \'cd /var/www/public; sudo find media/ -type f -exec chmod 600 {} \;\'';
88
        $output->writeln('<comment>Setting "media" Files Permissions</comment>');
89
        new ProcessCommand($command, $projectPath, $output);
90
91
        $command = 'vagrant ssh -c \'cd /var/www/public; sudo find var/ -type d -exec chmod 700 {} \;\'';
92
        $output->writeln('<comment>Setting "var" Folder Permissions</comment>');
93
        new ProcessCommand($command, $projectPath, $output);
94
95
        $command = 'vagrant ssh -c \'cd /var/www/public; sudo find media/ -type d -exec chmod 700 {} \;\'';
96
        $output->writeln('<comment>Setting "media" Folder Permissions</comment>');
97
        new ProcessCommand($command, $projectPath, $output);
98
99
        $command = 'vagrant ssh -c \'cd /var/www/public; sudo chmod 700 includes;\'';
100
        $output->writeln('<comment>Setting "includes" Permissions</comment>');
101
        new ProcessCommand($command, $projectPath, $output);
102
103
        $command = 'vagrant ssh -c \'cd /var/www/public; sudo chmod 600 includes/config.php;\'';
104
        $output->writeln('<comment>Setting "includes/config.php" Permissions</comment>');
105
        new ProcessCommand($command, $projectPath, $output);
106
    }
107
108
    /**
109
     * @param $projectPath
110
     * @param OutputInterface $output
111
     */
112 View Code Duplication
    protected function installMagerun($projectPath, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    {
114
        $command = 'vagrant ssh -c \'cd /var/www/bin; sudo wget https://files.magerun.net/n98-magerun.phar;\'';
115
        $output->writeln('<info>Downloading Magerun</info>');
116
        new ProcessCommand($command, $projectPath, $output);
117
118
        $command = 'vagrant ssh -c \'cd /var/www/bin; sudo chmod +x ./n98-magerun.phar;\'';
119
        $output->writeln('<comment>Setting Magerun Permissions</comment>');
120
        new ProcessCommand($command, $projectPath, $output);
121
    }
122
123
    protected function finaliseSetup($options, $projectPath, OutputInterface $output)
124
    {
125
        $command = 'vagrant ssh -c \'cd /var/www/public; ../bin/n98-magerun.phar index:reindex:all;\'';
126
        $output->writeln('<comment>Reindexing Tables</comment>');
127
        new ProcessCommand($command, $projectPath, $output);
128
129
        $command = 'vagrant ssh -c \'cd /var/www/public; ../bin/n98-magerun.phar cache:enable;\'';
130
        $output->writeln('<comment>Enabling All Cache</comment>');
131
        new ProcessCommand($command, $projectPath, $output);
132
133
        $command = 'vagrant ssh -c \'cd /var/www/public; ../bin/n98-magerun.phar cache:flush;\'';
134
        $output->writeln('<comment>Flushing All Cache</comment>');
135
        new ProcessCommand($command, $projectPath, $output);
136
137
        $this->processVcs($options, $projectPath, $output);
138
139
        $command = 'vagrant ssh -c \'cd /var/www/public; ../bin/n98-magerun.phar sys:check;\'';
140
        $output->writeln('<comment>System Check</comment>');
141
        new ProcessCommand($command, $projectPath, $output);
142
    }
143
144
    /**
145
     * @param array $options
146
     * @param OutputInterface $output
147
     */
148 View Code Duplication
    protected function showCredentials(array $options, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
    {
150
        $output->writeln('<info>SUCCESS: Magestead has finished installing Magento!</info>');
151
        $table = new Table($output);
152
        $table
153
            ->setHeaders(['Username', 'Password', 'Base URL'])
154
            ->setRows([
155
                ['admin', 'password123', $options['magestead']['apps']['mba_12345']['base_url']],
156
            ]);
157
        $table->render();
158
    }
159
160
    protected function processVcs(array $options, $projectPath, OutputInterface $output)
161
    {
162
        if (!empty($options['repo_url'])) {
163
            copy($projectPath . "/puphpet/magestead/magento/stubs/gitignore.tmp", $projectPath . "/.gitignore");
164
            $command = 'git init; git remote add origin ' . $options['repo_url'];
165
            $output->writeln('<info>Configuring GIT repo</info>');
166
            new ProcessCommand($command, $projectPath, $output);
167
168
            $add = 'git add -A';
169
            $output->writeln('<comment>Adding files to repo</comment>');
170
            new ProcessCommand($add, $projectPath, $output);
171
172
            $commit = "git commit -m 'Initial commit'";
173
            $output->writeln('<comment>Committing files to repo</comment>');
174
            new ProcessCommand($commit, $projectPath, $output);
175
        }
176
    }
177
178
    /**
179
     * @param $projectPath
180
     * @param OutputInterface $output
181
     */
182
    protected function composerInstall($projectPath, OutputInterface $output)
183
    {
184
        copy($projectPath . "/puphpet/magestead/magento/stubs/composer.tmp", $projectPath . "/composer.json");
185
        new ProcessCommand('composer install', $projectPath, $output);
186
    }
187
188
    /**
189
     * @param $projectPath
190
     */
191
    protected function configureRedis($projectPath)
192
    {
193
        $this->updateConfigXml($projectPath);
194
        $this->activateModule($projectPath);
195
    }
196
197
    /**
198
     * @param $projectPath
199
     */
200
    protected function updateConfigXml($projectPath)
201
    {
202
        $localFile = '/public/app/etc/local.xml';
203
        $localXml = file_get_contents($projectPath . $localFile);
204
205
        $config = new \SimpleXMLElement($localXml);
206
        $config->global[0]->redis_session[0]->host = '127.0.0.1';
207
        $config->global[0]->redis_session[0]->port = '6379';
208
        $config->global[0]->redis_session[0]->password = '';
209
        $config->global[0]->redis_session[0]->timeout = '2.5';
210
        $config->global[0]->redis_session[0]->persistent = '';
211
        $config->global[0]->redis_session[0]->db = '';
212
        $config->global[0]->redis_session[0]->compression_threshold = '2048';
213
        $config->global[0]->redis_session[0]->compression_lib = 'gzip';
214
        $config->global[0]->redis_session[0]->log_level = '1';
215
        $config->global[0]->redis_session[0]->max_concurrency = '6';
216
        $config->global[0]->redis_session[0]->break_after_frontend = '5';
217
        $config->global[0]->redis_session[0]->break_after_adminhtml = '30';
218
        $config->global[0]->redis_session[0]->first_lifetime = '600';
219
        $config->global[0]->redis_session[0]->bot_first_lifetime = '60';
220
        $config->global[0]->redis_session[0]->bot_lifetime = '7200';
221
        $config->global[0]->redis_session[0]->disable_locking = '0';
222
        $config->global[0]->redis_session[0]->min_lifetime = '60';
223
        $config->global[0]->redis_session[0]->max_lifetime = '2592000';
224
225
        file_put_contents($projectPath . $localFile, $config->asXML());
226
    }
227
228
    /**
229
     * @param $projectPath
230
     */
231
    protected function activateModule($projectPath)
232
    {
233
        $moduleFile = '/public/app/etc/modules/Cm_RedisSession.xml';
234
        $moduleXml = file_get_contents($projectPath . $moduleFile);
235
        $config = new \SimpleXMLElement($moduleXml);
236
        $config->modules[0]->Cm_RedisSession[0]->active = 'true';
237
        file_put_contents($projectPath . $moduleFile, $config->asXML());
238
    }
239
}