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\Exception\PluginException; |
21
|
|
|
use Eccube\Form\Type\Admin\AuthenticationType; |
22
|
|
|
use Eccube\Form\Type\Admin\PluginLocalInstallType; |
23
|
|
|
use Eccube\Form\Type\Admin\PluginManagementType; |
24
|
|
|
use Eccube\Repository\BaseInfoRepository; |
25
|
|
|
use Eccube\Repository\PluginRepository; |
26
|
|
|
use Eccube\Service\PluginApiService; |
27
|
|
|
use Eccube\Service\PluginService; |
28
|
|
|
use Eccube\Util\CacheUtil; |
29
|
|
|
use Eccube\Util\StringUtil; |
30
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
31
|
|
|
use Symfony\Component\DependencyInjection\Container; |
32
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
33
|
|
|
use Symfony\Component\Finder\Finder; |
34
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
35
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
36
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
37
|
|
|
use Symfony\Component\HttpFoundation\Request; |
38
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
39
|
|
|
use Symfony\Component\Routing\Exception\RouteNotFoundException; |
40
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
41
|
|
|
|
42
|
|
|
class PluginController extends AbstractController |
43
|
|
|
{ |
44
|
|
|
/** |
45
|
|
|
* @var PluginService |
46
|
|
|
*/ |
47
|
|
|
protected $pluginService; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var BaseInfo |
51
|
|
|
*/ |
52
|
|
|
protected $BaseInfo; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var PluginRepository |
56
|
|
|
*/ |
57
|
|
|
protected $pluginRepository; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var PluginApiService |
61
|
|
|
*/ |
62
|
|
|
protected $pluginApiService; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* PluginController constructor. |
66
|
|
|
* |
67
|
|
|
* @param PluginRepository $pluginRepository |
68
|
|
|
* @param PluginService $pluginService |
69
|
|
|
* @param BaseInfoRepository $baseInfoRepository |
70
|
|
|
* @param PluginApiService $pluginApiService |
71
|
|
|
* |
72
|
|
|
* @throws \Doctrine\ORM\NoResultException |
73
|
|
|
* @throws \Doctrine\ORM\NonUniqueResultException |
74
|
|
|
*/ |
75
|
|
|
public function __construct(PluginRepository $pluginRepository, PluginService $pluginService, BaseInfoRepository $baseInfoRepository, PluginApiService $pluginApiService) |
76
|
|
|
{ |
77
|
|
|
$this->pluginRepository = $pluginRepository; |
78
|
|
|
$this->pluginService = $pluginService; |
79
|
|
|
$this->BaseInfo = $baseInfoRepository->get(); |
80
|
|
|
$this->pluginApiService = $pluginApiService; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* インストール済プラグイン画面 |
85
|
|
|
* |
86
|
|
|
* @Route("/%eccube_admin_route%/store/plugin", name="admin_store_plugin") |
87
|
|
|
* @Template("@admin/Store/plugin.twig") |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
* @throws PluginException |
91
|
|
|
*/ |
92
|
|
|
public function index() |
93
|
|
|
{ |
94
|
|
|
$pluginForms = []; |
95
|
|
|
$configPages = []; |
96
|
|
|
$Plugins = $this->pluginRepository->findBy([], ['code' => 'ASC']); |
97
|
|
|
|
98
|
|
|
// ファイル設置プラグインの取得. |
99
|
|
|
$unregisteredPlugins = $this->getUnregisteredPlugins($Plugins); |
100
|
|
|
$unregisteredPluginsConfigPages = []; |
101
|
|
|
foreach ($unregisteredPlugins as $unregisteredPlugin) { |
102
|
|
|
try { |
103
|
|
|
$code = $unregisteredPlugin['code']; |
104
|
|
|
// プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか) |
105
|
|
|
$unregisteredPluginsConfigPages[$code] = $this->generateUrl('plugin_'.$code.'_config'); |
106
|
|
|
} catch (RouteNotFoundException $e) { |
107
|
|
|
// プラグインで設定画面のルートが定義されていない場合は無視 |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$officialPlugins = []; |
112
|
|
|
$unofficialPlugins = []; |
113
|
|
|
|
114
|
|
|
foreach ($Plugins as $Plugin) { |
115
|
|
|
$form = $this->formFactory |
116
|
|
|
->createNamedBuilder( |
117
|
|
|
'form'.$Plugin->getId(), |
118
|
|
|
PluginManagementType::class, |
119
|
|
|
null, |
120
|
|
|
[ |
121
|
|
|
'plugin_id' => $Plugin->getId(), |
122
|
|
|
] |
123
|
|
|
) |
124
|
|
|
->getForm(); |
125
|
|
|
$pluginForms[$Plugin->getId()] = $form->createView(); |
126
|
|
|
|
127
|
|
|
try { |
128
|
|
|
// プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか) |
129
|
|
|
$configPages[$Plugin->getCode()] = $this->generateUrl(Container::underscore($Plugin->getCode()).'_admin_config'); |
130
|
|
|
} catch (\Exception $e) { |
131
|
|
|
// プラグインで設定画面のルートが定義されていない場合は無視 |
132
|
|
|
} |
133
|
|
|
if ($Plugin->getSource() == 0) { |
134
|
|
|
// 商品IDが設定されていない場合、非公式プラグイン |
135
|
|
|
$unofficialPlugins[] = $Plugin; |
136
|
|
|
} else { |
137
|
|
|
$officialPlugins[$Plugin->getSource()] = $Plugin; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// オーナーズストア通信 |
142
|
|
|
list($json,) = $this->pluginApiService->getPurchased(); |
143
|
|
|
$officialPluginsDetail = []; |
144
|
|
|
if ($json) { |
145
|
|
|
// 接続成功時 |
146
|
|
|
$data = json_decode($json, true); |
147
|
|
|
foreach ($data as $item) { |
148
|
|
|
if (isset($officialPlugins[$item['id']])) { |
149
|
|
|
$Plugin = $officialPlugins[$item['id']]; |
150
|
|
|
$officialPluginsDetail[$item['id']] = $item; |
151
|
|
|
$officialPluginsDetail[$item['id']]['update_status'] = 0; |
152
|
|
View Code Duplication |
if ($this->pluginService->isUpdate($Plugin->getVersion(), $item['version'])) { |
|
|
|
|
153
|
|
|
$officialPluginsDetail[$item['id']]['update_status'] = 1; |
154
|
|
|
} |
155
|
|
|
} else { |
156
|
|
|
$Plugin = new Plugin(); |
157
|
|
|
$Plugin->setName($item['name']); |
158
|
|
|
$Plugin->setCode($item['code']); |
159
|
|
|
$Plugin->setVersion($item['version']); |
160
|
|
|
$Plugin->setSource($item['id']); |
161
|
|
|
$Plugin->setEnabled(false); |
162
|
|
|
$officialPlugins[$item['id']] = $Plugin; |
163
|
|
|
$officialPluginsDetail[$item['id']] = $item; |
164
|
|
|
$officialPluginsDetail[$item['id']]['update_status'] = 0; |
165
|
|
View Code Duplication |
if ($this->pluginService->isUpdate($Plugin->getVersion(), $item['version'])) { |
|
|
|
|
166
|
|
|
$officialPluginsDetail[$item['id']]['update_status'] = 1; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return [ |
173
|
|
|
'plugin_forms' => $pluginForms, |
174
|
|
|
'officialPlugins' => $officialPlugins, |
175
|
|
|
'unofficialPlugins' => $unofficialPlugins, |
176
|
|
|
'configPages' => $configPages, |
177
|
|
|
'unregisteredPlugins' => $unregisteredPlugins, |
178
|
|
|
'unregisteredPluginsConfigPages' => $unregisteredPluginsConfigPages, |
179
|
|
|
'officialPluginsDetail' => $officialPluginsDetail, |
180
|
|
|
]; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* インストール済プラグインからのアップデート |
185
|
|
|
* |
186
|
|
|
* @Route("/%eccube_admin_route%/store/plugin/{id}/update", requirements={"id" = "\d+"}, name="admin_store_plugin_update", methods={"POST"}) |
187
|
|
|
* |
188
|
|
|
* @param Request $request |
189
|
|
|
* @param Plugin $Plugin |
190
|
|
|
* |
191
|
|
|
* @return RedirectResponse |
192
|
|
|
*/ |
193
|
|
|
public function update(Request $request, Plugin $Plugin) |
194
|
|
|
{ |
195
|
|
|
$form = $this->formFactory |
196
|
|
|
->createNamedBuilder( |
197
|
|
|
'form'.$Plugin->getId(), |
198
|
|
|
PluginManagementType::class, |
199
|
|
|
null, |
200
|
|
|
[ |
201
|
|
|
'plugin_id' => null, // placeHolder |
202
|
|
|
] |
203
|
|
|
) |
204
|
|
|
->getForm(); |
205
|
|
|
|
206
|
|
|
$message = ''; |
207
|
|
|
$form->handleRequest($request); |
208
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
209
|
|
|
$tmpDir = null; |
210
|
|
|
try { |
211
|
|
|
$formFile = $form['plugin_archive']->getData(); |
212
|
|
|
$tmpDir = $this->pluginService->createTempDir(); |
213
|
|
|
$tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension(); |
214
|
|
|
$formFile->move($tmpDir, $tmpFile); |
215
|
|
|
$this->pluginService->update($Plugin, $tmpDir.'/'.$tmpFile); |
216
|
|
|
$fs = new Filesystem(); |
217
|
|
|
$fs->remove($tmpDir); |
218
|
|
|
$this->addSuccess('admin.plugin.update.complete', 'admin'); |
219
|
|
|
|
220
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
221
|
|
|
} catch (PluginException $e) { |
222
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
223
|
|
|
$fs = new Filesystem(); |
224
|
|
|
$fs->remove($tmpDir); |
225
|
|
|
} |
226
|
|
|
$message = $e->getMessage(); |
227
|
|
|
} catch (\Exception $er) { |
228
|
|
|
// Catch composer install error | Other error |
229
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
230
|
|
|
$fs = new Filesystem(); |
231
|
|
|
$fs->remove($tmpDir); |
232
|
|
|
} |
233
|
|
|
log_error('plugin install failed.', ['original-message' => $er->getMessage()]); |
234
|
|
|
$message = 'admin.plugin.install.fail'; |
235
|
|
|
} |
236
|
|
|
} else { |
237
|
|
|
$errors = $form->getErrors(true); |
238
|
|
|
foreach ($errors as $error) { |
239
|
|
|
$message = $error->getMessage(); |
|
|
|
|
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
$this->addError($message, 'admin'); |
244
|
|
|
|
245
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* 対象のプラグインを有効にします。 |
250
|
|
|
* |
251
|
|
|
* @Route("/%eccube_admin_route%/store/plugin/{id}/enable", requirements={"id" = "\d+"}, name="admin_store_plugin_enable", methods={"POST"}) |
252
|
|
|
* |
253
|
|
|
* @param Plugin $Plugin |
254
|
|
|
* |
255
|
|
|
* @return RedirectResponse|JsonResponse |
256
|
|
|
* |
257
|
|
|
* @throws PluginException |
258
|
|
|
*/ |
259
|
|
|
public function enable(Plugin $Plugin, CacheUtil $cacheUtil, Request $request) |
|
|
|
|
260
|
|
|
{ |
261
|
|
|
$this->isTokenValid(); |
262
|
|
|
|
263
|
|
|
$log = null; |
264
|
|
|
|
265
|
|
|
if ($Plugin->isEnabled()) { |
266
|
|
|
if ($request->isXmlHttpRequest()) { |
267
|
|
|
return $this->json(['success' => true]); |
268
|
|
|
} else { |
269
|
|
|
$this->addError('admin.plugin.already.enable', 'admin'); |
270
|
|
|
} |
271
|
|
|
} else { |
272
|
|
|
// ストアからインストールしたプラグインは依存プラグインが有効化されているかを確認 |
273
|
|
|
if ($Plugin->getSource()) { |
274
|
|
|
$requires = $this->pluginService->getPluginRequired($Plugin); |
275
|
|
View Code Duplication |
$requires = array_filter($requires, function ($req) { |
|
|
|
|
276
|
|
|
$code = preg_replace('/^ec-cube\//', '', $req['name']); |
277
|
|
|
/** @var Plugin $DependPlugin */ |
278
|
|
|
$DependPlugin = $this->pluginRepository->findOneBy(['code' => $code]); |
279
|
|
|
|
280
|
|
|
return $DependPlugin->isEnabled() == false; |
|
|
|
|
281
|
|
|
}); |
282
|
|
|
if (!empty($requires)) { |
283
|
|
|
$names = array_map(function ($req) { |
284
|
|
|
return "「${req['description']}」"; |
285
|
|
|
}, $requires); |
286
|
|
|
$message = trans('%depend_name%を先に有効化してください。', ['%name%' => $Plugin->getName(), '%depend_name%' => implode(', ', $names)]); |
287
|
|
|
|
288
|
|
|
if ($request->isXmlHttpRequest()) { |
289
|
|
|
return $this->json(['success' => false, 'message' => $message], 400); |
290
|
|
|
} else { |
291
|
|
|
$this->addError($message, 'admin'); |
292
|
|
|
|
293
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
ob_start(); |
299
|
|
|
$this->pluginService->enable($Plugin); |
300
|
|
|
$log = ob_get_clean(); |
301
|
|
|
ob_end_flush(); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
// $cacheUtil->clearCache(); |
305
|
|
|
|
306
|
|
View Code Duplication |
if ($request->isXmlHttpRequest()) { |
|
|
|
|
307
|
|
|
return $this->json(['success' => true, 'log' => $log]); |
308
|
|
|
} else { |
309
|
|
|
$this->addSuccess(trans('「%plugin_name%」を有効にしました。', ['%plugin_name%' => $Plugin->getName()]), 'admin'); |
310
|
|
|
|
311
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* 対象のプラグインを無効にします。 |
317
|
|
|
* |
318
|
|
|
* @Route("/%eccube_admin_route%/store/plugin/{id}/disable", requirements={"id" = "\d+"}, name="admin_store_plugin_disable", methods={"POST"}) |
319
|
|
|
* |
320
|
|
|
* @param Request $request |
321
|
|
|
* @param Plugin $Plugin |
322
|
|
|
* @param CacheUtil $cacheUtil |
323
|
|
|
* |
324
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse|RedirectResponse |
325
|
|
|
*/ |
326
|
|
|
public function disable(Request $request, Plugin $Plugin, CacheUtil $cacheUtil) |
|
|
|
|
327
|
|
|
{ |
328
|
|
|
$this->isTokenValid(); |
329
|
|
|
|
330
|
|
|
$log = null; |
331
|
|
|
if ($Plugin->isEnabled()) { |
332
|
|
|
$dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode()); |
333
|
|
|
if (!empty($dependents)) { |
334
|
|
|
$dependName = $dependents[0]; |
335
|
|
|
$DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]); |
336
|
|
|
if ($DependPlugin) { |
337
|
|
|
$dependName = $DependPlugin->getName(); |
338
|
|
|
} |
339
|
|
|
$message = trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]); |
340
|
|
|
|
341
|
|
|
if ($request->isXmlHttpRequest()) { |
342
|
|
|
return $this->json(['message' => $message], 400); |
343
|
|
|
} else { |
344
|
|
|
$this->addError($message, 'admin'); |
345
|
|
|
|
346
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
ob_start(); |
351
|
|
|
$this->pluginService->disable($Plugin); |
352
|
|
|
$log = ob_get_clean(); |
353
|
|
|
ob_end_flush(); |
354
|
|
View Code Duplication |
} else { |
|
|
|
|
355
|
|
|
if ($request->isXmlHttpRequest()) { |
356
|
|
|
return $this->json(['success' => true, 'log' => $log]); |
357
|
|
|
} else { |
358
|
|
|
$this->addError('admin.plugin.already.disable', 'admin'); |
359
|
|
|
|
360
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
361
|
|
|
} |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
// キャッシュを削除してリダイレクト |
365
|
|
|
// リダイレクトにredirectToRoute関数を使用していないのは、削除したキャッシュが再生成されてしまうため。 |
366
|
|
|
$url = $this->generateUrl('admin_store_plugin'); |
367
|
|
|
// $cacheUtil->clearCache(); |
368
|
|
|
|
369
|
|
View Code Duplication |
if ($request->isXmlHttpRequest()) { |
|
|
|
|
370
|
|
|
return $this->json(['success' => true, 'log' => $log]); |
371
|
|
|
} else { |
372
|
|
|
$this->addSuccess('admin.plugin.disable.complete', 'admin'); |
373
|
|
|
|
374
|
|
|
return $this->redirect($url); |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* 対象のプラグインを削除します。 |
380
|
|
|
* |
381
|
|
|
* @Route("/%eccube_admin_route%/store/plugin/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_uninstall", methods={"DELETE"}) |
382
|
|
|
* |
383
|
|
|
* @param Plugin $Plugin |
384
|
|
|
* |
385
|
|
|
* @return RedirectResponse |
386
|
|
|
* |
387
|
|
|
* @throws \Exception |
388
|
|
|
*/ |
389
|
|
|
public function uninstall(Plugin $Plugin) |
390
|
|
|
{ |
391
|
|
|
$this->isTokenValid(); |
392
|
|
|
|
393
|
|
|
if ($Plugin->isEnabled()) { |
394
|
|
|
$this->addError('admin.plugin.uninstall.error.not_disable', 'admin'); |
395
|
|
|
|
396
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
// Check other plugin depend on it |
400
|
|
|
$pluginCode = $Plugin->getCode(); |
401
|
|
|
$otherDepend = $this->pluginService->findDependentPlugin($pluginCode); |
402
|
|
|
if (!empty($otherDepend)) { |
403
|
|
|
$DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]); |
404
|
|
|
$dependName = $otherDepend[0]; |
405
|
|
|
if ($DependPlugin) { |
406
|
|
|
$dependName = $DependPlugin->getName(); |
407
|
|
|
} |
408
|
|
|
$message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]); |
409
|
|
|
$this->addError($message, 'admin'); |
410
|
|
|
|
411
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
$this->pluginService->uninstall($Plugin); |
415
|
|
|
$this->addSuccess('admin.plugin.uninstall.complete', 'admin'); |
416
|
|
|
|
417
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
/** |
421
|
|
|
* プラグインファイルアップロード画面 |
422
|
|
|
* |
423
|
|
|
* @Route("/%eccube_admin_route%/store/plugin/install", name="admin_store_plugin_install") |
424
|
|
|
* @Template("@admin/Store/plugin_install.twig") |
425
|
|
|
* |
426
|
|
|
* @param Request $request |
427
|
|
|
* |
428
|
|
|
* @return array|RedirectResponse |
429
|
|
|
*/ |
430
|
|
|
public function install(Request $request) |
431
|
|
|
{ |
432
|
|
|
$form = $this->formFactory |
433
|
|
|
->createBuilder(PluginLocalInstallType::class) |
434
|
|
|
->getForm(); |
435
|
|
|
$errors = []; |
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
|
|
|
$this->addSuccess('admin.plugin.install.complete', 'admin'); |
453
|
|
|
|
454
|
|
|
return $this->redirectToRoute('admin_store_plugin'); |
455
|
|
|
} catch (PluginException $e) { |
456
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
457
|
|
|
$fs = new Filesystem(); |
458
|
|
|
$fs->remove($tmpDir); |
459
|
|
|
} |
460
|
|
|
log_error('plugin install failed.', ['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
|
|
|
log_error('plugin install failed.', ['original-message' => $er->getMessage()]); |
469
|
|
|
$this->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("/%eccube_admin_route%/store/plugin/authentication_setting", name="admin_store_authentication_setting") |
487
|
|
|
* @Template("@admin/Store/authentication_setting.twig") |
488
|
|
|
*/ |
489
|
|
|
public function authenticationSetting(Request $request) |
490
|
|
|
{ |
491
|
|
|
$builder = $this->formFactory |
492
|
|
|
->createBuilder(AuthenticationType::class, $this->BaseInfo); |
493
|
|
|
|
494
|
|
|
$form = $builder->getForm(); |
495
|
|
|
$form->handleRequest($request); |
496
|
|
|
|
497
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
498
|
|
|
// 認証キーの登録 and PHP path |
499
|
|
|
$this->BaseInfo = $form->getData(); |
500
|
|
|
$this->entityManager->persist($this->BaseInfo); |
501
|
|
|
$this->entityManager->flush(); |
502
|
|
|
|
503
|
|
|
$this->addSuccess('admin.common.save_complete', 'admin'); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
return [ |
507
|
|
|
'form' => $form->createView(), |
508
|
|
|
'eccubeUrl' => $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL), |
509
|
|
|
]; |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* フォルダ設置のみのプラグインを取得する. |
514
|
|
|
* |
515
|
|
|
* @param array $plugins |
516
|
|
|
* |
517
|
|
|
* @return array |
518
|
|
|
* @throws PluginException |
519
|
|
|
*/ |
520
|
|
|
protected function getUnregisteredPlugins(array $plugins) |
521
|
|
|
{ |
522
|
|
|
$finder = new Finder(); |
523
|
|
|
$pluginCodes = []; |
524
|
|
|
|
525
|
|
|
// DB登録済みプラグインコードのみ取得 |
526
|
|
|
foreach ($plugins as $key => $plugin) { |
527
|
|
|
$pluginCodes[] = $plugin->getCode(); |
528
|
|
|
} |
529
|
|
|
// DB登録済みプラグインコードPluginディレクトリから排他 |
530
|
|
|
$dirs = $finder->in($this->eccubeConfig['plugin_realdir'])->depth(0)->directories(); |
531
|
|
|
|
532
|
|
|
// プラグイン基本チェック |
533
|
|
|
$unregisteredPlugins = []; |
534
|
|
|
foreach ($dirs as $dir) { |
535
|
|
|
$pluginCode = $dir->getBasename(); |
536
|
|
|
if (in_array($pluginCode, $pluginCodes, true)) { |
537
|
|
|
continue; |
538
|
|
|
} |
539
|
|
|
try { |
540
|
|
|
$this->pluginService->checkPluginArchiveContent($dir->getRealPath()); |
541
|
|
|
} catch (PluginException $e) { |
542
|
|
|
//config.yamlに不備があった際は全てスキップ |
543
|
|
|
log_warning($e->getMessage()); |
544
|
|
|
continue; |
545
|
|
|
} |
546
|
|
|
$config = $this->pluginService->readConfig($dir->getRealPath()); |
547
|
|
|
$unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null; |
548
|
|
|
$unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null; |
549
|
|
|
$unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null; |
550
|
|
|
$unregisteredPlugins[$pluginCode]['enabled'] = Constant::DISABLED; |
551
|
|
|
$unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
return $unregisteredPlugins; |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.