Failed Conditions
Push — sf/package-api ( 831849 )
by Kiyotaka
05:53
created

PluginController   D

Complexity

Total Complexity 59

Size/Duplication

Total Lines 542
Duplicated Lines 15.13 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 0
Metric Value
dl 82
loc 542
rs 4.08
c 0
b 0
f 0
wmc 59
lcom 1
cbo 19

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
C index() 6 95 11
B update() 0 54 10
A enable() 0 36 4
A disable() 33 33 4
A uninstall() 30 30 4
B install() 0 52 10
A authenticationSetting() 0 22 3
A getRequestApi() 0 30 1
A getResponseErrorMessage() 13 13 2
B getUnregisteredPlugins() 0 36 9

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like PluginController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use PluginController, and based on these observations, apply Extract Interface, too.

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\PluginException;
21
use Eccube\Form\Type\Admin\AuthenticationType;
22
use Eccube\Form\Type\Admin\CaptchaType;
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\RedirectResponse;
37
use Symfony\Component\HttpFoundation\Request;
38
use Symfony\Component\Routing\Annotation\Route;
39
use Symfony\Component\Routing\Exception\RouteNotFoundException;
40
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
41
42
class PluginController extends AbstractController
43
{
44
    /**
45
     * @var PluginService
46
     */
47
    protected $pluginService;
48
49
    /**
50
     * @var BaseInfo
51
     */
52
    protected $BaseInfo;
53
54
    /**
55
     * @var PluginRepository
56
     */
57
    protected $pluginRepository;
58
59
    /**
60
     * @var PluginApiService
61
     */
62
    protected $pluginApiService;
63
64
    /**
65
     * PluginController constructor.
66
     *
67
     * @param PluginRepository $pluginRepository
68
     * @param PluginService $pluginService
69
     * @param BaseInfoRepository $baseInfoRepository
70
     * @param PluginApiService $pluginApiService
71
     *
72
     * @throws \Doctrine\ORM\NoResultException
73
     * @throws \Doctrine\ORM\NonUniqueResultException
74
     */
75
    public function __construct(PluginRepository $pluginRepository, PluginService $pluginService, BaseInfoRepository $baseInfoRepository, PluginApiService $pluginApiService)
76
    {
77
        $this->pluginRepository = $pluginRepository;
78
        $this->pluginService = $pluginService;
79
        $this->BaseInfo = $baseInfoRepository->get();
80
        $this->pluginApiService = $pluginApiService;
81
    }
82
83
    /**
84
     * インストール済プラグイン画面
85
     *
86
     * @Route("/%eccube_admin_route%/store/plugin", name="admin_store_plugin")
87
     * @Template("@admin/Store/plugin.twig")
88
     * @param Request $request
89
     * @return array
90
     */
91
    public function index(Request $request)
92
    {
93
        $pluginForms = [];
94
        $configPages = [];
95
        $Plugins = $this->pluginRepository->findBy([], ['code' => 'ASC']);
96
97
        // ファイル設置プラグインの取得.
98
        $unregisteredPlugins = $this->getUnregisteredPlugins($Plugins);
99
        $unregisteredPluginsConfigPages = [];
100
        foreach ($unregisteredPlugins as $unregisteredPlugin) {
101
            try {
102
                $code = $unregisteredPlugin['code'];
103
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
104
                $unregisteredPluginsConfigPages[$code] = $this->generateUrl('plugin_'.$code.'_config');
105
            } catch (RouteNotFoundException $e) {
106
                // プラグインで設定画面のルートが定義されていない場合は無視
107
            }
108
        }
109
110
        $officialPlugins = [];
111
        $unofficialPlugins = [];
112
113
        foreach ($Plugins as $Plugin) {
114
            $form = $this->formFactory
115
                ->createNamedBuilder(
116
                    'form'.$Plugin->getId(),
117
                    PluginManagementType::class,
118
                    null,
119
                    [
120
                        'plugin_id' => $Plugin->getId(),
121
                    ]
122
                )
123
                ->getForm();
124
            $pluginForms[$Plugin->getId()] = $form->createView();
125
126
            try {
127
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
128
                $configPages[$Plugin->getCode()] = $this->generateUrl(Container::underscore($Plugin->getCode()).'_admin_config');
129
            } catch (\Exception $e) {
130
                // プラグインで設定画面のルートが定義されていない場合は無視
131
            }
132
            if ($Plugin->getSource() == 0) {
133
                // 商品IDが設定されていない場合、非公式プラグイン
134
                $unofficialPlugins[] = $Plugin;
135
            } else {
136
                $officialPlugins[$Plugin->getSource()] = $Plugin;
137
            }
138
        }
139
140
        // Todo: Need new authentication mechanism
141
        // オーナーズストアからダウンロード可能プラグイン情報を取得
142
        $authKey = $this->BaseInfo->getAuthenticationKey();
143
        // オーナーズストア通信
144
        // TODO: get url from api service instead of direct from controller
145
        $url = $this->eccubeConfig['eccube_package_repo_url'].'/plugins/purchased';
146
        list($json, $info) = $this->getRequestApi($request, $authKey, $url);
0 ignored issues
show
Unused Code introduced by
The assignment to $info is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Deprecated Code introduced by
The method Eccube\Controller\Admin\...roller::getRequestApi() has been deprecated with message: since release, please refer PluginApiService

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
147
        $officialPluginsDetail = [];
148
        if ($json) {
149
            // 接続成功時
150
            $data = json_decode($json, true);
151
            foreach ($data as $item) {
152
                if (isset($officialPlugins[$item['id']])) {
153
                    $Plugin = $officialPlugins[$item['id']];
154
                    $officialPluginsDetail[$item['id']] = $item;
155
                    $officialPluginsDetail[$item['id']]['update_status'] = 0;
156 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...
157
                        $officialPluginsDetail[$item['id']]['update_status'] = 1;
158
                    }
159
                } else {
160
                    $Plugin = new Plugin();
161
                    $Plugin->setName($item['name']);
162
                    $Plugin->setCode($item['code']);
163
                    $Plugin->setVersion($item['version']);
164
                    $Plugin->setSource($item['id']);
165
                    $Plugin->setEnabled(false);
166
                    $officialPlugins[$item['id']] = $Plugin;
167
                    $officialPluginsDetail[$item['id']] = $item;
168
                    $officialPluginsDetail[$item['id']]['update_status'] = 0;
169 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...
170
                        $officialPluginsDetail[$item['id']]['update_status'] = 1;
171
                    }
172
                }
173
            }
174
        }
175
176
        return [
177
            'plugin_forms' => $pluginForms,
178
            'officialPlugins' => $officialPlugins,
179
            'unofficialPlugins' => $unofficialPlugins,
180
            'configPages' => $configPages,
181
            'unregisteredPlugins' => $unregisteredPlugins,
182
            'unregisteredPluginsConfigPages' => $unregisteredPluginsConfigPages,
183
            'officialPluginsDetail' => $officialPluginsDetail,
184
        ];
185
    }
186
187
    /**
188
     * インストール済プラグインからのアップデート
189
     *
190
     * @Route("/%eccube_admin_route%/store/plugin/{id}/update", requirements={"id" = "\d+"}, name="admin_store_plugin_update", methods={"POST"})
191
     *
192
     * @param Request $request
193
     * @param Plugin $Plugin
194
     *
195
     * @return RedirectResponse
196
     */
197
    public function update(Request $request, Plugin $Plugin)
198
    {
199
        $form = $this->formFactory
200
            ->createNamedBuilder(
201
                'form'.$Plugin->getId(),
202
                PluginManagementType::class,
203
                null,
204
                [
205
                    'plugin_id' => null, // placeHolder
206
                ]
207
            )
208
            ->getForm();
209
210
        $message = '';
211
        $form->handleRequest($request);
212
        if ($form->isSubmitted() && $form->isValid()) {
213
            $tmpDir = null;
214
            try {
215
                $formFile = $form['plugin_archive']->getData();
216
                $tmpDir = $this->pluginService->createTempDir();
217
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
218
                $formFile->move($tmpDir, $tmpFile);
219
                $this->pluginService->update($Plugin, $tmpDir.'/'.$tmpFile);
220
                $fs = new Filesystem();
221
                $fs->remove($tmpDir);
222
                $this->addSuccess('admin.plugin.update.complete', 'admin');
223
224
                return $this->redirectToRoute('admin_store_plugin');
225
            } catch (PluginException $e) {
226
                if (!empty($tmpDir) && file_exists($tmpDir)) {
227
                    $fs = new Filesystem();
228
                    $fs->remove($tmpDir);
229
                }
230
                $message = $e->getMessage();
231
            } catch (\Exception $er) {
232
                // Catch composer install error | Other error
233
                if (!empty($tmpDir) && file_exists($tmpDir)) {
234
                    $fs = new Filesystem();
235
                    $fs->remove($tmpDir);
236
                }
237
                log_error('plugin install failed.', ['original-message' => $er->getMessage()]);
238
                $message = 'admin.plugin.install.fail';
239
            }
240
        } else {
241
            $errors = $form->getErrors(true);
242
            foreach ($errors as $error) {
243
                $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...
244
            }
245
        }
246
247
        $this->addError($message, 'admin');
248
249
        return $this->redirectToRoute('admin_store_plugin');
250
    }
251
252
    /**
253
     * 対象のプラグインを有効にします。
254
     *
255
     * @Route("/%eccube_admin_route%/store/plugin/{id}/enable", requirements={"id" = "\d+"}, name="admin_store_plugin_enable", methods={"PUT"})
256
     *
257
     * @param Plugin $Plugin
258
     *
259
     * @return RedirectResponse
260
     * @throws PluginException
261
     */
262
    public function enable(Plugin $Plugin, CacheUtil $cacheUtil)
263
    {
264
        $this->isTokenValid();
265
266
        if ($Plugin->isEnabled()) {
267
            $this->addError('admin.plugin.already.enable', 'admin');
268
        } else {
269
270
            // ストアからインストールしたプラグインは依存プラグインが有効化されているかを確認
271
            if ($Plugin->getSource()) {
272
                $requires = $this->pluginService->getPluginRequired($Plugin);
273
                $requires = array_filter($requires, function($req) {
274
                    $code = preg_replace('/^ec-cube\//', '', $req['name']);
275
                    /** @var Plugin $DependPlugin */
276
                    $DependPlugin = $this->pluginRepository->findOneBy(['code' => $code]);
277
                    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...
278
                });
279
                if (!empty($requires)) {
280
                    $names = array_map(function($req) {
281
                        return "「${req['description']}」";
282
                    }, $requires);
283
                    $message = trans('%depend_name%を先に有効化してください。', ['%name%' => $Plugin->getName(), '%depend_name%' => implode(', ', $names)]);
284
                    $this->addError($message, 'admin');
285
286
                    return $this->redirectToRoute('admin_store_plugin');
287
                }
288
            }
289
290
            $this->pluginService->enable($Plugin);
291
            $this->addSuccess(trans('「%plugin_name%」を有効にしました。', ['%plugin_name%' => $Plugin->getName()]), 'admin');
292
        }
293
294
        $cacheUtil->clearCache();
295
296
        return $this->redirectToRoute('admin_store_plugin');
297
    }
298
299
    /**
300
     * 対象のプラグインを無効にします。
301
     *
302
     * @Route("/%eccube_admin_route%/store/plugin/{id}/disable", requirements={"id" = "\d+"}, name="admin_store_plugin_disable", methods={"PUT"})
303
     *
304
     * @param Plugin $Plugin
305
     *
306
     * @return RedirectResponse
307
     */
308 View Code Duplication
    public function disable(Plugin $Plugin, CacheUtil $cacheUtil)
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...
309
    {
310
        $this->isTokenValid();
311
312
        if ($Plugin->isEnabled()) {
313
            $dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode());
314
            if (!empty($dependents)) {
315
                $dependName = $dependents[0];
316
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]);
317
                if ($DependPlugin) {
318
                    $dependName = $DependPlugin->getName();
319
                }
320
                $message = trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
321
                $this->addError($message, 'admin');
322
323
                return $this->redirectToRoute('admin_store_plugin');
324
            }
325
326
            $this->pluginService->disable($Plugin);
327
            $this->addSuccess('admin.plugin.disable.complete', 'admin');
328
        } else {
329
            $this->addError('admin.plugin.already.disable', 'admin');
330
331
            return $this->redirectToRoute('admin_store_plugin');
332
        }
333
334
        // キャッシュを削除してリダイレクト
335
        // リダイレクトにredirectToRoute関数を使用していないのは、削除したキャッシュが再生成されてしまうため。
336
        $url = $this->generateUrl('admin_store_plugin');
337
        $cacheUtil->clearCache();
338
339
        return $this->redirect($url);
340
    }
341
342
    /**
343
     * 対象のプラグインを削除します。
344
     *
345
     * @Route("/%eccube_admin_route%/store/plugin/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_uninstall", methods={"DELETE"})
346
     *
347
     * @param Plugin $Plugin
348
     *
349
     * @return RedirectResponse
350
     * @throws \Exception
351
     */
352 View Code Duplication
    public function uninstall(Plugin $Plugin)
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...
353
    {
354
        $this->isTokenValid();
355
356
        if ($Plugin->isEnabled()) {
357
            $this->addError('admin.plugin.uninstall.error.not_disable', 'admin');
358
359
            return $this->redirectToRoute('admin_store_plugin');
360
        }
361
362
        // Check other plugin depend on it
363
        $pluginCode = $Plugin->getCode();
364
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
365
        if (!empty($otherDepend)) {
366
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
367
            $dependName = $otherDepend[0];
368
            if ($DependPlugin) {
369
                $dependName = $DependPlugin->getName();
370
            }
371
            $message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
372
            $this->addError($message, 'admin');
373
374
            return $this->redirectToRoute('admin_store_plugin');
375
        }
376
377
        $this->pluginService->uninstall($Plugin);
378
        $this->addSuccess('admin.plugin.uninstall.complete', 'admin');
379
380
        return $this->redirectToRoute('admin_store_plugin');
381
    }
382
383
    /**
384
     * プラグインファイルアップロード画面
385
     *
386
     * @Route("/%eccube_admin_route%/store/plugin/install", name="admin_store_plugin_install")
387
     * @Template("@admin/Store/plugin_install.twig")
388
     *
389
     * @param Request $request
390
     *
391
     * @return array|RedirectResponse
392
     */
393
    public function install(Request $request)
394
    {
395
        $form = $this->formFactory
396
            ->createBuilder(PluginLocalInstallType::class)
397
            ->getForm();
398
        $errors = [];
399
        $form->handleRequest($request);
400
        if ($form->isSubmitted() && $form->isValid()) {
401
            $tmpDir = null;
402
            try {
403
                $service = $this->pluginService;
404
                /** @var UploadedFile $formFile */
405
                $formFile = $form['plugin_archive']->getData();
406
                $tmpDir = $service->createTempDir();
407
                // 拡張子を付けないとpharが動かないので付ける
408
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
409
                $formFile->move($tmpDir, $tmpFile);
410
                $tmpPath = $tmpDir.'/'.$tmpFile;
411
                $service->install($tmpPath);
412
                // Remove tmp file
413
                $fs = new Filesystem();
414
                $fs->remove($tmpDir);
415
                $this->addSuccess('admin.plugin.install.complete', 'admin');
416
417
                return $this->redirectToRoute('admin_store_plugin');
418
            } catch (PluginException $e) {
419
                if (!empty($tmpDir) && file_exists($tmpDir)) {
420
                    $fs = new Filesystem();
421
                    $fs->remove($tmpDir);
422
                }
423
                log_error('plugin install failed.', ['original-message' => $e->getMessage()]);
424
                $errors[] = $e;
425
            } catch (\Exception $er) {
426
                // Catch composer install error | Other error
427
                if (!empty($tmpDir) && file_exists($tmpDir)) {
428
                    $fs = new Filesystem();
429
                    $fs->remove($tmpDir);
430
                }
431
                log_error('plugin install failed.', ['original-message' => $er->getMessage()]);
432
                $this->addError('admin.plugin.install.fail', 'admin');
433
            }
434
        } else {
435
            foreach ($form->getErrors(true) as $error) {
436
                $errors[] = $error;
437
            }
438
        }
439
440
        return [
441
            'form' => $form->createView(),
442
            'errors' => $errors,
443
        ];
444
    }
445
446
    /**
447
     * 認証キー設定画面
448
     *
449
     * @Route("/%eccube_admin_route%/store/plugin/authentication_setting", name="admin_store_authentication_setting")
450
     * @Template("@admin/Store/authentication_setting.twig")
451
     */
452
    public function authenticationSetting(Request $request)
453
    {
454
        $builder = $this->formFactory
455
            ->createBuilder(AuthenticationType::class, $this->BaseInfo);
456
457
        $form = $builder->getForm();
458
        $form->handleRequest($request);
459
460
        if ($form->isSubmitted() && $form->isValid()) {
461
            // 認証キーの登録 and PHP path
462
            $this->BaseInfo = $form->getData();
463
            $this->entityManager->persist($this->BaseInfo);
464
            $this->entityManager->flush();
465
466
            $this->addSuccess('admin.common.save_complete', 'admin');
467
        }
468
469
        return [
470
            'form' => $form->createView(),
471
            'eccubeUrl' => $this->generateUrl('homepage', [], UrlGeneratorInterface::ABSOLUTE_URL)
472
        ];
473
    }
474
475
    /**
476
     * APIリクエスト処理
477
     *
478
     * @param Request $request
479
     * @param string|null $authKey
480
     * @param string $url
481
     *
482
     * @deprecated since release, please refer PluginApiService
483
     *
484
     * @return array
485
     */
486
    private function getRequestApi(Request $request, $authKey, $url)
487
    {
488
        $curl = curl_init($url);
489
490
        $options = [// オプション配列
491
            //HEADER
492
            CURLOPT_HTTPHEADER => [
493
                'Authorization: '.base64_encode($authKey),
494
                'x-eccube-store-url: '.base64_encode($request->getSchemeAndHttpHost().$request->getBasePath()),
495
                'x-eccube-store-version: '.base64_encode(Constant::VERSION),
496
            ],
497
            CURLOPT_HTTPGET => true,
498
            CURLOPT_SSL_VERIFYPEER => true,
499
            CURLOPT_RETURNTRANSFER => true,
500
            CURLOPT_FAILONERROR => true,
501
            CURLOPT_CAINFO => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(),
502
        ];
503
504
        curl_setopt_array($curl, $options); /// オプション値を設定
505
        $result = curl_exec($curl);
506
        $info = curl_getinfo($curl);
507
508
        $message = curl_error($curl);
509
        $info['message'] = $message;
510
        curl_close($curl);
511
512
        log_info('http get_info', $info);
513
514
        return [$result, $info];
515
    }
516
517
    /**
518
     * レスポンスのチェック
519
     *
520
     * @param $info
521
     *
522
     * @return string
523
     *
524
     * @deprecated since release, please refer PluginApiService
525
     */
526 View Code Duplication
    private function getResponseErrorMessage($info)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
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...
527
    {
528
        if (!empty($info)) {
529
            $statusCode = $info['http_code'];
530
            $message = $info['message'];
531
532
            $message = $statusCode.' : '.$message;
533
        } else {
534
            $message = trans('plugin.text.error.timeout_or_invalid_url');
535
        }
536
537
        return $message;
538
    }
539
540
    /**
541
     * フォルダ設置のみのプラグインを取得する.
542
     *
543
     * @param array $plugins
544
     *
545
     * @return array
546
     */
547
    protected function getUnregisteredPlugins(array $plugins)
548
    {
549
        $finder = new Finder();
550
        $pluginCodes = [];
551
552
        // DB登録済みプラグインコードのみ取得
553
        foreach ($plugins as $key => $plugin) {
554
            $pluginCodes[] = $plugin->getCode();
555
        }
556
        // DB登録済みプラグインコードPluginディレクトリから排他
557
        $dirs = $finder->in($this->eccubeConfig['plugin_realdir'])->depth(0)->directories();
558
559
        // プラグイン基本チェック
560
        $unregisteredPlugins = [];
561
        foreach ($dirs as $dir) {
562
            $pluginCode = $dir->getBasename();
563
            if (in_array($pluginCode, $pluginCodes, true)) {
564
                continue;
565
            }
566
            try {
567
                $this->pluginService->checkPluginArchiveContent($dir->getRealPath());
568
            } catch (\Eccube\Exception\PluginException $e) {
569
                //config.yamlに不備があった際は全てスキップ
570
                log_warning($e->getMessage());
571
                continue;
572
            }
573
            $config = $this->pluginService->readConfig($dir->getRealPath());
574
            $unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null;
575
            $unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null;
576
            $unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null;
577
            $unregisteredPlugins[$pluginCode]['enabled'] = Constant::DISABLED;
578
            $unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null;
579
        }
580
581
        return $unregisteredPlugins;
582
    }
583
}
584