Completed
Pull Request — 4.0 (#4067)
by NOBU
06:16
created

PluginInstallCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
B execute() 0 35 6
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Command;
15
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Console\Style\SymfonyStyle;
21
22
class PluginInstallCommand extends Command
23
{
24
    protected static $defaultName = 'eccube:plugin:install';
25
26
    use PluginCommandTrait;
27
28
    protected function configure()
29
    {
30
        $this
31
            ->addOption('path', null, InputOption::VALUE_OPTIONAL, 'path of tar or zip')
32
            ->addOption('code', null, InputOption::VALUE_OPTIONAL, 'plugin code')
33
            ->addOption('with-composer')
34
            ->setDescription('Install plugin from local.');
35
    }
36
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        $io = new SymfonyStyle($input, $output);
40
41
        $path = $input->getOption('path');
42
        $code = $input->getOption('code');
43
        $composer = $input->getOption('with-composer');
44
45
        // アーカイブからインストール
46
        if ($path) {
47
            if ($this->pluginService->install($path)) {
48
                if ($composer) {
49
                    $this->pluginService->installComposer($code);
50
                }
51
                $io->success('Installed.');
52
53
                return 0;
54
            }
55
        }
56
57
        // 設置済ファイルからインストール
58
        if ($code) {
59
            $this->pluginService->installWithCode($code);
60
            if ($composer) {
61
                $this->pluginService->installComposer($code);
62
            }
63
            $this->clearCache($io);
64
            $io->success('Installed.');
65
66
            return 0;
67
        }
68
69
70
        $io->error('path or code is required.');
71
    }
72
}
73