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 |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
protected $app; |
36
|
|
|
|
37
|
|
|
public function __construct(\Eccube\Application $app, $name = null) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
parent::__construct($name); |
40
|
|
|
$this->app = $app; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function configure() |
|
|
|
|
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') |
|
|
|
|
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) |
|
|
|
|
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) |
|
|
|
|
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; |
|
|
|
|
107
|
|
|
} |
108
|
|
|
if (empty($path)) { |
109
|
|
|
$output->writeln('path is required.'); |
110
|
|
|
return; |
|
|
|
|
111
|
|
|
} |
112
|
|
|
$plugin = $this->getPluginFromCode($code); |
113
|
|
|
if ($service->update($plugin, $path)) { |
114
|
|
|
$output->writeln('success'); |
115
|
|
|
return; |
|
|
|
|
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
if ($mode == 'uninstall') { |
120
|
|
|
if (empty($code)) { |
121
|
|
|
$output->writeln('code is required.'); |
122
|
|
|
return; |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$plugin = $this->getPluginFromCode($code); |
126
|
|
|
|
127
|
|
|
// ディレクトリも含め全て削除. |
128
|
|
|
if ($uninstallForce) { |
|
|
|
|
129
|
|
|
|
130
|
|
|
if ($service->uninstall($plugin)) { |
131
|
|
|
$output->writeln('success'); |
132
|
|
|
return; |
|
|
|
|
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; |
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if (in_array($mode, array('enable', 'disable'), true)) { |
151
|
|
|
if (empty($code)) { |
152
|
|
|
$output->writeln('code is required.'); |
153
|
|
|
return; |
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
$plugin = $this->getPluginFromCode($code); |
157
|
|
|
if ($service->$mode($plugin)) { |
158
|
|
|
$output->writeln('success'); |
159
|
|
|
return; |
|
|
|
|
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
$output->writeln('undefined mode.'); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|