Failed Conditions
Push — master ( fc54b8...947180 )
by Yangsin
124:44 queued 119:37
created

PluginCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Command;
26
27
use Symfony\Component\Console\Input\InputArgument;
28
use Symfony\Component\Console\Input\InputInterface;
29
use Symfony\Component\Console\Output\OutputInterface;
30
use Symfony\Component\Console\Input\InputOption;
31
32
class PluginCommand extends \Knp\Command\Command
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
33
{
34
35
    protected $app;
36
37
    public function __construct(\Eccube\Application $app, $name = null) 
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
introduced by
Please trim any trailing whitespace
Loading history...
38
    {
39
        parent::__construct($name);
40
        $this->app = $app;
41
    }
42
43
    protected function configure() 
0 ignored issues
show
introduced by
Please trim any trailing whitespace
Loading history...
44
    {
45
        $this
46
            ->setName('plugin:develop')
47
            ->addArgument('mode', InputArgument::REQUIRED, 'mode(install/uninstall/enable/disable/update/reload)', null)
48
            ->addOption('path', null, InputOption::VALUE_OPTIONAL, 'path of tar or zip') 
0 ignored issues
show
introduced by
Please trim any trailing whitespace
Loading history...
49
            ->addOption('code', null, InputOption::VALUE_OPTIONAL, 'plugin code')
50
            ->addOption('uninstall-force', null, InputOption::VALUE_OPTIONAL, 'if set true, remove directory')
51
            ->setDescription('plugin commandline installer.')
52
            ->setHelp(<<<EOF
53
The <info>%command.name%</info> plugin installer runner for developer;
54
EOF
55
            );
56
    }
57
58
59
    protected function getPluginFromCode($pluginCode) 
0 ignored issues
show
introduced by
Please trim any trailing whitespace
Loading history...
60
    {
61
        return $this->app['eccube.repository.plugin']->findOneBy(array('del_flg'=>0, 'code'=>$pluginCode));
62
    }
63
64
    protected function execute(InputInterface $input, OutputInterface $output) 
0 ignored issues
show
introduced by
Please trim any trailing whitespace
Loading history...
65
    {
66
        $this->app->initialize();
67
        $this->app->boot();
68
69
        $mode = $input->getArgument('mode');
70
        $path = $input->getOption('path');
71
        $code = $input->getOption('code');
72
        $uninstallForce = $input->getOption('uninstall-force');
73
74
        $service = $this->app['eccube.service.plugin'];
75
76
        if ($mode == 'install') {
77
            // アーカイブからインストール
78
            if ($path) {
79
                if ($service->install($path)) {
80
                    $output->writeln('success');
81
82
                    return;
83
                }
84
            }
85
            // 設置済ファイルからインストール
86
            if ($code) {
87
                $pluginDir = $service->calcPluginDir($code);
88
                $service->checkPluginArchiveContent($pluginDir);
89
                $config = $service->readYml($pluginDir.'/config.yml');
90
                $event = $service->readYml($pluginDir.'/event.yml');
91
                $service->checkSamePlugin($config['code']);
92
                $service->registerPlugin($config, $event);
93
94
                $output->writeln('success');
95
96
                return;
97
            }
98
99
            $output->writeln('path or code is required.');
100
101
            return;
102
        }
103
        if ($mode == 'update') {
104
            if (empty($code)) {
105
                $output->writeln('code is required.');
106
                return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
107
            }
108
            if (empty($path)) {
109
                $output->writeln('path is required.');
110
                return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
111
            }
112
            $plugin = $this->getPluginFromCode($code);
113
            if ($service->update($plugin, $path)) {
114
                $output->writeln('success');
115
                return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
116
            }
117
        }
118
119
        if ($mode == 'uninstall') {
120
            if (empty($code)) {
121
                $output->writeln('code is required.');
122
                return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
123
            }
124
125
            $plugin = $this->getPluginFromCode($code);
126
127
            // ディレクトリも含め全て削除.
128
            if ($uninstallForce) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
129
130
                if ($service->uninstall($plugin)) {
131
                    $output->writeln('success');
132
                    return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
133
                }
134
135
                return;
136
            }
137
138
            // ディレクトリは残し, プラグインを削除.
139
            $pluginDir = $service->calcPluginDir($code);
140
            $config = $service->readYml($pluginDir.'/config.yml');
141
            $service->callPluginManagerMethod($config, 'disable');
142
            $service->callPluginManagerMethod($config, 'uninstall');
143
            $service->unregisterPlugin($plugin);
144
145
            $output->writeln('success');
146
            return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
147
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
148
        }
149
150
        if (in_array($mode, array('enable', 'disable'), true)) {
151
            if (empty($code)) {
152
                $output->writeln('code is required.');
153
                return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
154
            }
155
156
            $plugin = $this->getPluginFromCode($code);
157
            if ($service->$mode($plugin)) {
158
                $output->writeln('success');
159
                return;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
160
            }
161
        }
162
        $output->writeln('undefined mode.');
163
    }
164
}
165