Failed Conditions
Pull Request — 4.0 (#4000)
by
unknown
06:12
created

PluginController::uninstall()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
nc 1
nop 3
dl 0
loc 42
ccs 0
cts 22
cp 0
crap 20
rs 9.248
c 0
b 0
f 0
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\PluginApiException;
21
use Eccube\Exception\PluginException;
22
use Eccube\Form\Type\Admin\AuthenticationType;
23
use Eccube\Form\Type\Admin\PluginLocalInstallType;
24
use Eccube\Form\Type\Admin\PluginManagementType;
25
use Eccube\Repository\BaseInfoRepository;
26
use Eccube\Repository\PluginRepository;
27
use Eccube\Service\Composer\ComposerServiceInterface;
28
use Eccube\Service\PluginApiService;
29
use Eccube\Service\PluginService;
30
use Eccube\Service\SystemService;
31
use Eccube\Util\CacheUtil;
32
use Eccube\Util\StringUtil;
33
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
34
use Symfony\Component\DependencyInjection\Container;
35
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
36
use Symfony\Component\Filesystem\Filesystem;
37
use Symfony\Component\Finder\Finder;
38
use Symfony\Component\HttpFoundation\File\UploadedFile;
39
use Symfony\Component\HttpFoundation\JsonResponse;
40
use Symfony\Component\HttpFoundation\RedirectResponse;
41
use Symfony\Component\HttpFoundation\Request;
42
use Symfony\Component\HttpKernel\KernelEvents;
43
use Symfony\Component\Routing\Annotation\Route;
44
use Symfony\Component\Routing\Exception\RouteNotFoundException;
45
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
46
47
48
class PluginController extends AbstractController
49
{
50
    /**
51
     * @var PluginService
52
     */
53
    protected $pluginService;
54
55
    /**
56
     * @var BaseInfo
57
     */
58
    protected $BaseInfo;
59
60
    /**
61
     * @var PluginRepository
62
     */
63
    protected $pluginRepository;
64
65
    /**
66
     * @var PluginApiService
67
     */
68
    protected $pluginApiService;
69
70
    /**
71
     * @var ComposerServiceInterface
72
     */
73
    private $composerService;
74
75
    /**
76
     * @var SystemService
77
     */
78
    private $systemService;
79
80
    /**
81
     * PluginController constructor.
82
     *
83
     * @param PluginRepository $pluginRepository
84
     * @param PluginService $pluginService
85
     * @param BaseInfoRepository $baseInfoRepository
86
     * @param PluginApiService $pluginApiService
87
     * @param ComposerServiceInterface $composerService
88
     *
89
     * @throws \Doctrine\ORM\NoResultException
90
     * @throws \Doctrine\ORM\NonUniqueResultException
91
     */
92
    public function __construct(
93
        PluginRepository $pluginRepository,
94
        PluginService $pluginService,
95
        BaseInfoRepository $baseInfoRepository,
96
        PluginApiService $pluginApiService,
97
        ComposerServiceInterface $composerService,
98
        SystemService $systemService
99
    ){
100
        $this->pluginRepository = $pluginRepository;
101
        $this->pluginService = $pluginService;
102
        $this->BaseInfo = $baseInfoRepository->get();
103
        $this->pluginApiService = $pluginApiService;
104
        $this->composerService = $composerService;
105
        $this->systemService = $systemService;
106
    }
107
108
    /**
109
     * インストール済プラグイン画面
110
     *
111
     * @Route("/%eccube_admin_route%/store/plugin", name="admin_store_plugin")
112
     * @Template("@admin/Store/plugin.twig")
113
     *
114
     * @return array
115
     *
116
     * @throws PluginException
117
     */
118
    public function index()
119
    {
120
        $pluginForms = [];
121
        $configPages = [];
122
        $Plugins = $this->pluginRepository->findBy([], ['code' => 'ASC']);
123
124
        // ファイル設置プラグインの取得.
125
        $unregisteredPlugins = $this->getUnregisteredPlugins($Plugins);
126
        $unregisteredPluginsConfigPages = [];
127
        foreach ($unregisteredPlugins as $unregisteredPlugin) {
128
            try {
129
                $code = $unregisteredPlugin['code'];
130
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
131
                $unregisteredPluginsConfigPages[$code] = $this->generateUrl('plugin_'.$code.'_config');
132
            } catch (RouteNotFoundException $e) {
133
                // プラグインで設定画面のルートが定義されていない場合は無視
134
            }
135
        }
136
137
        $officialPlugins = [];
138
        $unofficialPlugins = [];
139
140
        foreach ($Plugins as $Plugin) {
141
            $form = $this->formFactory
142
                ->createNamedBuilder(
143
                    'form'.$Plugin->getId(),
144
                    PluginManagementType::class,
145
                    null,
146
                    [
147
                        'plugin_id' => $Plugin->getId(),
148
                    ]
149
                )
150
                ->getForm();
151
            $pluginForms[$Plugin->getId()] = $form->createView();
152
153
            try {
154
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
155
                $configPages[$Plugin->getCode()] = $this->generateUrl(Container::underscore($Plugin->getCode()).'_admin_config');
156
            } catch (\Exception $e) {
157
                // プラグインで設定画面のルートが定義されていない場合は無視
158
            }
159
            if ($Plugin->getSource() == 0) {
160
                // 商品IDが設定されていない場合、非公式プラグイン
161
                $unofficialPlugins[] = $Plugin;
162
            } else {
163
                $officialPlugins[$Plugin->getSource()] = $Plugin;
164
            }
165
        }
166
167
        // オーナーズストア通信
168
        $officialPluginsDetail = [];
169
        try {
170
            $data = $this->pluginApiService->getPurchased();
171
            foreach ($data as $item) {
172
                if (isset($officialPlugins[$item['id']]) === false) {
173
                    $Plugin = new Plugin();
174
                    $Plugin->setName($item['name']);
175
                    $Plugin->setCode($item['code']);
176
                    $Plugin->setVersion($item['version']);
177
                    $Plugin->setSource($item['id']);
178
                    $Plugin->setEnabled(false);
179
                    $officialPlugins[$item['id']] = $Plugin;
180
                }
181
                $officialPluginsDetail[$item['id']] = $item;
182
            }
183
        } catch (PluginApiException $e) {
184
            $this->addWarning($e->getMessage(), 'admin');
185
        }
186
187
        return [
188
            'plugin_forms' => $pluginForms,
189
            'officialPlugins' => $officialPlugins,
190
            'unofficialPlugins' => $unofficialPlugins,
191
            'configPages' => $configPages,
192
            'unregisteredPlugins' => $unregisteredPlugins,
193
            'unregisteredPluginsConfigPages' => $unregisteredPluginsConfigPages,
194
            'officialPluginsDetail' => $officialPluginsDetail,
195
        ];
196
    }
197
198
    /**
199
     * インストール済プラグインからのアップデート
200
     *
201
     * @Route("/%eccube_admin_route%/store/plugin/{id}/update", requirements={"id" = "\d+"}, name="admin_store_plugin_update", methods={"POST"})
202
     *
203
     * @param Request $request
204
     * @param Plugin $Plugin
205
     * @param CacheUtil $cacheUtil
206
     *
207
     * @return RedirectResponse
208
     */
209
    public function update(Request $request, Plugin $Plugin, CacheUtil $cacheUtil)
210
    {
211
        $form = $this->formFactory
212
            ->createNamedBuilder(
213
                'form'.$Plugin->getId(),
214
                PluginManagementType::class,
215
                null,
216
                [
217
                    'plugin_id' => null, // placeHolder
218
                ]
219
            )
220
            ->getForm();
221
222
        $message = '';
223
        $form->handleRequest($request);
224
        if ($form->isSubmitted() && $form->isValid()) {
225
            $tmpDir = null;
226
            try {
227
                $cacheUtil->clearCache();
228
                $formFile = $form['plugin_archive']->getData();
229
                $tmpDir = $this->pluginService->createTempDir();
230
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
231
                $formFile->move($tmpDir, $tmpFile);
232
                $this->pluginService->update($Plugin, $tmpDir.'/'.$tmpFile);
233
                $fs = new Filesystem();
234
                $fs->remove($tmpDir);
235
                $this->addSuccess(trans('admin.store.plugin.update.complete', ['%plugin_name%' => $Plugin->getName()]), 'admin');
236
237
                return $this->redirectToRoute('admin_store_plugin');
238
            } catch (PluginException $e) {
239
                if (!empty($tmpDir) && file_exists($tmpDir)) {
240
                    $fs = new Filesystem();
241
                    $fs->remove($tmpDir);
242
                }
243
                $message = $e->getMessage();
244
            } catch (\Exception $er) {
245
                // Catch composer install error | Other error
246
                if (!empty($tmpDir) && file_exists($tmpDir)) {
247
                    $fs = new Filesystem();
248
                    $fs->remove($tmpDir);
249
                }
250
                log_error('plugin install failed.', ['original-message' => $er->getMessage()]);
251
                $message = trans('admin.store.plugin.update.failed', ['%plugin_name%' => $Plugin->getName()]);
252
            }
253
        } else {
254
            $errors = $form->getErrors(true);
255
            foreach ($errors as $error) {
256
                $message = $error->getMessage();
0 ignored issues
show
Bug introduced by
The method getMessage does only exist in Symfony\Component\Form\FormError, but not in Symfony\Component\Form\FormErrorIterator.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
257
            }
258
        }
259
260
        $this->addError($message, 'admin');
261
262
        return $this->redirectToRoute('admin_store_plugin');
263
    }
264
265
    /**
266
     * 対象のプラグインを有効にします。
267
     *
268
     * @Route("/%eccube_admin_route%/store/plugin/{id}/enable", requirements={"id" = "\d+"}, name="admin_store_plugin_enable", methods={"POST"})
269
     *
270
     * @param Plugin $Plugin
271
     *
272
     * @return RedirectResponse|JsonResponse
273
     *
274
     * @throws PluginException
275
     */
276
    public function enable(Plugin $Plugin, CacheUtil $cacheUtil, Request $request, EventDispatcherInterface $dispatcher)
277
    {
278
        // .maintenanceファイルを設置
279
        $this->systemService->switchMaintenance(true);
280
281
        // TERMINATE時のイベントを設定
282
        $dispatcher->addListener(KernelEvents::TERMINATE, function () {
283
            // .maintenanceファイルを削除
284
            $this->systemService->switchMaintenance();
285
        });
286
287
        $this->isTokenValid();
288
289
        $cacheUtil->clearCache();
290
291
        $log = null;
0 ignored issues
show
Unused Code introduced by
$log is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
292
293
        if ($Plugin->isEnabled()) {
294
            if ($request->isXmlHttpRequest()) {
295
                return $this->json(['success' => true]);
296
            } else {
297
                $this->addError(trans('admin.store.plugin.already.enabled', ['%plugin_name%' => $Plugin->getName()]), 'admin');
298
                return $this->redirectToRoute('admin_store_plugin');
299
            }
300
        } else {
301
            // ストアからインストールしたプラグインは依存プラグインが有効化されているかを確認
302
            if ($Plugin->getSource()) {
303
                $requires = $this->pluginService->getPluginRequired($Plugin);
304 View Code Duplication
                $requires = array_filter($requires, function ($req) {
305
                    $code = preg_replace('/^ec-cube\//', '', $req['name']);
306
                    /** @var Plugin $DependPlugin */
307
                    $DependPlugin = $this->pluginRepository->findOneBy(['code' => $code]);
308
309
                    return $DependPlugin->isEnabled() == false;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
310
                });
311
                if (!empty($requires)) {
312
                    $names = array_map(function ($req) {
313
                        return "「${req['description']}」";
314
                    }, $requires);
315
                    $message = trans('%depend_name%を先に有効化してください。', ['%name%' => $Plugin->getName(), '%depend_name%' => implode(', ', $names)]);
316
317 View Code Duplication
                    if ($request->isXmlHttpRequest()) {
318
                        return $this->json(['success' => false, 'message' => $message], 400);
319
                    } else {
320
                        $this->addError($message, 'admin');
321
322
                        return $this->redirectToRoute('admin_store_plugin');
323
                    }
324
                }
325
            }
326
327
328
            try {
329
                ob_start();
330
331
                if (!$Plugin->isInitialized()) {
332
                    $this->pluginService->installWithCode($Plugin->getCode());
333
                }
334
335
                $this->pluginService->enable($Plugin);
336
            } finally {
337
                $log = ob_get_clean();
338
                while (ob_get_level() > 0) {
339
                    ob_end_flush();
340
                }
341
            }
342
        }
343
344
        if ($request->isXmlHttpRequest()) {
345
            return $this->json(['success' => true, 'log' => $log]);
346
        } else {
347
            $this->addSuccess(trans('admin.store.plugin.enable.complete', ['%plugin_name%' => $Plugin->getName()]), 'admin');
348
349
            return $this->redirectToRoute('admin_store_plugin');
350
        }
351
    }
352
353
    /**
354
     * 対象のプラグインを無効にします。
355
     *
356
     * @Route("/%eccube_admin_route%/store/plugin/{id}/disable", requirements={"id" = "\d+"}, name="admin_store_plugin_disable", methods={"POST"})
357
     *
358
     * @param Request $request
359
     * @param Plugin $Plugin
360
     * @param CacheUtil $cacheUtil
361
     *
362
     * @return \Symfony\Component\HttpFoundation\JsonResponse|RedirectResponse
363
     */
364
    public function disable(Request $request, Plugin $Plugin, CacheUtil $cacheUtil, EventDispatcherInterface $dispatcher)
365
    {
366
        // .maintenanceファイルを設置
367
        $this->systemService->switchMaintenance(true);
368
369
        // TERMINATE時のイベントを設定
370
        $dispatcher->addListener(KernelEvents::TERMINATE, function () {
371
            // .maintenanceファイルを削除
372
            $this->systemService->switchMaintenance();
373
        });
374
375
        $this->isTokenValid();
376
377
        $cacheUtil->clearCache();
378
379
        $log = null;
380
        if ($Plugin->isEnabled()) {
381
            $dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode());
382
            if (!empty($dependents)) {
383
                $dependName = $dependents[0];
384
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]);
385
                if ($DependPlugin) {
386
                    $dependName = $DependPlugin->getName();
387
                }
388
                $message = trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
389
390 View Code Duplication
                if ($request->isXmlHttpRequest()) {
391
                    return $this->json(['message' => $message], 400);
392
                } else {
393
                    $this->addError($message, 'admin');
394
395
                    return $this->redirectToRoute('admin_store_plugin');
396
                }
397
            }
398
399
            try {
400
                ob_start();
401
                $this->pluginService->disable($Plugin);
402
            } finally {
403
                $log = ob_get_clean();
404
                while (ob_get_level() > 0) {
405
                    ob_end_flush();
406
                }
407
            }
408
        } else {
409
            if ($request->isXmlHttpRequest()) {
410
                return $this->json(['success' => true, 'log' => $log]);
411
            } else {
412
                $this->addError(trans('admin.store.plugin.already.disabled', ['%plugin_name%' => $Plugin->getName()]), 'admin');
413
414
                return $this->redirectToRoute('admin_store_plugin');
415
            }
416
        }
417
418
        if ($request->isXmlHttpRequest()) {
419
            return $this->json(['success' => true, 'log' => $log]);
420
        } else {
421
            $this->addSuccess(trans('admin.store.plugin.disable.complete', ['%plugin_name%' => $Plugin->getName()]), 'admin');
422
423
            return $this->redirectToRoute('admin_store_plugin');
424
        }
425
    }
426
427
    /**
428
     * 対象のプラグインを削除します。
429
     *
430
     * @Route("/%eccube_admin_route%/store/plugin/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_uninstall", methods={"DELETE"})
431
     *
432
     * @param Plugin $Plugin
433
     * @param CacheUtil $cacheUtil
434
     *
435
     * @return RedirectResponse
436
     *
437
     * @throws \Exception
438
     */
439
    public function uninstall(Plugin $Plugin, CacheUtil $cacheUtil, EventDispatcherInterface $dispatcher)
0 ignored issues
show
Unused Code introduced by
The parameter $Plugin is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $cacheUtil is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $dispatcher is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
440
    {
441
        die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method uninstall() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
442
        // .maintenanceファイルを設置
443
        $this->systemService->switchMaintenance(true);
0 ignored issues
show
Unused Code introduced by
$this->systemService->switchMaintenance(true); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
444
445
        // TERMINATE時のイベントを設定
446
        $dispatcher->addListener(KernelEvents::TERMINATE, function () {
447
            // .maintenanceファイルを削除
448
            $this->systemService->switchMaintenance();
449
        });
450
451
        $this->isTokenValid();
452
453
        if ($Plugin->isEnabled()) {
454
            $this->addError('admin.plugin.uninstall.error.not_disable', 'admin');
455
456
            return $this->redirectToRoute('admin_store_plugin');
457
        }
458
459
        // Check other plugin depend on it
460
        $pluginCode = $Plugin->getCode();
461
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
462
        if (!empty($otherDepend)) {
463
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
464
            $dependName = $otherDepend[0];
465
            if ($DependPlugin) {
466
                $dependName = $DependPlugin->getName();
467
            }
468
            $message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
469
            $this->addError($message, 'admin');
470
471
            return $this->redirectToRoute('admin_store_plugin');
472
        }
473
474
        $cacheUtil->clearCache();
475
476
        $this->pluginService->uninstall($Plugin);
477
        $this->addSuccess('admin.store.plugin.uninstall.complete', 'admin');
478
479
        return $this->redirectToRoute('admin_store_plugin');
480
    }
481
482
    /**
483
     * プラグインファイルアップロード画面
484
     *
485
     * @Route("/%eccube_admin_route%/store/plugin/install", name="admin_store_plugin_install")
486
     * @Template("@admin/Store/plugin_install.twig")
487
     *
488
     * @param Request $request
489
     * @param CacheUtil $cacheUtil
490
     *
491
     * @return array|RedirectResponse
492
     */
493
    public function install(Request $request, CacheUtil $cacheUtil)
494
    {
495
        $form = $this->formFactory
496
            ->createBuilder(PluginLocalInstallType::class)
497
            ->getForm();
498
        $errors = [];
499
        $form->handleRequest($request);
500
        if ($form->isSubmitted() && $form->isValid()) {
501
            $tmpDir = null;
502
            try {
503
504
                $cacheUtil->clearCache();
505
506
                /** @var UploadedFile $formFile */
507
                $formFile = $form['plugin_archive']->getData();
508
                $tmpDir = $this->pluginService->createTempDir();
509
                // 拡張子を付けないとpharが動かないので付ける
510
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
511
                $formFile->move($tmpDir, $tmpFile);
512
                $tmpPath = $tmpDir.'/'.$tmpFile;
513
                $this->pluginService->install($tmpPath);
514
                // Remove tmp file
515
                $fs = new Filesystem();
516
                $fs->remove($tmpDir);
517
                $this->addSuccess('admin.store.plugin.install.complete', 'admin');
518
519
                return $this->redirectToRoute('admin_store_plugin');
520
            } catch (PluginException $e) {
521
                if (!empty($tmpDir) && file_exists($tmpDir)) {
522
                    $fs = new Filesystem();
523
                    $fs->remove($tmpDir);
524
                }
525
                log_error('plugin install failed.', ['original-message' => $e->getMessage()]);
526
                $errors[] = $e;
527
            } catch (\Exception $er) {
528
                // Catch composer install error | Other error
529
                if (!empty($tmpDir) && file_exists($tmpDir)) {
530
                    $fs = new Filesystem();
531
                    $fs->remove($tmpDir);
532
                }
533
                log_error('plugin install failed.', ['original-message' => $er->getMessage()]);
534
                $this->addError('admin.store.plugin.install.failed', 'admin');
535
            }
536
        } else {
537
            foreach ($form->getErrors(true) as $error) {
538
                $errors[] = $error;
539
            }
540
        }
541
542
        return [
543
            'form' => $form->createView(),
544
            'errors' => $errors,
545
        ];
546
    }
547
548
    /**
549
     * 認証キー設定画面
550
     *
551
     * @Route("/%eccube_admin_route%/store/plugin/authentication_setting", name="admin_store_authentication_setting")
552
     * @Template("@admin/Store/authentication_setting.twig")
553
     *
554
     * @param Request $request
555
     *
556
     * @return array
557
     */
558
    public function authenticationSetting(Request $request, CacheUtil $cacheUtil)
559
    {
560
561
        $builder = $this->formFactory
562
            ->createBuilder(AuthenticationType::class, $this->BaseInfo);
563
564
        $form = $builder->getForm();
565
        $form->handleRequest($request);
566
567
        if ($form->isSubmitted() && $form->isValid()) {
568
            // 認証キーの登録 and PHP path
569
            $this->BaseInfo = $form->getData();
570
            $this->entityManager->persist($this->BaseInfo);
571
            $this->entityManager->flush();
572
573
            // composerの認証を更新
574
            $this->composerService->configureRepository($this->BaseInfo);
575
            $this->addSuccess('admin.common.save_complete', 'admin');
576
            $cacheUtil->clearCache();
577
578
            return $this->redirectToRoute('admin_store_authentication_setting');
579
        }
580
581
        return [
582
            'form' => $form->createView(),
583
            'eccubeUrl' => $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL),
584
            'eccubeShopName' => $this->BaseInfo->getShopName(),
585
        ];
586
    }
587
588
    /**
589
     * フォルダ設置のみのプラグインを取得する.
590
     *
591
     * @param array $plugins
592
     *
593
     * @return array
594
     *
595
     * @throws PluginException
596
     */
597
    protected function getUnregisteredPlugins(array $plugins)
598
    {
599
        $finder = new Finder();
600
        $pluginCodes = [];
601
602
        // DB登録済みプラグインコードのみ取得
603
        foreach ($plugins as $key => $plugin) {
604
            $pluginCodes[] = $plugin->getCode();
605
        }
606
        // DB登録済みプラグインコードPluginディレクトリから排他
607
        $dirs = $finder->in($this->eccubeConfig['plugin_realdir'])->depth(0)->directories();
608
609
        // プラグイン基本チェック
610
        $unregisteredPlugins = [];
611
        foreach ($dirs as $dir) {
612
            $pluginCode = $dir->getBasename();
613
            if (in_array($pluginCode, $pluginCodes, true)) {
614
                continue;
615
            }
616
            try {
617
                $this->pluginService->checkPluginArchiveContent($dir->getRealPath());
618
            } catch (PluginException $e) {
619
                //config.yamlに不備があった際は全てスキップ
620
                log_warning($e->getMessage());
621
                continue;
622
            }
623
            $config = $this->pluginService->readConfig($dir->getRealPath());
624
            $unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null;
625
            $unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null;
626
            $unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null;
627
            $unregisteredPlugins[$pluginCode]['enabled'] = Constant::DISABLED;
628
            $unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null;
629
        }
630
631
        return $unregisteredPlugins;
632
    }
633
}
634