Failed Conditions
Push — dev/recommend-plugins ( 237cf5 )
by Kiyotaka
07:46
created

PluginController::index()   F

Complexity

Conditions 11
Paths 520

Size

Total Lines 90

Duplication

Lines 6
Ratio 6.67 %

Importance

Changes 0
Metric Value
cc 11
nc 520
nop 0
dl 6
loc 90
rs 3.2715
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\PluginApiService;
28
use Eccube\Service\PluginService;
29
use Eccube\Util\CacheUtil;
30
use Eccube\Util\StringUtil;
31
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
32
use Symfony\Component\DependencyInjection\Container;
33
use Symfony\Component\Filesystem\Filesystem;
34
use Symfony\Component\Finder\Finder;
35
use Symfony\Component\HttpFoundation\File\UploadedFile;
36
use Symfony\Component\HttpFoundation\JsonResponse;
37
use Symfony\Component\HttpFoundation\RedirectResponse;
38
use Symfony\Component\HttpFoundation\Request;
39
use Symfony\Component\Routing\Annotation\Route;
40
use Symfony\Component\Routing\Exception\RouteNotFoundException;
41
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
42
43
class PluginController extends AbstractController
44
{
45
    /**
46
     * @var PluginService
47
     */
48
    protected $pluginService;
49
50
    /**
51
     * @var BaseInfo
52
     */
53
    protected $BaseInfo;
54
55
    /**
56
     * @var PluginRepository
57
     */
58
    protected $pluginRepository;
59
60
    /**
61
     * @var PluginApiService
62
     */
63
    protected $pluginApiService;
64
65
    /**
66
     * PluginController constructor.
67
     *
68
     * @param PluginRepository $pluginRepository
69
     * @param PluginService $pluginService
70
     * @param BaseInfoRepository $baseInfoRepository
71
     * @param PluginApiService $pluginApiService
72
     *
73
     * @throws \Doctrine\ORM\NoResultException
74
     * @throws \Doctrine\ORM\NonUniqueResultException
75
     */
76 View Code Duplication
    public function __construct(PluginRepository $pluginRepository, PluginService $pluginService, BaseInfoRepository $baseInfoRepository, PluginApiService $pluginApiService)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
77
    {
78
        $this->pluginRepository = $pluginRepository;
79
        $this->pluginService = $pluginService;
80
        $this->BaseInfo = $baseInfoRepository->get();
81
        $this->pluginApiService = $pluginApiService;
82
    }
83
84
    /**
85
     * インストール済プラグイン画面
86
     *
87
     * @Route("/%eccube_admin_route%/store/plugin", name="admin_store_plugin")
88
     * @Template("@admin/Store/plugin.twig")
89
     *
90
     * @return array
91
     * @throws PluginException
92
     */
93
    public function index()
94
    {
95
        $pluginForms = [];
96
        $configPages = [];
97
        $Plugins = $this->pluginRepository->findBy([], ['code' => 'ASC']);
98
99
        // ファイル設置プラグインの取得.
100
        $unregisteredPlugins = $this->getUnregisteredPlugins($Plugins);
101
        $unregisteredPluginsConfigPages = [];
102
        foreach ($unregisteredPlugins as $unregisteredPlugin) {
103
            try {
104
                $code = $unregisteredPlugin['code'];
105
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
106
                $unregisteredPluginsConfigPages[$code] = $this->generateUrl('plugin_'.$code.'_config');
107
            } catch (RouteNotFoundException $e) {
108
                // プラグインで設定画面のルートが定義されていない場合は無視
109
            }
110
        }
111
112
        $officialPlugins = [];
113
        $unofficialPlugins = [];
114
115
        foreach ($Plugins as $Plugin) {
116
            $form = $this->formFactory
117
                ->createNamedBuilder(
118
                    'form'.$Plugin->getId(),
119
                    PluginManagementType::class,
120
                    null,
121
                    [
122
                        'plugin_id' => $Plugin->getId(),
123
                    ]
124
                )
125
                ->getForm();
126
            $pluginForms[$Plugin->getId()] = $form->createView();
127
128
            try {
129
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
130
                $configPages[$Plugin->getCode()] = $this->generateUrl(Container::underscore($Plugin->getCode()).'_admin_config');
131
            } catch (\Exception $e) {
132
                // プラグインで設定画面のルートが定義されていない場合は無視
133
            }
134
            if ($Plugin->getSource() == 0) {
135
                // 商品IDが設定されていない場合、非公式プラグイン
136
                $unofficialPlugins[] = $Plugin;
137
            } else {
138
                $officialPlugins[$Plugin->getSource()] = $Plugin;
139
            }
140
        }
141
142
        // オーナーズストア通信
143
        $officialPluginsDetail = [];
144
        try {
145
            $data = $this->pluginApiService->getPurchased();
146
            foreach ($data as $item) {
147
                if (isset($officialPlugins[$item['id']])) {
148
                    $Plugin = $officialPlugins[$item['id']];
149
                    $officialPluginsDetail[$item['id']] = $item;
150
                    $officialPluginsDetail[$item['id']]['update_status'] = 0;
151 View Code Duplication
                    if ($this->pluginService->isUpdate($Plugin->getVersion(), $item['version'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
152
                        $officialPluginsDetail[$item['id']]['update_status'] = 1;
153
                    }
154
                } else {
155
                    $Plugin = new Plugin();
156
                    $Plugin->setName($item['name']);
157
                    $Plugin->setCode($item['code']);
158
                    $Plugin->setVersion($item['version']);
159
                    $Plugin->setSource($item['id']);
160
                    $Plugin->setEnabled(false);
161
                    $officialPlugins[$item['id']] = $Plugin;
162
                    $officialPluginsDetail[$item['id']] = $item;
163
                    $officialPluginsDetail[$item['id']]['update_status'] = 0;
164 View Code Duplication
                    if ($this->pluginService->isUpdate($Plugin->getVersion(), $item['version'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
165
                        $officialPluginsDetail[$item['id']]['update_status'] = 1;
166
                    }
167
                }
168
            }
169
        } catch (PluginApiException $e) {
170
            $this->addWarning($e->getMessage(), 'admin');
171
        }
172
173
        return [
174
            'plugin_forms' => $pluginForms,
175
            'officialPlugins' => $officialPlugins,
176
            'unofficialPlugins' => $unofficialPlugins,
177
            'configPages' => $configPages,
178
            'unregisteredPlugins' => $unregisteredPlugins,
179
            'unregisteredPluginsConfigPages' => $unregisteredPluginsConfigPages,
180
            'officialPluginsDetail' => $officialPluginsDetail,
181
        ];
182
    }
183
184
    /**
185
     * インストール済プラグインからのアップデート
186
     *
187
     * @Route("/%eccube_admin_route%/store/plugin/{id}/update", requirements={"id" = "\d+"}, name="admin_store_plugin_update", methods={"POST"})
188
     *
189
     * @param Request $request
190
     * @param Plugin $Plugin
191
     *
192
     * @return RedirectResponse
193
     */
194
    public function update(Request $request, Plugin $Plugin)
195
    {
196
        $form = $this->formFactory
197
            ->createNamedBuilder(
198
                'form'.$Plugin->getId(),
199
                PluginManagementType::class,
200
                null,
201
                [
202
                    'plugin_id' => null, // placeHolder
203
                ]
204
            )
205
            ->getForm();
206
207
        $message = '';
208
        $form->handleRequest($request);
209
        if ($form->isSubmitted() && $form->isValid()) {
210
            $tmpDir = null;
211
            try {
212
                $formFile = $form['plugin_archive']->getData();
213
                $tmpDir = $this->pluginService->createTempDir();
214
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
215
                $formFile->move($tmpDir, $tmpFile);
216
                $this->pluginService->update($Plugin, $tmpDir.'/'.$tmpFile);
217
                $fs = new Filesystem();
218
                $fs->remove($tmpDir);
219
                $this->addSuccess('admin.plugin.update.complete', 'admin');
220
221
                return $this->redirectToRoute('admin_store_plugin');
222
            } catch (PluginException $e) {
223
                if (!empty($tmpDir) && file_exists($tmpDir)) {
224
                    $fs = new Filesystem();
225
                    $fs->remove($tmpDir);
226
                }
227
                $message = $e->getMessage();
228
            } catch (\Exception $er) {
229
                // Catch composer install error | Other error
230
                if (!empty($tmpDir) && file_exists($tmpDir)) {
231
                    $fs = new Filesystem();
232
                    $fs->remove($tmpDir);
233
                }
234
                log_error('plugin install failed.', ['original-message' => $er->getMessage()]);
235
                $message = 'admin.plugin.install.fail';
236
            }
237
        } else {
238
            $errors = $form->getErrors(true);
239
            foreach ($errors as $error) {
240
                $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...
241
            }
242
        }
243
244
        $this->addError($message, 'admin');
245
246
        return $this->redirectToRoute('admin_store_plugin');
247
    }
248
249
    /**
250
     * 対象のプラグインを有効にします。
251
     *
252
     * @Route("/%eccube_admin_route%/store/plugin/{id}/enable", requirements={"id" = "\d+"}, name="admin_store_plugin_enable", methods={"POST"})
253
     *
254
     * @param Plugin $Plugin
255
     *
256
     * @return RedirectResponse|JsonResponse
257
     *
258
     * @throws PluginException
259
     */
260
    public function enable(Plugin $Plugin, CacheUtil $cacheUtil, Request $request)
261
    {
262
        $this->isTokenValid();
263
264
        $log = null;
265
266
        if ($Plugin->isEnabled()) {
267
            if ($request->isXmlHttpRequest()) {
268
                return $this->json(['success' => true]);
269
            } else {
270
                $this->addError('admin.plugin.already.enable', 'admin');
271
            }
272
        } else {
273
            // ストアからインストールしたプラグインは依存プラグインが有効化されているかを確認
274
            if ($Plugin->getSource()) {
275
                $requires = $this->pluginService->getPluginRequired($Plugin);
276 View Code Duplication
                $requires = array_filter($requires, function ($req) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
277
                    $code = preg_replace('/^ec-cube\//', '', $req['name']);
278
                    /** @var Plugin $DependPlugin */
279
                    $DependPlugin = $this->pluginRepository->findOneBy(['code' => $code]);
280
281
                    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...
282
                });
283
                if (!empty($requires)) {
284
                    $names = array_map(function ($req) {
285
                        return "「${req['description']}」";
286
                    }, $requires);
287
                    $message = trans('%depend_name%を先に有効化してください。', ['%name%' => $Plugin->getName(), '%depend_name%' => implode(', ', $names)]);
288
289
                    if ($request->isXmlHttpRequest()) {
290
                        return $this->json(['success' => false, 'message' => $message], 400);
291
                    } else {
292
                        $this->addError($message, 'admin');
293
294
                        return $this->redirectToRoute('admin_store_plugin');
295
                    }
296
                }
297
            }
298
299
300
            ob_start();
301
302
            if (!$Plugin->isInitialized()) {
303
                $this->pluginService->installWithCode($Plugin->getCode());
304
            }
305
306
            $this->pluginService->enable($Plugin);
307
            $log = ob_get_clean();
308
            ob_end_flush();
309
        }
310
311
        $cacheUtil->clearCache();
312
313 View Code Duplication
        if ($request->isXmlHttpRequest()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
314
            return $this->json(['success' => true, 'log' => $log]);
315
        } else {
316
            $this->addSuccess(trans('「%plugin_name%」を有効にしました。', ['%plugin_name%' => $Plugin->getName()]), 'admin');
317
318
            return $this->redirectToRoute('admin_store_plugin');
319
        }
320
    }
321
322
    /**
323
     * 対象のプラグインを無効にします。
324
     *
325
     * @Route("/%eccube_admin_route%/store/plugin/{id}/disable", requirements={"id" = "\d+"}, name="admin_store_plugin_disable", methods={"POST"})
326
     *
327
     * @param Request $request
328
     * @param Plugin $Plugin
329
     * @param CacheUtil $cacheUtil
330
     *
331
     * @return \Symfony\Component\HttpFoundation\JsonResponse|RedirectResponse
332
     */
333
    public function disable(Request $request, Plugin $Plugin, CacheUtil $cacheUtil)
334
    {
335
        $this->isTokenValid();
336
337
        $log = null;
338
        if ($Plugin->isEnabled()) {
339
            $dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode());
340
            if (!empty($dependents)) {
341
                $dependName = $dependents[0];
342
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]);
343
                if ($DependPlugin) {
344
                    $dependName = $DependPlugin->getName();
345
                }
346
                $message = trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
347
348
                if ($request->isXmlHttpRequest()) {
349
                    return $this->json(['message' => $message], 400);
350
                } else {
351
                    $this->addError($message, 'admin');
352
353
                    return $this->redirectToRoute('admin_store_plugin');
354
                }
355
            }
356
357
            ob_start();
358
            $this->pluginService->disable($Plugin);
359
            $log = ob_get_clean();
360
            ob_end_flush();
361 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
362
            if ($request->isXmlHttpRequest()) {
363
                return $this->json(['success' => true, 'log' => $log]);
364
            } else {
365
                $this->addError('admin.plugin.already.disable', 'admin');
366
367
                return $this->redirectToRoute('admin_store_plugin');
368
            }
369
        }
370
371
        $cacheUtil->clearCache();
372
373 View Code Duplication
        if ($request->isXmlHttpRequest()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
374
            return $this->json(['success' => true, 'log' => $log]);
375
        } else {
376
            $this->addSuccess('admin.plugin.disable.complete', 'admin');
377
378
            return $this->redirectToRoute('admin_store_plugin');
379
        }
380
    }
381
382
    /**
383
     * 対象のプラグインを削除します。
384
     *
385
     * @Route("/%eccube_admin_route%/store/plugin/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_uninstall", methods={"DELETE"})
386
     *
387
     * @param Plugin $Plugin
388
     *
389
     * @return RedirectResponse
390
     *
391
     * @throws \Exception
392
     */
393
    public function uninstall(Plugin $Plugin)
394
    {
395
        $this->isTokenValid();
396
397
        if ($Plugin->isEnabled()) {
398
            $this->addError('admin.plugin.uninstall.error.not_disable', 'admin');
399
400
            return $this->redirectToRoute('admin_store_plugin');
401
        }
402
403
        // Check other plugin depend on it
404
        $pluginCode = $Plugin->getCode();
405
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
406
        if (!empty($otherDepend)) {
407
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
408
            $dependName = $otherDepend[0];
409
            if ($DependPlugin) {
410
                $dependName = $DependPlugin->getName();
411
            }
412
            $message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
413
            $this->addError($message, 'admin');
414
415
            return $this->redirectToRoute('admin_store_plugin');
416
        }
417
418
        $this->pluginService->uninstall($Plugin);
419
        $this->addSuccess('admin.plugin.uninstall.complete', 'admin');
420
421
        return $this->redirectToRoute('admin_store_plugin');
422
    }
423
424
    /**
425
     * プラグインファイルアップロード画面
426
     *
427
     * @Route("/%eccube_admin_route%/store/plugin/install", name="admin_store_plugin_install")
428
     * @Template("@admin/Store/plugin_install.twig")
429
     *
430
     * @param Request $request
431
     *
432
     * @return array|RedirectResponse
433
     */
434
    public function install(Request $request)
435
    {
436
        $form = $this->formFactory
437
            ->createBuilder(PluginLocalInstallType::class)
438
            ->getForm();
439
        $errors = [];
440
        $form->handleRequest($request);
441
        if ($form->isSubmitted() && $form->isValid()) {
442
            $tmpDir = null;
443
            try {
444
                $service = $this->pluginService;
445
                /** @var UploadedFile $formFile */
446
                $formFile = $form['plugin_archive']->getData();
447
                $tmpDir = $service->createTempDir();
448
                // 拡張子を付けないとpharが動かないので付ける
449
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
450
                $formFile->move($tmpDir, $tmpFile);
451
                $tmpPath = $tmpDir.'/'.$tmpFile;
452
                $service->install($tmpPath);
453
                // Remove tmp file
454
                $fs = new Filesystem();
455
                $fs->remove($tmpDir);
456
                $this->addSuccess('admin.plugin.install.complete', 'admin');
457
458
                return $this->redirectToRoute('admin_store_plugin');
459
            } catch (PluginException $e) {
460
                if (!empty($tmpDir) && file_exists($tmpDir)) {
461
                    $fs = new Filesystem();
462
                    $fs->remove($tmpDir);
463
                }
464
                log_error('plugin install failed.', ['original-message' => $e->getMessage()]);
465
                $errors[] = $e;
466
            } catch (\Exception $er) {
467
                // Catch composer install error | Other error
468
                if (!empty($tmpDir) && file_exists($tmpDir)) {
469
                    $fs = new Filesystem();
470
                    $fs->remove($tmpDir);
471
                }
472
                log_error('plugin install failed.', ['original-message' => $er->getMessage()]);
473
                $this->addError('admin.plugin.install.fail', 'admin');
474
            }
475
        } else {
476
            foreach ($form->getErrors(true) as $error) {
477
                $errors[] = $error;
478
            }
479
        }
480
481
        return [
482
            'form' => $form->createView(),
483
            'errors' => $errors,
484
        ];
485
    }
486
487
    /**
488
     * 認証キー設定画面
489
     *
490
     * @Route("/%eccube_admin_route%/store/plugin/authentication_setting", name="admin_store_authentication_setting")
491
     * @Template("@admin/Store/authentication_setting.twig")
492
     */
493
    public function authenticationSetting(Request $request)
494
    {
495
        $builder = $this->formFactory
496
            ->createBuilder(AuthenticationType::class, $this->BaseInfo);
497
498
        $form = $builder->getForm();
499
        $form->handleRequest($request);
500
501
        if ($form->isSubmitted() && $form->isValid()) {
502
            // 認証キーの登録 and PHP path
503
            $this->BaseInfo = $form->getData();
504
            $this->entityManager->persist($this->BaseInfo);
505
            $this->entityManager->flush();
506
507
            $this->addSuccess('admin.common.save_complete', 'admin');
508
        }
509
510
        return [
511
            'form' => $form->createView(),
512
            'eccubeUrl' => $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL),
513
            'eccubeShopName' => $this->BaseInfo->getShopName()
514
        ];
515
    }
516
517
    /**
518
     * フォルダ設置のみのプラグインを取得する.
519
     *
520
     * @param array $plugins
521
     *
522
     * @return array
523
     * @throws PluginException
524
     */
525
    protected function getUnregisteredPlugins(array $plugins)
526
    {
527
        $finder = new Finder();
528
        $pluginCodes = [];
529
530
        // DB登録済みプラグインコードのみ取得
531
        foreach ($plugins as $key => $plugin) {
532
            $pluginCodes[] = $plugin->getCode();
533
        }
534
        // DB登録済みプラグインコードPluginディレクトリから排他
535
        $dirs = $finder->in($this->eccubeConfig['plugin_realdir'])->depth(0)->directories();
536
537
        // プラグイン基本チェック
538
        $unregisteredPlugins = [];
539
        foreach ($dirs as $dir) {
540
            $pluginCode = $dir->getBasename();
541
            if (in_array($pluginCode, $pluginCodes, true)) {
542
                continue;
543
            }
544
            try {
545
                $this->pluginService->checkPluginArchiveContent($dir->getRealPath());
546
            } catch (PluginException $e) {
547
                //config.yamlに不備があった際は全てスキップ
548
                log_warning($e->getMessage());
549
                continue;
550
            }
551
            $config = $this->pluginService->readConfig($dir->getRealPath());
552
            $unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null;
553
            $unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null;
554
            $unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null;
555
            $unregisteredPlugins[$pluginCode]['enabled'] = Constant::DISABLED;
556
            $unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null;
557
        }
558
559
        return $unregisteredPlugins;
560
    }
561
}
562