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

PluginController::disable()   B

Complexity

Conditions 8
Paths 14

Size

Total Lines 62

Duplication

Lines 7
Ratio 11.29 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
nc 14
nop 4
dl 7
loc 62
ccs 0
cts 22
cp 0
crap 72
rs 7.5846
c 0
b 0
f 0

How to fix   Long Method   

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