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