Completed
Pull Request — 4.0 (#4000)
by
unknown
06:58
created

PluginController::install()   B

Complexity

Conditions 10
Paths 43

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
nc 43
nop 2
dl 0
loc 54
ccs 0
cts 24
cp 0
crap 110
rs 7.1369
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        if (!$request->query->has('maintenance_mode')) {
279
            $this->systemService->switchMaintenance(true);
280
            // TERMINATE時のイベントを設定
281
            $dispatcher->addListener(KernelEvents::TERMINATE, function () {
282
            // .maintenanceファイルを削除
283
            $this->systemService->switchMaintenance();
284
            });
285
        } else {
286
            // TERMINATE時のイベントを設定
287
            $dispatcher->addListener(KernelEvents::TERMINATE, function () {
288
            // .maintenanceファイルを削除
289
            $this->systemService->switchMaintenance(false,SystemService::AUTO_MAINTENANCE_UPDATE);
290
            });
291
        }
292
293
        $this->isTokenValid();
294
295
        $cacheUtil->clearCache();
296
297
        $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...
298
299
        if ($Plugin->isEnabled()) {
300
            if ($request->isXmlHttpRequest()) {
301
                return $this->json(['success' => true]);
302
            } else {
303
                $this->addError(trans('admin.store.plugin.already.enabled', ['%plugin_name%' => $Plugin->getName()]), 'admin');
304
                return $this->redirectToRoute('admin_store_plugin');
305
            }
306
        } else {
307
            // ストアからインストールしたプラグインは依存プラグインが有効化されているかを確認
308
            if ($Plugin->getSource()) {
309
                $requires = $this->pluginService->getPluginRequired($Plugin);
310 View Code Duplication
                $requires = array_filter($requires, function ($req) {
311
                    $code = preg_replace('/^ec-cube\//', '', $req['name']);
312
                    /** @var Plugin $DependPlugin */
313
                    $DependPlugin = $this->pluginRepository->findOneBy(['code' => $code]);
314
315
                    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...
316
                });
317
                if (!empty($requires)) {
318
                    $names = array_map(function ($req) {
319
                        return "「${req['description']}」";
320
                    }, $requires);
321
                    $message = trans('%depend_name%を先に有効化してください。', ['%name%' => $Plugin->getName(), '%depend_name%' => implode(', ', $names)]);
322
323 View Code Duplication
                    if ($request->isXmlHttpRequest()) {
324
                        return $this->json(['success' => false, 'message' => $message], 400);
325
                    } else {
326
                        $this->addError($message, 'admin');
327
328
                        return $this->redirectToRoute('admin_store_plugin');
329
                    }
330
                }
331
            }
332
333
334
            try {
335
                ob_start();
336
337
                if (!$Plugin->isInitialized()) {
338
                    $this->pluginService->installWithCode($Plugin->getCode());
339
                }
340
341
                $this->pluginService->enable($Plugin);
342
            } finally {
343
                $log = ob_get_clean();
344
                while (ob_get_level() > 0) {
345
                    ob_end_flush();
346
                }
347
            }
348
        }
349
350
        if ($request->isXmlHttpRequest()) {
351
            return $this->json(['success' => true, 'log' => $log]);
352
        } else {
353
            $this->addSuccess(trans('admin.store.plugin.enable.complete', ['%plugin_name%' => $Plugin->getName()]), 'admin');
354
355
            return $this->redirectToRoute('admin_store_plugin');
356
        }
357
    }
358
359
    /**
360
     * 対象のプラグインを無効にします。
361
     *
362
     * @Route("/%eccube_admin_route%/store/plugin/{id}/disable", requirements={"id" = "\d+"}, name="admin_store_plugin_disable", methods={"POST"})
363
     *
364
     * @param Request $request
365
     * @param Plugin $Plugin
366
     * @param CacheUtil $cacheUtil
367
     *
368
     * @return \Symfony\Component\HttpFoundation\JsonResponse|RedirectResponse
369
     */
370
    public function disable(Request $request, Plugin $Plugin, CacheUtil $cacheUtil, EventDispatcherInterface $dispatcher)
371
    {
372
        $mentenance_mode = $request->query->get('maintenance_mode');
373
        if (SystemService::AUTO_MAINTENANCE_UPDATE == $mentenance_mode) {
374
            // .maintenanceファイルを設置
375
            $this->systemService->switchMaintenance(true, SystemService::AUTO_MAINTENANCE_UPDATE);
376
        } else {
377
            $this->systemService->switchMaintenance(true);
378
            // TERMINATE時のイベントを設定
379
            $dispatcher->addListener(KernelEvents::TERMINATE, function () {
380
                // .maintenanceファイルを削除
381
                $this->systemService->switchMaintenance();
382
            });
383
        }
384
385
        $this->isTokenValid();
386
387
        $cacheUtil->clearCache();
388
389
        $log = null;
390
        if ($Plugin->isEnabled()) {
391
            $dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode());
392
            if (!empty($dependents)) {
393
                $dependName = $dependents[0];
394
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]);
395
                if ($DependPlugin) {
396
                    $dependName = $DependPlugin->getName();
397
                }
398
                $message = trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
399
400 View Code Duplication
                if ($request->isXmlHttpRequest()) {
401
                    return $this->json(['message' => $message], 400);
402
                } else {
403
                    $this->addError($message, 'admin');
404
405
                    return $this->redirectToRoute('admin_store_plugin');
406
                }
407
            }
408
409
            try {
410
                ob_start();
411
                $this->pluginService->disable($Plugin);
412
            } finally {
413
                $log = ob_get_clean();
414
                while (ob_get_level() > 0) {
415
                    ob_end_flush();
416
                }
417
            }
418
        } else {
419
            if ($request->isXmlHttpRequest()) {
420
                return $this->json(['success' => true, 'log' => $log]);
421
            } else {
422
                $this->addError(trans('admin.store.plugin.already.disabled', ['%plugin_name%' => $Plugin->getName()]), 'admin');
423
424
                return $this->redirectToRoute('admin_store_plugin');
425
            }
426
        }
427
428
        if ($request->isXmlHttpRequest()) {
429
            return $this->json(['success' => true, 'log' => $log]);
430
        } else {
431
            $this->addSuccess(trans('admin.store.plugin.disable.complete', ['%plugin_name%' => $Plugin->getName()]), 'admin');
432
433
            return $this->redirectToRoute('admin_store_plugin');
434
        }
435
    }
436
437
    /**
438
     * 対象のプラグインを削除します。
439
     *
440
     * @Route("/%eccube_admin_route%/store/plugin/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_uninstall", methods={"DELETE"})
441
     *
442
     * @param Plugin $Plugin
443
     * @param CacheUtil $cacheUtil
444
     *
445
     * @return RedirectResponse
446
     *
447
     * @throws \Exception
448
     */
449
    public function uninstall(Plugin $Plugin, CacheUtil $cacheUtil)
450
    {
451
452
        $this->isTokenValid();
453
454
        if ($Plugin->isEnabled()) {
455
            $this->addError('admin.plugin.uninstall.error.not_disable', 'admin');
456
457
            return $this->redirectToRoute('admin_store_plugin');
458
        }
459
460
        // Check other plugin depend on it
461
        $pluginCode = $Plugin->getCode();
462
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
463
        if (!empty($otherDepend)) {
464
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
465
            $dependName = $otherDepend[0];
466
            if ($DependPlugin) {
467
                $dependName = $DependPlugin->getName();
468
            }
469
            $message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
470
            $this->addError($message, 'admin');
471
472
            return $this->redirectToRoute('admin_store_plugin');
473
        }
474
475
        $cacheUtil->clearCache();
476
477
        $this->pluginService->uninstall($Plugin);
478
        $this->addSuccess('admin.store.plugin.uninstall.complete', 'admin');
479
480
        return $this->redirectToRoute('admin_store_plugin');
481
    }
482
483
    /**
484
     * プラグインファイルアップロード画面
485
     *
486
     * @Route("/%eccube_admin_route%/store/plugin/install", name="admin_store_plugin_install")
487
     * @Template("@admin/Store/plugin_install.twig")
488
     *
489
     * @param Request $request
490
     * @param CacheUtil $cacheUtil
491
     *
492
     * @return array|RedirectResponse
493
     */
494
    public function install(Request $request, CacheUtil $cacheUtil)
495
    {
496
        $form = $this->formFactory
497
            ->createBuilder(PluginLocalInstallType::class)
498
            ->getForm();
499
        $errors = [];
500
        $form->handleRequest($request);
501
        if ($form->isSubmitted() && $form->isValid()) {
502
            $tmpDir = null;
503
            try {
504
505
                $cacheUtil->clearCache();
506
507
                /** @var UploadedFile $formFile */
508
                $formFile = $form['plugin_archive']->getData();
509
                $tmpDir = $this->pluginService->createTempDir();
510
                // 拡張子を付けないとpharが動かないので付ける
511
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
512
                $formFile->move($tmpDir, $tmpFile);
513
                $tmpPath = $tmpDir.'/'.$tmpFile;
514
                $this->pluginService->install($tmpPath);
515
                // Remove tmp file
516
                $fs = new Filesystem();
517
                $fs->remove($tmpDir);
518
                $this->addSuccess('admin.store.plugin.install.complete', 'admin');
519
520
                return $this->redirectToRoute('admin_store_plugin');
521
            } catch (PluginException $e) {
522
                if (!empty($tmpDir) && file_exists($tmpDir)) {
523
                    $fs = new Filesystem();
524
                    $fs->remove($tmpDir);
525
                }
526
                log_error('plugin install failed.', ['original-message' => $e->getMessage()]);
527
                $errors[] = $e;
528
            } catch (\Exception $er) {
529
                // Catch composer install error | Other error
530
                if (!empty($tmpDir) && file_exists($tmpDir)) {
531
                    $fs = new Filesystem();
532
                    $fs->remove($tmpDir);
533
                }
534
                log_error('plugin install failed.', ['original-message' => $er->getMessage()]);
535
                $this->addError('admin.store.plugin.install.failed', 'admin');
536
            }
537
        } else {
538
            foreach ($form->getErrors(true) as $error) {
539
                $errors[] = $error;
540
            }
541
        }
542
543
        return [
544
            'form' => $form->createView(),
545
            'errors' => $errors,
546
        ];
547
    }
548
549
    /**
550
     * 認証キー設定画面
551
     *
552
     * @Route("/%eccube_admin_route%/store/plugin/authentication_setting", name="admin_store_authentication_setting")
553
     * @Template("@admin/Store/authentication_setting.twig")
554
     *
555
     * @param Request $request
556
     *
557
     * @return array
558
     */
559
    public function authenticationSetting(Request $request, CacheUtil $cacheUtil)
560
    {
561
562
        $builder = $this->formFactory
563
            ->createBuilder(AuthenticationType::class, $this->BaseInfo);
564
565
        $form = $builder->getForm();
566
        $form->handleRequest($request);
567
568
        if ($form->isSubmitted() && $form->isValid()) {
569
            // 認証キーの登録 and PHP path
570
            $this->BaseInfo = $form->getData();
571
            $this->entityManager->persist($this->BaseInfo);
572
            $this->entityManager->flush();
573
574
            // composerの認証を更新
575
            $this->composerService->configureRepository($this->BaseInfo);
576
            $this->addSuccess('admin.common.save_complete', 'admin');
577
            $cacheUtil->clearCache();
578
579
            return $this->redirectToRoute('admin_store_authentication_setting');
580
        }
581
582
        return [
583
            'form' => $form->createView(),
584
            'eccubeUrl' => $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL),
585
            'eccubeShopName' => $this->BaseInfo->getShopName(),
586
        ];
587
    }
588
589
    /**
590
     * フォルダ設置のみのプラグインを取得する.
591
     *
592
     * @param array $plugins
593
     *
594
     * @return array
595
     *
596
     * @throws PluginException
597
     */
598
    protected function getUnregisteredPlugins(array $plugins)
599
    {
600
        $finder = new Finder();
601
        $pluginCodes = [];
602
603
        // DB登録済みプラグインコードのみ取得
604
        foreach ($plugins as $key => $plugin) {
605
            $pluginCodes[] = $plugin->getCode();
606
        }
607
        // DB登録済みプラグインコードPluginディレクトリから排他
608
        $dirs = $finder->in($this->eccubeConfig['plugin_realdir'])->depth(0)->directories();
609
610
        // プラグイン基本チェック
611
        $unregisteredPlugins = [];
612
        foreach ($dirs as $dir) {
613
            $pluginCode = $dir->getBasename();
614
            if (in_array($pluginCode, $pluginCodes, true)) {
615
                continue;
616
            }
617
            try {
618
                $this->pluginService->checkPluginArchiveContent($dir->getRealPath());
619
            } catch (PluginException $e) {
620
                //config.yamlに不備があった際は全てスキップ
621
                log_warning($e->getMessage());
622
                continue;
623
            }
624
            $config = $this->pluginService->readConfig($dir->getRealPath());
625
            $unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null;
626
            $unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null;
627
            $unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null;
628
            $unregisteredPlugins[$pluginCode]['enabled'] = Constant::DISABLED;
629
            $unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null;
630
        }
631
632
        return $unregisteredPlugins;
633
    }
634
}
635