|
1
|
|
|
<?php namespace Magestead\Installers; |
|
2
|
|
|
|
|
3
|
|
|
use Magestead\Helper\HostsPluginChecker; |
|
4
|
|
|
use Magestead\Service\Notification; |
|
5
|
|
|
use Magestead\Service\VersionControl; |
|
6
|
|
|
use Magestead\Command\ProcessCommand; |
|
7
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
|
8
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use Symfony\Component\Yaml\Dumper; |
|
11
|
|
|
use Symfony\Component\Yaml\Exception\ParseException; |
|
12
|
|
|
use Symfony\Component\Yaml\Parser; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class MagentoProject |
|
16
|
|
|
* @package Magestead\Installers |
|
17
|
|
|
*/ |
|
18
|
|
|
class MagentoProject |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* MagentoProject constructor. |
|
22
|
|
|
* @param array $options |
|
23
|
|
|
* @param array $config |
|
24
|
|
|
* @param $projectPath |
|
25
|
|
|
* @param OutputInterface $output |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(array $options, array $config, $projectPath, OutputInterface $output) |
|
28
|
|
|
{ |
|
29
|
|
|
$output->writeln('<info>Installing Magento with Composer</info>'); |
|
30
|
|
|
$this->composerInstall($projectPath, $output); |
|
31
|
|
|
|
|
32
|
|
|
$output->writeln('<info>Installing Magento Software</info>'); |
|
33
|
|
|
$this->installMagento($config, $projectPath, $output); |
|
34
|
|
|
|
|
35
|
|
|
$this->configureTestSuites($options, $projectPath, $output); |
|
36
|
|
|
|
|
37
|
|
|
$output->writeln('<info>Finalising Setup</info>'); |
|
38
|
|
|
$this->finaliseSetup($options, $projectPath, $output); |
|
39
|
|
|
$this->showCredentials($config, $output); |
|
40
|
|
|
|
|
41
|
|
|
Notification::send('Magento was successfully installed!'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param array $options |
|
46
|
|
|
* @param $projectPath |
|
47
|
|
|
* @param $output |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function installMagento(array $options, $projectPath, OutputInterface $output) |
|
50
|
|
|
{ |
|
51
|
|
|
$locale = $options['magestead']['apps']['mba_12345']['locale']; |
|
52
|
|
|
$db_name = $options['magestead']['apps']['mba_12345']['db_name']; |
|
53
|
|
|
$base_url = $options['magestead']['apps']['mba_12345']['base_url']; |
|
54
|
|
|
$default_currency = $options['magestead']['apps']['mba_12345']['default_currency']; |
|
55
|
|
|
|
|
56
|
|
|
$install = 'vagrant ssh -c \'cd /var/www/public; php -f install.php -- \ |
|
57
|
|
|
--license_agreement_accepted "yes" \ |
|
58
|
|
|
--locale "' . $locale . '" \ |
|
59
|
|
|
--timezone "Europe/London" \ |
|
60
|
|
|
--default_currency "' . $default_currency . '" \ |
|
61
|
|
|
--db_host "localhost" \ |
|
62
|
|
|
--db_name "' . $db_name . '" \ |
|
63
|
|
|
--db_user "magestead" \ |
|
64
|
|
|
--db_pass "vagrant" \ |
|
65
|
|
|
--session_save "db" \ |
|
66
|
|
|
--url "http://' . $base_url . '/" \ |
|
67
|
|
|
--use_rewrites "yes" \ |
|
68
|
|
|
--skip_url_validation "yes" \ |
|
69
|
|
|
--use_secure "no" \ |
|
70
|
|
|
--use_secure_admin "no" \ |
|
71
|
|
|
--secure_base_url "http://' . $base_url . '/" \ |
|
72
|
|
|
--admin_firstname "RichDynamix" \ |
|
73
|
|
|
--admin_lastname "Magestead" \ |
|
74
|
|
|
--admin_email "[email protected]" \ |
|
75
|
|
|
--admin_username "admin" \ |
|
76
|
|
|
--admin_password "password123"\' '; |
|
77
|
|
|
|
|
78
|
|
|
new ProcessCommand($install, $projectPath, $output); |
|
79
|
|
|
|
|
80
|
|
|
$this->configureRedis($projectPath); |
|
81
|
|
|
$this->setPermissions($projectPath, $output); |
|
82
|
|
|
$this->installMagerun($projectPath, $output); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param $projectPath |
|
87
|
|
|
* @param OutputInterface $output |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function setPermissions($projectPath, OutputInterface $output) |
|
90
|
|
|
{ |
|
91
|
|
|
// $command = 'vagrant ssh -c \'cd /var/www/public; sudo find . -type f -exec chmod 400 {} \;\''; |
|
|
|
|
|
|
92
|
|
|
// $output->writeln('<comment>Setting Files Permissions</comment>'); |
|
93
|
|
|
// new ProcessCommand($command, $projectPath, $output); |
|
94
|
|
|
// |
|
95
|
|
|
// $command = 'vagrant ssh -c \'cd /var/www/public; sudo find . -type d -exec chmod 500 {} \;\''; |
|
96
|
|
|
// $output->writeln('<comment>Setting Folder Permissions</comment>'); |
|
97
|
|
|
// new ProcessCommand($command, $projectPath, $output); |
|
98
|
|
|
|
|
99
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; sudo find var/ -type f -exec chmod 600 {} \;\''; |
|
100
|
|
|
$output->writeln('<comment>Setting "var" Files Permissions</comment>'); |
|
101
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
102
|
|
|
|
|
103
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; sudo find media/ -type f -exec chmod 600 {} \;\''; |
|
104
|
|
|
$output->writeln('<comment>Setting "media" Files Permissions</comment>'); |
|
105
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
106
|
|
|
|
|
107
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; sudo find var/ -type d -exec chmod 700 {} \;\''; |
|
108
|
|
|
$output->writeln('<comment>Setting "var" Folder Permissions</comment>'); |
|
109
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
110
|
|
|
|
|
111
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; sudo find media/ -type d -exec chmod 700 {} \;\''; |
|
112
|
|
|
$output->writeln('<comment>Setting "media" Folder Permissions</comment>'); |
|
113
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
114
|
|
|
|
|
115
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; sudo chmod 700 includes;\''; |
|
116
|
|
|
$output->writeln('<comment>Setting "includes" Permissions</comment>'); |
|
117
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
118
|
|
|
|
|
119
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; sudo chmod 600 includes/config.php;\''; |
|
120
|
|
|
$output->writeln('<comment>Setting "includes/config.php" Permissions</comment>'); |
|
121
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param $projectPath |
|
126
|
|
|
* @param OutputInterface $output |
|
127
|
|
|
*/ |
|
128
|
|
|
protected function installMagerun($projectPath, OutputInterface $output) |
|
129
|
|
|
{ |
|
130
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/bin; sudo wget https://files.magerun.net/n98-magerun.phar;\''; |
|
131
|
|
|
$output->writeln('<info>Downloading Magerun</info>'); |
|
132
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
133
|
|
|
|
|
134
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/bin; sudo chmod +x ./n98-magerun.phar;\''; |
|
135
|
|
|
$output->writeln('<comment>Setting Magerun Permissions</comment>'); |
|
136
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param array $options |
|
141
|
|
|
* @param $projectPath |
|
142
|
|
|
* @param OutputInterface $output |
|
143
|
|
|
*/ |
|
144
|
|
|
protected function finaliseSetup(array $options, $projectPath, OutputInterface $output) |
|
145
|
|
|
{ |
|
146
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; ../bin/n98-magerun.phar index:reindex:all;\''; |
|
147
|
|
|
$output->writeln('<comment>Reindexing Tables</comment>'); |
|
148
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
149
|
|
|
|
|
150
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; ../bin/n98-magerun.phar cache:enable;\''; |
|
151
|
|
|
$output->writeln('<comment>Enabling All Cache</comment>'); |
|
152
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
153
|
|
|
|
|
154
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; ../bin/n98-magerun.phar cache:flush;\''; |
|
155
|
|
|
$output->writeln('<comment>Flushing All Cache</comment>'); |
|
156
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
157
|
|
|
|
|
158
|
|
|
$this->processVcs($options, $projectPath, $output); |
|
159
|
|
|
|
|
160
|
|
|
$command = 'vagrant ssh -c \'cd /var/www/public; ../bin/n98-magerun.phar sys:check;\''; |
|
161
|
|
|
$output->writeln('<comment>System Check</comment>'); |
|
162
|
|
|
new ProcessCommand($command, $projectPath, $output); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @param array $options |
|
167
|
|
|
* @param OutputInterface $output |
|
168
|
|
|
*/ |
|
169
|
|
View Code Duplication |
protected function showCredentials(array $options, OutputInterface $output) |
|
|
|
|
|
|
170
|
|
|
{ |
|
171
|
|
|
$output->writeln('<info>SUCCESS: Magestead has finished installing Magento!</info>'); |
|
172
|
|
|
$table = new Table($output); |
|
173
|
|
|
$table |
|
174
|
|
|
->setHeaders(['Username', 'Password', 'Base URL']) |
|
175
|
|
|
->setRows([ |
|
176
|
|
|
['admin', 'password123', $options['magestead']['apps']['mba_12345']['base_url']], |
|
177
|
|
|
]); |
|
178
|
|
|
$table->render(); |
|
179
|
|
|
|
|
180
|
|
|
HostsPluginChecker::verify($options, $output); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param array $options |
|
185
|
|
|
* @param $projectPath |
|
186
|
|
|
* @param OutputInterface $output |
|
187
|
|
|
* @return VersionControl |
|
188
|
|
|
*/ |
|
189
|
|
View Code Duplication |
protected function processVcs(array $options, $projectPath, OutputInterface $output) |
|
|
|
|
|
|
190
|
|
|
{ |
|
191
|
|
|
if (!empty($options['repo_url'])) { |
|
192
|
|
|
copy($projectPath . "/puphpet/magestead/magento/stubs/gitignore.tmp", $projectPath . "/.gitignore"); |
|
193
|
|
|
return new VersionControl($options['repo_url'], $projectPath, $output); |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param $projectPath |
|
199
|
|
|
* @param OutputInterface $output |
|
200
|
|
|
*/ |
|
201
|
|
|
protected function composerInstall($projectPath, OutputInterface $output) |
|
202
|
|
|
{ |
|
203
|
|
|
copy($projectPath . "/puphpet/magestead/magento/stubs/composer.tmp", $projectPath . "/composer.json"); |
|
204
|
|
|
new ProcessCommand('composer install', $projectPath, $output); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* @param $projectPath |
|
209
|
|
|
*/ |
|
210
|
|
|
protected function configureRedis($projectPath) |
|
211
|
|
|
{ |
|
212
|
|
|
$this->updateConfigXml($projectPath); |
|
213
|
|
|
$this->activateModule($projectPath); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param $projectPath |
|
218
|
|
|
*/ |
|
219
|
|
|
protected function updateConfigXml($projectPath) |
|
220
|
|
|
{ |
|
221
|
|
|
$localFile = '/public/app/etc/local.xml'; |
|
222
|
|
|
$localXml = file_get_contents($projectPath . $localFile); |
|
223
|
|
|
|
|
224
|
|
|
$config = new \SimpleXMLElement($localXml); |
|
225
|
|
|
$config->global[0]->redis_session[0]->host = '127.0.0.1'; |
|
226
|
|
|
$config->global[0]->redis_session[0]->port = '6379'; |
|
227
|
|
|
$config->global[0]->redis_session[0]->password = ''; |
|
228
|
|
|
$config->global[0]->redis_session[0]->timeout = '2.5'; |
|
229
|
|
|
$config->global[0]->redis_session[0]->persistent = ''; |
|
230
|
|
|
$config->global[0]->redis_session[0]->db = ''; |
|
231
|
|
|
$config->global[0]->redis_session[0]->compression_threshold = '2048'; |
|
232
|
|
|
$config->global[0]->redis_session[0]->compression_lib = 'gzip'; |
|
233
|
|
|
$config->global[0]->redis_session[0]->log_level = '1'; |
|
234
|
|
|
$config->global[0]->redis_session[0]->max_concurrency = '6'; |
|
235
|
|
|
$config->global[0]->redis_session[0]->break_after_frontend = '5'; |
|
236
|
|
|
$config->global[0]->redis_session[0]->break_after_adminhtml = '30'; |
|
237
|
|
|
$config->global[0]->redis_session[0]->first_lifetime = '600'; |
|
238
|
|
|
$config->global[0]->redis_session[0]->bot_first_lifetime = '60'; |
|
239
|
|
|
$config->global[0]->redis_session[0]->bot_lifetime = '7200'; |
|
240
|
|
|
$config->global[0]->redis_session[0]->disable_locking = '0'; |
|
241
|
|
|
$config->global[0]->redis_session[0]->min_lifetime = '60'; |
|
242
|
|
|
$config->global[0]->redis_session[0]->max_lifetime = '2592000'; |
|
243
|
|
|
|
|
244
|
|
|
file_put_contents($projectPath . $localFile, $config->asXML()); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @param $projectPath |
|
249
|
|
|
*/ |
|
250
|
|
|
protected function activateModule($projectPath) |
|
251
|
|
|
{ |
|
252
|
|
|
$moduleFile = '/public/app/etc/modules/Cm_RedisSession.xml'; |
|
253
|
|
|
$moduleXml = file_get_contents($projectPath . $moduleFile); |
|
254
|
|
|
$config = new \SimpleXMLElement($moduleXml); |
|
255
|
|
|
$config->modules[0]->Cm_RedisSession[0]->active = 'true'; |
|
256
|
|
|
file_put_contents($projectPath . $moduleFile, $config->asXML()); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @param array $options |
|
261
|
|
|
* @param $projectPath |
|
262
|
|
|
* @param OutputInterface $output |
|
263
|
|
|
* @return ProcessCommand |
|
264
|
|
|
*/ |
|
265
|
|
|
protected function configureTestSuites(array $options, $projectPath, OutputInterface $output) |
|
|
|
|
|
|
266
|
|
|
{ |
|
267
|
|
|
$output->writeln('<info>Configuring PHPSpec & Behat Suites</info>'); |
|
268
|
|
|
$progress = new ProgressBar($output, 2); |
|
269
|
|
|
|
|
270
|
|
|
$progress->start(); |
|
271
|
|
|
copy($projectPath . "/puphpet/magestead/magento/stubs/phpspec.yml", $projectPath . "/phpspec.yml"); |
|
272
|
|
|
$progress->advance(); |
|
273
|
|
|
$progress->advance(); |
|
274
|
|
|
// $behat = $this->getBehatConfig($options, $projectPath, $output); |
|
|
|
|
|
|
275
|
|
|
// $this->saveBehatConfig($projectPath, $output, $behat, $progress); |
|
276
|
|
|
$progress->finish(); |
|
277
|
|
|
echo "\n"; |
|
278
|
|
|
new ProcessCommand('bin/phpspec r', $projectPath, $output); |
|
279
|
|
|
return new ProcessCommand('bin/behat --init', $projectPath, $output); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @param array $options |
|
284
|
|
|
* @param $projectPath |
|
285
|
|
|
* @param OutputInterface $output |
|
286
|
|
|
* @return bool|mixed |
|
287
|
|
|
*/ |
|
288
|
|
|
protected function getBehatConfig(array $options, $projectPath, OutputInterface $output) |
|
289
|
|
|
{ |
|
290
|
|
|
$yaml = new Parser(); |
|
291
|
|
|
try { |
|
292
|
|
|
$behat = $yaml->parse(file_get_contents($projectPath . "/puphpet/magestead/magento/stubs/behat.yml")); |
|
293
|
|
|
$behat['default']['extensions']['MageTest\MagentoExtension\Extension']['base_url'] = $options['base_url']; |
|
294
|
|
|
return $behat; |
|
295
|
|
|
} catch (ParseException $e) { |
|
296
|
|
|
$output->writeln('<error>Unable to parse the YAML config</error>'); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
return false; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* @param $projectPath |
|
304
|
|
|
* @param OutputInterface $output |
|
305
|
|
|
* @param $behat |
|
306
|
|
|
* @param $progress |
|
307
|
|
|
*/ |
|
308
|
|
View Code Duplication |
protected function saveBehatConfig($projectPath, OutputInterface $output, $behat, $progress) |
|
|
|
|
|
|
309
|
|
|
{ |
|
310
|
|
|
$dumper = new Dumper(); |
|
311
|
|
|
$yaml = $dumper->dump($behat, 6); |
|
312
|
|
|
try { |
|
313
|
|
|
file_put_contents($projectPath . '/behat.yml', $yaml); |
|
314
|
|
|
$progress->advance(); |
|
315
|
|
|
} catch (\Exception $e) { |
|
316
|
|
|
$output->writeln('<error>Unable to write to the YAML file</error>'); |
|
317
|
|
|
} |
|
318
|
|
|
} |
|
319
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.