Completed
Push — 4.0 ( 16398e...769a6f )
by chihiro
25s queued 10s
created

PluginController::enable()   C

Complexity

Conditions 10
Paths 88

Size

Total Lines 84

Duplication

Lines 14
Ratio 16.67 %

Code Coverage

Tests 0
CRAP Score 110

Importance

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