Completed
Push — develop ( d772da...357d8d )
by Tom
8s
created

InstallCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 76 1
A isEnabled() 0 4 1
B execute() 0 33 2
1
<?php
2
3
namespace N98\Magento\Command\Installer;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use N98\Magento\Command\Installer\SubCommand\SubCommandFactory;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Input\StringInput;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Class InstallCommand
14
 *
15
 * @codeCoverageIgnore  - Travis server uses installer to create a new shop. If it not works complete build fails.
16
 * @package N98\Magento\Command\Installer
17
 */
18
class InstallCommand extends AbstractMagentoCommand
19
{
20
    const EXEC_STATUS_OK = 0;
21
22
    /**
23
     * @var array
24
     */
25
    protected $commandConfig;
26
27
    /**
28
     * @var \Closure
29
     */
30
    protected $notEmptyCallback;
31
32
    /**
33
     * @var SubCommandFactory;
34
     */
35
    protected $subCommandFactory;
36
37
    protected function configure()
38
    {
39
        $this
40
            ->setName('install')
41
            ->addOption('magentoVersion', null, InputOption::VALUE_OPTIONAL, 'Magento version')
42
            ->addOption(
43
                'magentoVersionByName',
44
                null,
45
                InputOption::VALUE_OPTIONAL,
46
                'Magento version name instead of order number'
47
            )
48
            ->addOption('installationFolder', null, InputOption::VALUE_OPTIONAL, 'Installation folder')
49
            ->addOption('dbHost', null, InputOption::VALUE_OPTIONAL, 'Database host')
50
            ->addOption('dbUser', null, InputOption::VALUE_OPTIONAL, 'Database user')
51
            ->addOption('dbPass', null, InputOption::VALUE_OPTIONAL, 'Database password')
52
            ->addOption('dbName', null, InputOption::VALUE_OPTIONAL, 'Database name')
53
            ->addOption('dbPort', null, InputOption::VALUE_OPTIONAL, 'Database port', 3306)
54
            ->addOption('installSampleData', null, InputOption::VALUE_OPTIONAL, 'Install sample data')
55
            ->addOption(
56
                'useDefaultConfigParams',
57
                null,
58
                InputOption::VALUE_OPTIONAL,
59
                'Use default installation parameters defined in the yaml file'
60
            )
61
            ->addOption('baseUrl', null, InputOption::VALUE_OPTIONAL, 'Installation base url')
62
            ->addOption(
63
                'replaceHtaccessFile',
64
                null,
65
                InputOption::VALUE_OPTIONAL,
66
                'Generate htaccess file (for non vhost environment)'
67
            )
68
            ->addOption(
69
                'noDownload',
70
                null,
71
                InputOption::VALUE_NONE,
72
                'If set skips download step. Used when installationFolder is already a Magento installation that has ' .
73
                'to be installed on the given database.'
74
            )
75
            ->addOption(
76
                'only-download',
77
                null,
78
                InputOption::VALUE_NONE,
79
                'Downloads (and extracts) source code'
80
            )
81
            ->addOption(
82
                'forceUseDb',
83
                null,
84
                InputOption::VALUE_OPTIONAL,
85
                'If --noDownload passed, force to use given database if it already exists.'
86
            )
87
            ->setDescription('Install magento');
88
89
        $help = <<<HELP
90
* Download Magento by a list of git repos and zip files (mageplus, 
91
  magelte, official community packages).
92
* Try to create database if it does not exist.
93
* Installs Magento sample data if available (since version 1.2.0).
94
* Starts Magento installer
95
* Sets rewrite base in .htaccess file
96
97
Example of an unattended Magento CE 2.0.0 installation:
98
99
   $ n98-magerun.phar install --dbHost="localhost" --dbUser="mydbuser" \
100
     --dbPass="mysecret" --dbName="magentodb" --installSampleData=yes \
101
     --useDefaultConfigParams=yes \
102
     --magentoVersionByName="magento-ce-2.0.0" \
103
     --installationFolder="magento" --baseUrl="http://magento.localdomain/"
104
105
Additionally, with --noDownload option you can install Magento working 
106
copy already stored in --installationFolder on the given database.
107
108
See it in action: http://youtu.be/WU-CbJ86eQc
109
110
HELP;
111
        $this->setHelp($help);
112
    }
113
114
    /**
115
     * @return bool
116
     */
117
    public function isEnabled()
118
    {
119
        return function_exists('exec');
120
    }
121
122
    /**
123
     * @param InputInterface $input
124
     * @param OutputInterface $output
125
     * @throws \RuntimeException
126
     * @return int|null|void
127
     */
128
    protected function execute(InputInterface $input, OutputInterface $output)
129
    {
130
        $this->commandConfig = $this->getCommandConfig();
131
        $this->writeSection($output, 'Magento 2 Installation');
132
133
        $subCommandFactory = $this->createSubCommandFactory(
134
            $input,
135
            $output,
136
            'N98\Magento\Command\Installer\SubCommand' // sub-command namespace
137
        );
138
139
        // @todo load commands from config
140
        $subCommandFactory->create('PreCheckPhp')->execute();
141
        $subCommandFactory->create('SelectMagentoVersion')->execute();
142
        $subCommandFactory->create('ChooseInstallationFolder')->execute();
143
        $subCommandFactory->create('InstallComposer')->execute();
144
145
        $subCommandFactory->create('DownloadMagento')->execute();
146
        if ($input->getOption('only-download')) {
147
            return 0;
148
        }
149
150
151
        //$subCommandFactory->create('InstallComposerPackages')->execute();
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
152
        $subCommandFactory->create('CreateDatabase')->execute();
153
        $subCommandFactory->create('RemoveEmptyFolders')->execute();
154
        $subCommandFactory->create('SetDirectoryPermissions')->execute();
155
        $subCommandFactory->create('InstallMagento')->execute();
156
        $subCommandFactory->create('RewriteHtaccessFile')->execute();
157
        $subCommandFactory->create('InstallSampleData')->execute();
158
        $subCommandFactory->create('PostInstallation')->execute();
159
        $output->writeln('<info>Successfully installed magento</info>');
160
    }
161
}
162