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\Controller\Admin\Store; |
26
|
|
|
|
27
|
|
|
use Doctrine\ORM\EntityManager; |
28
|
|
|
use Eccube\Annotation\Inject; |
29
|
|
|
use Eccube\Application; |
30
|
|
|
use Eccube\Common\Constant; |
31
|
|
|
use Eccube\Controller\AbstractController; |
32
|
|
|
use Eccube\Entity\BaseInfo; |
33
|
|
|
use Eccube\Entity\Plugin; |
34
|
|
|
use Eccube\Entity\PluginEventHandler; |
35
|
|
|
use Eccube\Exception\PluginException; |
36
|
|
|
use Eccube\Form\Type\Admin\PluginLocalInstallType; |
37
|
|
|
use Eccube\Form\Type\Admin\PluginManagementType; |
38
|
|
|
use Eccube\Repository\PluginEventHandlerRepository; |
39
|
|
|
use Eccube\Repository\PluginRepository; |
40
|
|
|
use Eccube\Service\PluginService; |
41
|
|
|
use Eccube\Util\StringUtil; |
42
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
43
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
44
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
45
|
|
|
use Symfony\Bridge\Monolog\Logger; |
46
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
47
|
|
|
use Symfony\Component\Finder\Finder; |
48
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FormType; |
49
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
50
|
|
|
use Symfony\Component\Form\FormFactory; |
51
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
52
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
53
|
|
|
use Symfony\Component\HttpFoundation\Request; |
54
|
|
|
use Symfony\Component\Routing\Exception\RouteNotFoundException; |
55
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @Route(service=PluginController::class) |
59
|
|
|
*/ |
60
|
|
|
class PluginController extends AbstractController |
61
|
|
|
{ |
62
|
|
|
/** |
63
|
|
|
* @Inject("orm.em") |
64
|
|
|
* @var EntityManager |
65
|
|
|
*/ |
66
|
|
|
protected $entityManager; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @Inject("monolog") |
70
|
|
|
* @var Logger |
71
|
|
|
*/ |
72
|
|
|
protected $logger; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @Inject(PluginEventHandlerRepository::class) |
76
|
|
|
* @var PluginEventHandlerRepository |
77
|
|
|
*/ |
78
|
|
|
protected $pluginEventHandlerRepository; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @Inject(PluginService::class) |
82
|
|
|
* @var PluginService |
83
|
|
|
*/ |
84
|
|
|
protected $pluginService; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Inject("config") |
88
|
|
|
* @var array |
89
|
|
|
*/ |
90
|
|
|
protected $appConfig; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @Inject(BaseInfo::class) |
94
|
|
|
* @var BaseInfo |
95
|
|
|
*/ |
96
|
|
|
protected $BaseInfo; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Inject("form.factory") |
100
|
|
|
* @var FormFactory |
101
|
|
|
*/ |
102
|
|
|
protected $formFactory; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @Inject(PluginRepository::class) |
106
|
|
|
* @var PluginRepository |
107
|
|
|
*/ |
108
|
|
|
protected $pluginRepository; |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
|
|
|
|
112
|
|
|
* インストール済プラグイン画面 |
113
|
|
|
* |
114
|
|
|
* @Route("/{_admin}/store/plugin", name="admin_store_plugin") |
115
|
|
|
* @Template("Store/plugin.twig") |
116
|
|
|
*/ |
|
|
|
|
117
|
|
|
public function index(Application $app, Request $request) |
118
|
|
|
{ |
119
|
|
|
$pluginForms = array(); |
120
|
|
|
$configPages = array(); |
121
|
|
|
$Plugins = $this->pluginRepository->findBy(array(), array('code' => 'ASC')); |
122
|
|
|
|
123
|
|
|
// ファイル設置プラグインの取得. |
124
|
|
|
$unregisterdPlugins = $this->getUnregisteredPlugins($Plugins, $app); |
125
|
|
|
$unregisterdPluginsConfigPages = array(); |
126
|
|
|
foreach ($unregisterdPlugins as $unregisterdPlugin) { |
127
|
|
|
try { |
128
|
|
|
$code = $unregisterdPlugin['code']; |
129
|
|
|
// プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか) |
130
|
|
|
$unregisterdPluginsConfigPages[$code] = $app->url('plugin_'.$code.'_config'); |
131
|
|
|
} catch (RouteNotFoundException $e) { |
132
|
|
|
// プラグインで設定画面のルートが定義されていない場合は無視 |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
$officialPlugins = array(); |
137
|
|
|
$unofficialPlugins = array(); |
138
|
|
|
|
139
|
|
|
foreach ($Plugins as $Plugin) { |
140
|
|
|
$form = $this->formFactory |
141
|
|
|
->createNamedBuilder( |
142
|
|
|
'form'.$Plugin->getId(), |
143
|
|
|
PluginManagementType::class, |
144
|
|
|
null, |
145
|
|
|
array( |
146
|
|
|
'plugin_id' => $Plugin->getId(), |
147
|
|
|
) |
148
|
|
|
) |
149
|
|
|
->getForm(); |
150
|
|
|
$pluginForms[$Plugin->getId()] = $form->createView(); |
151
|
|
|
|
152
|
|
|
try { |
153
|
|
|
// プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか) |
154
|
|
|
$configPages[$Plugin->getCode()] = $app->url('plugin_'.$Plugin->getCode().'_config'); |
155
|
|
|
} catch (\Exception $e) { |
156
|
|
|
// プラグインで設定画面のルートが定義されていない場合は無視 |
157
|
|
|
} |
158
|
|
|
if ($Plugin->getSource() == 0) { |
159
|
|
|
// 商品IDが設定されていない場合、非公式プラグイン |
160
|
|
|
$unofficialPlugins[] = $Plugin; |
161
|
|
|
} else { |
162
|
|
|
$officialPlugins[] = $Plugin; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
// Todo: Need new authentication mechanism |
167
|
|
|
// オーナーズストアからダウンロード可能プラグイン情報を取得 |
168
|
|
|
$authKey = $this->BaseInfo->getAuthenticationKey(); |
169
|
|
|
// オーナーズストア通信 |
170
|
|
|
$url = $this->appConfig['package_repo_url'].'/search/packages.json'; |
171
|
|
|
list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app); |
|
|
|
|
172
|
|
|
|
173
|
|
|
$officialPluginsDetail = []; |
174
|
|
|
if ($json) { |
175
|
|
|
// 接続成功時 |
176
|
|
|
$data = json_decode($json, true); |
177
|
|
|
if (isset($data['success']) && $data['success']) { |
178
|
|
|
foreach ($data['item'] as $item) { |
179
|
|
|
foreach ($officialPlugins as $key => $plugin) { |
180
|
|
|
if ($plugin->getSource() == $item['product_id']) { |
181
|
|
|
$officialPluginsDetail[$key] = $item; |
182
|
|
|
$officialPluginsDetail[$key]['update_status'] = 0; |
183
|
|
|
if ($this->pluginService->isUpdate($plugin->getVersion(), $item['version'])) { |
184
|
|
|
$officialPluginsDetail[$key]['update_status'] = 1; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
return [ |
193
|
|
|
'plugin_forms' => $pluginForms, |
194
|
|
|
'officialPlugins' => $officialPlugins, |
195
|
|
|
'unofficialPlugins' => $unofficialPlugins, |
196
|
|
|
'configPages' => $configPages, |
197
|
|
|
'unregisterdPlugins' => $unregisterdPlugins, |
198
|
|
|
'unregisterdPluginsConfigPages' => $unregisterdPluginsConfigPages, |
199
|
|
|
'officialPluginsDetail' => $officialPluginsDetail, |
200
|
|
|
]; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* インストール済プラグインからのアップデート |
205
|
|
|
* |
206
|
|
|
* @Method("POST") |
207
|
|
|
* @Route("/{_admin}/store/plugin/{id}/update", requirements={"id" = "\d+"}, name="admin_store_plugin_update") |
208
|
|
|
* @param Application $app |
209
|
|
|
* @param Request $request |
210
|
|
|
* @param Plugin $Plugin |
211
|
|
|
* @return RedirectResponse |
212
|
|
|
*/ |
213
|
|
|
public function update(Application $app, Request $request, Plugin $Plugin) |
214
|
|
|
{ |
215
|
|
|
$form = $this->formFactory |
216
|
|
|
->createNamedBuilder( |
217
|
|
|
'form'.$Plugin->getId(), |
218
|
|
|
PluginManagementType::class, |
219
|
|
|
null, |
220
|
|
|
array( |
221
|
|
|
'plugin_id' => null, // placeHolder |
222
|
|
|
) |
223
|
|
|
) |
224
|
|
|
->getForm(); |
225
|
|
|
|
226
|
|
|
$message = ''; |
227
|
|
|
$form->handleRequest($request); |
228
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
229
|
|
|
$tmpDir = null; |
230
|
|
|
try { |
231
|
|
|
$formFile = $form['plugin_archive']->getData(); |
232
|
|
|
$tmpDir = $this->pluginService->createTempDir(); |
233
|
|
|
$tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension(); |
234
|
|
|
$formFile->move($tmpDir, $tmpFile); |
235
|
|
|
$this->pluginService->update($Plugin, $tmpDir.'/'.$tmpFile); |
236
|
|
|
$fs = new Filesystem(); |
237
|
|
|
$fs->remove($tmpDir); |
238
|
|
|
$app->addSuccess('admin.plugin.update.complete', 'admin'); |
239
|
|
|
|
240
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
241
|
|
|
} catch (PluginException $e) { |
242
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
243
|
|
|
$fs = new Filesystem(); |
244
|
|
|
$fs->remove($tmpDir); |
245
|
|
|
} |
246
|
|
|
$message = $e->getMessage(); |
247
|
|
|
} catch (\Exception $er) { |
248
|
|
|
// Catch composer install error | Other error |
249
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
250
|
|
|
$fs = new Filesystem(); |
251
|
|
|
$fs->remove($tmpDir); |
252
|
|
|
} |
253
|
|
|
$this->logger->error("plugin install failed.", array('original-message' => $er->getMessage())); |
254
|
|
|
$message = 'admin.plugin.install.fail'; |
255
|
|
|
} |
256
|
|
|
} else { |
257
|
|
|
$errors = $form->getErrors(true); |
258
|
|
|
foreach ($errors as $error) { |
259
|
|
|
$message = $error->getMessage(); |
|
|
|
|
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
$app->addError($message, 'admin'); |
264
|
|
|
|
265
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* 対象のプラグインを有効にします。 |
271
|
|
|
* |
272
|
|
|
* @Method("PUT") |
273
|
|
|
* @Route("/{_admin}/store/plugin/{id}/enable", requirements={"id" = "\d+"}, name="admin_store_plugin_enable") |
274
|
|
|
* @param Application $app |
275
|
|
|
* @param Plugin $Plugin |
276
|
|
|
* @return RedirectResponse |
277
|
|
|
*/ |
278
|
|
View Code Duplication |
public function enable(Application $app, Plugin $Plugin) |
|
|
|
|
279
|
|
|
{ |
280
|
|
|
$this->isTokenValid($app); |
281
|
|
|
|
282
|
|
|
if ($Plugin->isEnabled()) { |
283
|
|
|
$app->addError('admin.plugin.already.enable', 'admin'); |
284
|
|
|
} else { |
285
|
|
|
$requires = $this->pluginService->findRequirePluginNeedEnable($Plugin->getCode()); |
286
|
|
|
if (!empty($requires)) { |
287
|
|
|
$DependPlugin = $this->pluginRepository->findOneBy(['code' => $requires[0]]); |
288
|
|
|
$dependName = $requires[0]; |
289
|
|
|
if ($DependPlugin) { |
290
|
|
|
$dependName = $DependPlugin->getName(); |
291
|
|
|
} |
292
|
|
|
$message = $app->trans('admin.plugin.enable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]); |
293
|
|
|
$app->addError($message, 'admin'); |
294
|
|
|
|
295
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
296
|
|
|
} |
297
|
|
|
$this->pluginService->enable($Plugin); |
298
|
|
|
$app->addSuccess('admin.plugin.enable.complete', 'admin'); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* 対象のプラグインを無効にします。 |
306
|
|
|
* |
307
|
|
|
* @Method("PUT") |
308
|
|
|
* @Route("/{_admin}/store/plugin/{id}/disable", requirements={"id" = "\d+"}, name="admin_store_plugin_disable") |
309
|
|
|
* @param Application $app |
310
|
|
|
* @param Plugin $Plugin |
311
|
|
|
* @return RedirectResponse |
312
|
|
|
*/ |
313
|
|
View Code Duplication |
public function disable(Application $app, Plugin $Plugin) |
|
|
|
|
314
|
|
|
{ |
315
|
|
|
$this->isTokenValid($app); |
316
|
|
|
|
317
|
|
|
if ($Plugin->isEnabled()) { |
318
|
|
|
$dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode()); |
319
|
|
|
if (!empty($dependents)) { |
320
|
|
|
$dependName = $dependents[0]; |
321
|
|
|
$DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]); |
322
|
|
|
if ($DependPlugin) { |
323
|
|
|
$dependName = $DependPlugin->getName(); |
324
|
|
|
} |
325
|
|
|
$message = $app->trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]); |
326
|
|
|
$app->addError($message, 'admin'); |
327
|
|
|
|
328
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
$this->pluginService->disable($Plugin); |
332
|
|
|
$app->addSuccess('admin.plugin.disable.complete', 'admin'); |
333
|
|
|
} else { |
334
|
|
|
$app->addError('admin.plugin.already.disable', 'admin'); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* 対象のプラグインを削除します。 |
342
|
|
|
* |
343
|
|
|
* @Method("DELETE") |
344
|
|
|
* @Route("/{_admin}/store/plugin/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_uninstall") |
345
|
|
|
* @param Application $app |
346
|
|
|
* @param Plugin $Plugin |
347
|
|
|
* @return RedirectResponse |
348
|
|
|
*/ |
349
|
|
|
public function uninstall(Application $app, Plugin $Plugin) |
350
|
|
|
{ |
351
|
|
|
$this->isTokenValid($app); |
352
|
|
|
|
353
|
|
|
if ($Plugin->isEnabled()) { |
354
|
|
|
$app->addError('admin.plugin.uninstall.error.not_disable', 'admin'); |
355
|
|
|
|
356
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
// Check other plugin depend on it |
360
|
|
|
$pluginCode = $Plugin->getCode(); |
361
|
|
|
$otherDepend = $this->pluginService->findDependentPlugin($pluginCode); |
362
|
|
|
if (!empty($otherDepend)) { |
363
|
|
|
$DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]); |
364
|
|
|
$dependName = $otherDepend[0]; |
365
|
|
|
if ($DependPlugin) { |
366
|
|
|
$dependName = $DependPlugin->getName(); |
367
|
|
|
} |
368
|
|
|
$message = $app->trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]); |
369
|
|
|
$app->addError($message, 'admin'); |
370
|
|
|
|
371
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
$this->pluginService->uninstall($Plugin); |
375
|
|
|
$app->addSuccess('admin.plugin.uninstall.complete', 'admin'); |
376
|
|
|
|
377
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
|
|
|
|
381
|
|
|
* @Route("/{_admin}/store/plugin/handler", name="admin_store_plugin_handler") |
382
|
|
|
* @Template("Store/plugin_handler.twig") |
383
|
|
|
*/ |
|
|
|
|
384
|
|
|
public function handler(Application $app) |
|
|
|
|
385
|
|
|
{ |
386
|
|
|
$handlers = $this->pluginEventHandlerRepository->getHandlers(); |
387
|
|
|
|
388
|
|
|
// 一次元配列からイベント毎の二次元配列に変換する |
389
|
|
|
$HandlersPerEvent = array(); |
390
|
|
|
foreach ($handlers as $handler) { |
391
|
|
|
$HandlersPerEvent[$handler->getEvent()][$handler->getHandlerType()][] = $handler; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
return [ |
395
|
|
|
'handlersPerEvent' => $HandlersPerEvent, |
396
|
|
|
]; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
|
|
|
|
400
|
|
|
* @Route("/{_admin}/store/plugin/handler_up/{id}", requirements={"id" = "\d+"}, name="admin_store_plugin_handler_up") |
401
|
|
|
*/ |
|
|
|
|
402
|
|
View Code Duplication |
public function handler_up(Application $app, PluginEventHandler $Handler) |
|
|
|
|
403
|
|
|
{ |
404
|
|
|
$repo = $this->pluginEventHandlerRepository; |
405
|
|
|
$repo->upPriority($repo->find($Handler->getId())); |
406
|
|
|
|
407
|
|
|
return $app->redirect($app->url('admin_store_plugin_handler')); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
|
|
|
|
411
|
|
|
* @Route("/{_admin}/store/plugin/handler_down/{id}", requirements={"id" = "\d+"}, name="admin_store_plugin_handler_down") |
412
|
|
|
*/ |
|
|
|
|
413
|
|
View Code Duplication |
public function handler_down(Application $app, PluginEventHandler $Handler) |
|
|
|
|
414
|
|
|
{ |
415
|
|
|
$repo = $this->pluginEventHandlerRepository; |
416
|
|
|
$repo->upPriority($Handler, false); |
417
|
|
|
|
418
|
|
|
return $app->redirect($app->url('admin_store_plugin_handler')); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* プラグインファイルアップロード画面 |
423
|
|
|
* |
424
|
|
|
* @Route("/{_admin}/store/plugin/install", name="admin_store_plugin_install") |
425
|
|
|
* @Template("Store/plugin_install.twig") |
426
|
|
|
* @param Application $app |
427
|
|
|
* @param Request $request |
428
|
|
|
* @return array|RedirectResponse |
429
|
|
|
*/ |
430
|
|
|
public function install(Application $app, Request $request) |
431
|
|
|
{ |
432
|
|
|
$form = $this->formFactory |
433
|
|
|
->createBuilder(PluginLocalInstallType::class) |
434
|
|
|
->getForm(); |
435
|
|
|
$errors = array(); |
436
|
|
|
$form->handleRequest($request); |
437
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
438
|
|
|
$tmpDir = null; |
439
|
|
|
try { |
440
|
|
|
$service = $this->pluginService; |
441
|
|
|
/** @var UploadedFile $formFile */ |
442
|
|
|
$formFile = $form['plugin_archive']->getData(); |
443
|
|
|
$tmpDir = $service->createTempDir(); |
444
|
|
|
// 拡張子を付けないとpharが動かないので付ける |
445
|
|
|
$tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension(); |
446
|
|
|
$formFile->move($tmpDir, $tmpFile); |
447
|
|
|
$tmpPath = $tmpDir.'/'.$tmpFile; |
448
|
|
|
$service->install($tmpPath); |
449
|
|
|
// Remove tmp file |
450
|
|
|
$fs = new Filesystem(); |
451
|
|
|
$fs->remove($tmpDir); |
452
|
|
|
$app->addSuccess('admin.plugin.install.complete', 'admin'); |
453
|
|
|
|
454
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
455
|
|
|
} catch (PluginException $e) { |
456
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
457
|
|
|
$fs = new Filesystem(); |
458
|
|
|
$fs->remove($tmpDir); |
459
|
|
|
} |
460
|
|
|
$this->logger->error("plugin install failed.", array('original-message' => $e->getMessage())); |
461
|
|
|
$errors[] = $e; |
462
|
|
|
} catch (\Exception $er) { |
463
|
|
|
// Catch composer install error | Other error |
464
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
465
|
|
|
$fs = new Filesystem(); |
466
|
|
|
$fs->remove($tmpDir); |
467
|
|
|
} |
468
|
|
|
$this->logger->error("plugin install failed.", array('original-message' => $er->getMessage())); |
469
|
|
|
$app->addError('admin.plugin.install.fail', 'admin'); |
470
|
|
|
} |
471
|
|
|
} else { |
472
|
|
|
foreach ($form->getErrors(true) as $error) { |
473
|
|
|
$errors[] = $error; |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
return [ |
478
|
|
|
'form' => $form->createView(), |
479
|
|
|
'errors' => $errors, |
480
|
|
|
]; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
|
|
|
|
484
|
|
|
* 認証キー設定画面 |
485
|
|
|
* |
486
|
|
|
* @Route("/{_admin}/store/plugin/authentication_setting", name="admin_store_authentication_setting") |
487
|
|
|
* @Template("Store/authentication_setting.twig") |
488
|
|
|
*/ |
|
|
|
|
489
|
|
|
public function authenticationSetting(Application $app, Request $request) |
490
|
|
|
{ |
491
|
|
|
$builder = $this->formFactory |
492
|
|
|
->createBuilder(FormType::class, $this->BaseInfo); |
493
|
|
|
$builder->add( |
494
|
|
|
'authentication_key', |
495
|
|
|
TextType::class, |
496
|
|
|
[ |
497
|
|
|
'label' => '認証キー', |
498
|
|
|
'constraints' => [ |
499
|
|
|
new Assert\Regex(['pattern' => "/^[0-9a-zA-Z]+$/",]), |
|
|
|
|
500
|
|
|
], |
501
|
|
|
] |
502
|
|
|
); |
503
|
|
|
|
504
|
|
|
$form = $builder->getForm(); |
505
|
|
|
$form->handleRequest($request); |
506
|
|
|
|
507
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
508
|
|
|
// 認証キーの登録 |
509
|
|
|
$BaseInfo = $form->getData(); |
510
|
|
|
$this->entityManager->flush($BaseInfo); |
511
|
|
|
|
512
|
|
|
$app->addSuccess('admin.plugin.authentication.setting.complete', 'admin'); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
return [ |
516
|
|
|
'form' => $form->createView(), |
517
|
|
|
]; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* APIリクエスト処理 |
523
|
|
|
* |
524
|
|
|
* @param Request $request |
525
|
|
|
* @param $authKey |
526
|
|
|
* @param string $url |
527
|
|
|
* @param Application $app |
528
|
|
|
* @return array |
529
|
|
|
*/ |
530
|
|
|
private function getRequestApi(Request $request, $authKey, $url, $app) |
531
|
|
|
{ |
532
|
|
|
$curl = curl_init($url); |
533
|
|
|
|
534
|
|
|
$options = array( // オプション配列 |
535
|
|
|
//HEADER |
536
|
|
|
CURLOPT_HTTPHEADER => array( |
537
|
|
|
'Authorization: '.base64_encode($authKey), |
538
|
|
|
'x-eccube-store-url: '.base64_encode($request->getSchemeAndHttpHost().$request->getBasePath()), |
539
|
|
|
'x-eccube-store-version: '.base64_encode(Constant::VERSION), |
540
|
|
|
), |
541
|
|
|
CURLOPT_HTTPGET => true, |
542
|
|
|
CURLOPT_SSL_VERIFYPEER => true, |
543
|
|
|
CURLOPT_RETURNTRANSFER => true, |
544
|
|
|
CURLOPT_FAILONERROR => true, |
545
|
|
|
CURLOPT_CAINFO => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(), |
546
|
|
|
); |
547
|
|
|
|
548
|
|
|
curl_setopt_array($curl, $options); /// オプション値を設定 |
549
|
|
|
$result = curl_exec($curl); |
550
|
|
|
$info = curl_getinfo($curl); |
551
|
|
|
|
552
|
|
|
$message = curl_error($curl); |
553
|
|
|
$info['message'] = $message; |
554
|
|
|
curl_close($curl); |
555
|
|
|
|
556
|
|
|
$app->log('http get_info', $info); |
557
|
|
|
|
558
|
|
|
return array($result, $info); |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* レスポンスのチェック |
563
|
|
|
* |
564
|
|
|
* @param $info |
565
|
|
|
* @return string |
566
|
|
|
*/ |
567
|
|
View Code Duplication |
private function getResponseErrorMessage($info) |
|
|
|
|
568
|
|
|
{ |
569
|
|
|
if (!empty($info)) { |
570
|
|
|
$statusCode = $info['http_code']; |
571
|
|
|
$message = $info['message']; |
572
|
|
|
|
573
|
|
|
$message = $statusCode.' : '.$message; |
574
|
|
|
|
|
|
|
|
575
|
|
|
} else { |
576
|
|
|
$message = "タイムアウトエラーまたはURLの指定に誤りがあります。"; |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
return $message; |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* フォルダ設置のみのプラグインを取得する. |
585
|
|
|
* |
586
|
|
|
* @param array $plugins |
587
|
|
|
* @param Application $app |
588
|
|
|
* @return array |
589
|
|
|
*/ |
590
|
|
|
protected function getUnregisteredPlugins(array $plugins, \Eccube\Application $app) |
|
|
|
|
591
|
|
|
{ |
592
|
|
|
$finder = new Finder(); |
593
|
|
|
$pluginCodes = array(); |
594
|
|
|
|
595
|
|
|
// DB登録済みプラグインコードのみ取得 |
596
|
|
|
foreach ($plugins as $key => $plugin) { |
597
|
|
|
$pluginCodes[] = $plugin->getCode(); |
598
|
|
|
} |
599
|
|
|
// DB登録済みプラグインコードPluginディレクトリから排他 |
600
|
|
|
$dirs = $finder->in($this->appConfig['plugin_realdir'])->depth(0)->directories(); |
601
|
|
|
|
602
|
|
|
// プラグイン基本チェック |
603
|
|
|
$unregisteredPlugins = array(); |
604
|
|
|
foreach ($dirs as $dir) { |
605
|
|
|
$pluginCode = $dir->getBasename(); |
606
|
|
|
if (in_array($pluginCode, $pluginCodes, true)) { |
607
|
|
|
continue; |
608
|
|
|
} |
609
|
|
|
try { |
610
|
|
|
$this->pluginService->checkPluginArchiveContent($dir->getRealPath()); |
611
|
|
|
} catch (\Eccube\Exception\PluginException $e) { |
612
|
|
|
//config.yamlに不備があった際は全てスキップ |
613
|
|
|
$this->logger->warning($e->getMessage()); |
614
|
|
|
continue; |
615
|
|
|
} |
616
|
|
|
$config = $this->pluginService->readYml($dir->getRealPath().'/config.yml'); |
617
|
|
|
$unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null; |
618
|
|
|
$unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null; |
619
|
|
|
$unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null; |
620
|
|
|
$unregisteredPlugins[$pluginCode]['enabled'] = Constant::DISABLED; |
621
|
|
|
$unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
return $unregisteredPlugins; |
625
|
|
|
} |
626
|
|
|
} |
627
|
|
|
|