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

InstallSampleData   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 6
c 6
b 1
f 0
lcom 1
cbo 7
dl 0
loc 50
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 15 3
A runSampleDataInstaller() 0 5 1
A runMagentoCommand() 0 19 2
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