Completed
Push — develop ( f8e6eb...81325c )
by Tom
04:33
created

InstallSampleData::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 8
nc 3
nop 0
1
<?php
2
3
namespace N98\Magento\Command\Installer\SubCommand;
4
5
use N98\Magento\Command\SubCommand\AbstractSubCommand;
6
use N98\Util\OperatingSystem;
7
use Symfony\Component\Process\ProcessBuilder;
8
9
class InstallSampleData extends AbstractSubCommand
10
{
11
    /**
12
     * @return void
13
     */
14
    public function execute()
15
    {
16
        if ($this->input->getOption('noDownload')) {
17
            return;
18
        }
19
20
        $installationFolder = $this->config->getString('installationFolder');
21
        chdir($installationFolder);
22
23
        $flag = $this->getOptionalBooleanOption('installSampleData', 'Install sample data?');
24
25
        if ($flag) {
26
            $this->runSampleDataInstaller();
27
        }
28
    }
29
30
    protected function runSampleDataInstaller()
31
    {
32
        $this->runMagentoCommand('sampledata:deploy');
33
        $this->runMagentoCommand('setup:upgrade');
34
    }
35
36
    /**
37
     * @return void
38
     */
39
    private function runMagentoCommand($command)
40
    {
41
        $processBuilder = new ProcessBuilder([
42
            'php',
43
            'bin/magento',
44
            $command,
45
        ]);
46
47
        if (!OperatingSystem::isWindows()) {
48
            $processBuilder->setPrefix('/usr/bin/env');
49
        }
50
51
        $process = $processBuilder->getProcess();
52
        $process->setTimeout(86400);
53
        $process->start();
54
        $process->wait(function ($type, $buffer) {
55
            $this->output->write('bin/magento > ' . $buffer, false);
56
        });
57
    }
58
}
59