Completed
Push — experimental/3.1 ( f5947c...5d0f05 )
by Ryo
48:59
created

PluginController::update()   C

Complexity

Conditions 10
Paths 39

Size

Total Lines 54
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
eloc 40
nc 39
nop 3
dl 0
loc 54
ccs 0
cts 30
cp 0
crap 110
rs 6.8372
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
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Controller\Admin\Store;
26
27
use Doctrine\ORM\EntityManager;
28
use Eccube\Annotation\Inject;
29
use Eccube\Application;
30
use Eccube\Common\Constant;
31
use Eccube\Controller\AbstractController;
32
use Eccube\Entity\BaseInfo;
33
use Eccube\Entity\Plugin;
34
use Eccube\Entity\PluginEventHandler;
35
use Eccube\Exception\PluginException;
36
use Eccube\Form\Type\Admin\PluginLocalInstallType;
37
use Eccube\Form\Type\Admin\PluginManagementType;
38
use Eccube\Repository\PluginEventHandlerRepository;
39
use Eccube\Repository\PluginRepository;
40
use Eccube\Service\PluginService;
41
use Eccube\Util\StringUtil;
42
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
43
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
44
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
45
use Symfony\Bridge\Monolog\Logger;
46
use Symfony\Component\Filesystem\Filesystem;
47
use Symfony\Component\Finder\Finder;
48
use Symfony\Component\Form\Extension\Core\Type\FormType;
49
use Symfony\Component\Form\Extension\Core\Type\TextType;
50
use Symfony\Component\Form\FormFactory;
51
use Symfony\Component\HttpFoundation\File\UploadedFile;
52
use Symfony\Component\HttpFoundation\RedirectResponse;
53
use Symfony\Component\HttpFoundation\Request;
54
use Symfony\Component\Routing\Exception\RouteNotFoundException;
55
use Symfony\Component\Validator\Constraints as Assert;
56
57
/**
58
 * @Route(service=PluginController::class)
59
 */
60
class PluginController extends AbstractController
61
{
62
    /**
63
     * @Inject("orm.em")
64
     * @var EntityManager
65
     */
66
    protected $entityManager;
67
68
    /**
69
     * @Inject("monolog")
70
     * @var Logger
71
     */
72
    protected $logger;
73
74
    /**
75
     * @Inject(PluginEventHandlerRepository::class)
76
     * @var PluginEventHandlerRepository
77
     */
78
    protected $pluginEventHandlerRepository;
79
80
    /**
81
     * @Inject(PluginService::class)
82
     * @var PluginService
83
     */
84
    protected $pluginService;
85
86
    /**
87
     * @Inject("config")
88
     * @var array
89
     */
90
    protected $appConfig;
91
92
    /**
93
     * @Inject(BaseInfo::class)
94
     * @var BaseInfo
95
     */
96
    protected $BaseInfo;
97
98
    /**
99
     * @Inject("form.factory")
100
     * @var FormFactory
101
     */
102
    protected $formFactory;
103
104
    /**
105
     * @Inject(PluginRepository::class)
106
     * @var PluginRepository
107
     */
108
    protected $pluginRepository;
109
110
111
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
112
     * インストール済プラグイン画面
113
     *
114
     * @Route("/{_admin}/store/plugin", name="admin_store_plugin")
115
     * @Template("Store/plugin.twig")
116
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
117
    public function index(Application $app, Request $request)
118
    {
119
        $pluginForms = array();
120
        $configPages = array();
121
        $Plugins = $this->pluginRepository->findBy(array(), array('code' => 'ASC'));
122
123
        // ファイル設置プラグインの取得.
124
        $unregisterdPlugins = $this->getUnregisteredPlugins($Plugins, $app);
125
        $unregisterdPluginsConfigPages = array();
126
        foreach ($unregisterdPlugins as $unregisterdPlugin) {
127
            try {
128
                $code = $unregisterdPlugin['code'];
129
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
130
                $unregisterdPluginsConfigPages[$code] = $app->url('plugin_'.$code.'_config');
131
            } catch (RouteNotFoundException $e) {
132
                // プラグインで設定画面のルートが定義されていない場合は無視
133
            }
134
        }
135
136
        $officialPlugins = array();
137
        $unofficialPlugins = array();
138
139
        foreach ($Plugins as $Plugin) {
140
            $form = $this->formFactory
141
                ->createNamedBuilder(
142
                    'form'.$Plugin->getId(),
143
                    PluginManagementType::class,
144
                    null,
145
                    array(
146
                        'plugin_id' => $Plugin->getId(),
147
                    )
148
                )
149
                ->getForm();
150
            $pluginForms[$Plugin->getId()] = $form->createView();
151
152
            try {
153
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
154
                $configPages[$Plugin->getCode()] = $app->url('plugin_'.$Plugin->getCode().'_config');
155
            } catch (\Exception $e) {
156
                // プラグインで設定画面のルートが定義されていない場合は無視
157
            }
158
            if ($Plugin->getSource() == 0) {
159
                // 商品IDが設定されていない場合、非公式プラグイン
160
                $unofficialPlugins[] = $Plugin;
161
            } else {
162
                $officialPlugins[] = $Plugin;
163
            }
164
        }
165
166
        // Todo: Need new authentication mechanism
167
        // オーナーズストアからダウンロード可能プラグイン情報を取得
168
        $authKey = $this->BaseInfo->getAuthenticationKey();
169
        // オーナーズストア通信
170
        $url = $this->appConfig['package_repo_url'].'/search/packages.json';
171
        list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app);
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...
172
173
        $officialPluginsDetail = [];
174
        if ($json) {
175
            // 接続成功時
176
            $data = json_decode($json, true);
177
            if (isset($data['success']) && $data['success']) {
178
                foreach ($data['item'] as $item) {
179
                    foreach ($officialPlugins as $key => $plugin) {
180
                        if ($plugin->getSource() == $item['product_id']) {
181
                            $officialPluginsDetail[$key] = $item;
182
                            $officialPluginsDetail[$key]['update_status'] = 0;
183
                            if ($this->pluginService->isUpdate($plugin->getVersion(), $item['version'])) {
184
                                $officialPluginsDetail[$key]['update_status'] = 1;
185
                            }
186
                        }
187
                    }
188
                }
189
            }
190
        }
191
192
        return [
193
            'plugin_forms' => $pluginForms,
194
            'officialPlugins' => $officialPlugins,
195
            'unofficialPlugins' => $unofficialPlugins,
196
            'configPages' => $configPages,
197
            'unregisterdPlugins' => $unregisterdPlugins,
198
            'unregisterdPluginsConfigPages' => $unregisterdPluginsConfigPages,
199
            'officialPluginsDetail' => $officialPluginsDetail,
200
        ];
201
    }
202
203
    /**
204
     * インストール済プラグインからのアップデート
205
     *
206
     * @Method("POST")
207
     * @Route("/{_admin}/store/plugin/{id}/update", requirements={"id" = "\d+"}, name="admin_store_plugin_update")
208
     * @param Application $app
209
     * @param Request     $request
210
     * @param Plugin      $Plugin
211
     * @return RedirectResponse
212
     */
213
    public function update(Application $app, Request $request, Plugin $Plugin)
214
    {
215
        $form = $this->formFactory
216
            ->createNamedBuilder(
217
                'form'.$Plugin->getId(),
218
                PluginManagementType::class,
219
                null,
220
                array(
221
                    'plugin_id' => null, // placeHolder
222
                )
223
            )
224
            ->getForm();
225
226
        $message = '';
227
        $form->handleRequest($request);
228
        if ($form->isSubmitted() && $form->isValid()) {
229
            $tmpDir = null;
230
            try {
231
                $formFile = $form['plugin_archive']->getData();
232
                $tmpDir = $this->pluginService->createTempDir();
233
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
234
                $formFile->move($tmpDir, $tmpFile);
235
                $this->pluginService->update($Plugin, $tmpDir.'/'.$tmpFile);
236
                $fs = new Filesystem();
237
                $fs->remove($tmpDir);
238
                $app->addSuccess('admin.plugin.update.complete', 'admin');
239
240
                return $app->redirect($app->url('admin_store_plugin'));
241
            } catch (PluginException $e) {
242
                if (!empty($tmpDir) && file_exists($tmpDir)) {
243
                    $fs = new Filesystem();
244
                    $fs->remove($tmpDir);
245
                }
246
                $message = $e->getMessage();
247
            } catch (\Exception $er) {
248
                // Catch composer install error | Other error
249
                if (!empty($tmpDir) && file_exists($tmpDir)) {
250
                    $fs = new Filesystem();
251
                    $fs->remove($tmpDir);
252
                }
253
                $this->logger->error("plugin install failed.", array('original-message' => $er->getMessage()));
254
                $message = 'admin.plugin.install.fail';
255
            }
256
        } else {
257
            $errors = $form->getErrors(true);
258
            foreach ($errors as $error) {
259
                $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...
260
            }
261
        }
262
263
        $app->addError($message, 'admin');
264
265
        return $app->redirect($app->url('admin_store_plugin'));
266
    }
267
268
269
    /**
270
     * 対象のプラグインを有効にします。
271
     *
272
     * @Method("PUT")
273
     * @Route("/{_admin}/store/plugin/{id}/enable", requirements={"id" = "\d+"}, name="admin_store_plugin_enable")
274
     * @param Application $app
275
     * @param Plugin      $Plugin
276
     * @return RedirectResponse
277
     */
278 View Code Duplication
    public function enable(Application $app, 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...
279
    {
280
        $this->isTokenValid($app);
281
282
        if ($Plugin->isEnabled()) {
283
            $app->addError('admin.plugin.already.enable', 'admin');
284
        } else {
285
            $requires = $this->pluginService->findRequirePluginNeedEnable($Plugin->getCode());
286
            if (!empty($requires)) {
287
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $requires[0]]);
288
                $dependName = $requires[0];
289
                if ($DependPlugin) {
290
                    $dependName = $DependPlugin->getName();
291
                }
292
                $message = $app->trans('admin.plugin.enable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
293
                $app->addError($message, 'admin');
294
295
                return $app->redirect($app->url('admin_store_plugin'));
296
            }
297
            $this->pluginService->enable($Plugin);
298
            $app->addSuccess('admin.plugin.enable.complete', 'admin');
299
        }
300
301
        return $app->redirect($app->url('admin_store_plugin'));
302
    }
303
304
    /**
305
     * 対象のプラグインを無効にします。
306
     *
307
     * @Method("PUT")
308
     * @Route("/{_admin}/store/plugin/{id}/disable", requirements={"id" = "\d+"}, name="admin_store_plugin_disable")
309
     * @param Application $app
310
     * @param Plugin      $Plugin
311
     * @return RedirectResponse
312
     */
313 View Code Duplication
    public function disable(Application $app, 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...
314
    {
315
        $this->isTokenValid($app);
316
317
        if ($Plugin->isEnabled()) {
318
            $dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode());
319
            if (!empty($dependents)) {
320
                $dependName = $dependents[0];
321
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]);
322
                if ($DependPlugin) {
323
                    $dependName = $DependPlugin->getName();
324
                }
325
                $message = $app->trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
326
                $app->addError($message, 'admin');
327
328
                return $app->redirect($app->url('admin_store_plugin'));
329
            }
330
331
            $this->pluginService->disable($Plugin);
332
            $app->addSuccess('admin.plugin.disable.complete', 'admin');
333
        } else {
334
            $app->addError('admin.plugin.already.disable', 'admin');
335
        }
336
337
        return $app->redirect($app->url('admin_store_plugin'));
338
    }
339
340
    /**
341
     * 対象のプラグインを削除します。
342
     *
343
     * @Method("DELETE")
344
     * @Route("/{_admin}/store/plugin/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_uninstall")
345
     * @param Application $app
346
     * @param Plugin      $Plugin
347
     * @return RedirectResponse
348
     */
349
    public function uninstall(Application $app, Plugin $Plugin)
350
    {
351
        $this->isTokenValid($app);
352
        // Check other plugin depend on it
353
        $pluginCode = $Plugin->getCode();
354
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
355
        if (!empty($otherDepend)) {
356
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
357
            $dependName = $otherDepend[0];
358
            if ($DependPlugin) {
359
                $dependName = $DependPlugin->getName();
360
            }
361
            $message = $app->trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
362
            $app->addError($message, 'admin');
363
364
            return $app->redirect($app->url('admin_store_plugin'));
365
        }
366
367
        $this->pluginService->uninstall($Plugin);
368
        $app->addSuccess('admin.plugin.uninstall.complete', 'admin');
369
370
        return $app->redirect($app->url('admin_store_plugin'));
371
    }
372
373
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
374
     * @Route("/{_admin}/store/plugin/handler", name="admin_store_plugin_handler")
375
     * @Template("Store/plugin_handler.twig")
376
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
377
    public function handler(Application $app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
378
    {
379
        $handlers = $this->pluginEventHandlerRepository->getHandlers();
380
381
        // 一次元配列からイベント毎の二次元配列に変換する
382
        $HandlersPerEvent = array();
383
        foreach ($handlers as $handler) {
384
            $HandlersPerEvent[$handler->getEvent()][$handler->getHandlerType()][] = $handler;
385
        }
386
387
        return [
388
            'handlersPerEvent' => $HandlersPerEvent,
389
        ];
390
    }
391
392
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$Handler" missing
Loading history...
393
     * @Route("/{_admin}/store/plugin/handler_up/{id}", requirements={"id" = "\d+"}, name="admin_store_plugin_handler_up")
394
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
395 View Code Duplication
    public function handler_up(Application $app, PluginEventHandler $Handler)
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...
Coding Style introduced by
Method name "PluginController::handler_up" is not in camel caps format
Loading history...
396
    {
397
        $repo = $this->pluginEventHandlerRepository;
398
        $repo->upPriority($repo->find($Handler->getId()));
399
400
        return $app->redirect($app->url('admin_store_plugin_handler'));
401
    }
402
403
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$Handler" missing
Loading history...
404
     * @Route("/{_admin}/store/plugin/handler_down/{id}", requirements={"id" = "\d+"}, name="admin_store_plugin_handler_down")
405
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
406 View Code Duplication
    public function handler_down(Application $app, PluginEventHandler $Handler)
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...
Coding Style introduced by
Method name "PluginController::handler_down" is not in camel caps format
Loading history...
407
    {
408
        $repo = $this->pluginEventHandlerRepository;
409
        $repo->upPriority($Handler, false);
410
411
        return $app->redirect($app->url('admin_store_plugin_handler'));
412
    }
413
414
    /**
415
     * プラグインファイルアップロード画面
416
     *
417
     * @Route("/{_admin}/store/plugin/install", name="admin_store_plugin_install")
418
     * @Template("Store/plugin_install.twig")
419
     * @param Application $app
420
     * @param Request     $request
421
     * @return array|RedirectResponse
422
     */
423
    public function install(Application $app, Request $request)
424
    {
425
        $form = $this->formFactory
426
            ->createBuilder(PluginLocalInstallType::class)
427
            ->getForm();
428
        $errors = array();
429
        $form->handleRequest($request);
430
        if ($form->isSubmitted() && $form->isValid()) {
431
            $tmpDir = null;
432
            try {
433
                $service = $this->pluginService;
434
                /** @var UploadedFile $formFile */
435
                $formFile = $form['plugin_archive']->getData();
436
                $tmpDir = $service->createTempDir();
437
                // 拡張子を付けないとpharが動かないので付ける
438
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
439
                $formFile->move($tmpDir, $tmpFile);
440
                $tmpPath = $tmpDir.'/'.$tmpFile;
441
                $service->install($tmpPath);
442
                // Remove tmp file
443
                $fs = new Filesystem();
444
                $fs->remove($tmpDir);
445
                $app->addSuccess('admin.plugin.install.complete', 'admin');
446
447
                return $app->redirect($app->url('admin_store_plugin'));
448
            } catch (PluginException $e) {
449
                if (!empty($tmpDir) && file_exists($tmpDir)) {
450
                    $fs = new Filesystem();
451
                    $fs->remove($tmpDir);
452
                }
453
                $this->logger->error("plugin install failed.", array('original-message' => $e->getMessage()));
454
                $errors[] = $e;
455
            } catch (\Exception $er) {
456
                // Catch composer install error | Other error
457
                if (!empty($tmpDir) && file_exists($tmpDir)) {
458
                    $fs = new Filesystem();
459
                    $fs->remove($tmpDir);
460
                }
461
                $this->logger->error("plugin install failed.", array('original-message' => $er->getMessage()));
462
                $app->addError('admin.plugin.install.fail', 'admin');
463
            }
464
        } else {
465
            foreach ($form->getErrors(true) as $error) {
466
                $errors[] = $error;
467
            }
468
        }
469
470
        return [
471
            'form' => $form->createView(),
472
            'errors' => $errors,
473
        ];
474
    }
475
476
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
477
     * 認証キー設定画面
478
     *
479
     * @Route("/{_admin}/store/plugin/authentication_setting", name="admin_store_authentication_setting")
480
     * @Template("Store/authentication_setting.twig")
481
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
482
    public function authenticationSetting(Application $app, Request $request)
483
    {
484
        $builder = $this->formFactory
485
            ->createBuilder(FormType::class, $this->BaseInfo);
486
        $builder->add(
487
            'authentication_key',
488
            TextType::class,
489
            [
490
                'label' => '認証キー',
491
                'constraints' => [
492
                    new Assert\Regex(['pattern' => "/^[0-9a-zA-Z]+$/",]),
0 ignored issues
show
introduced by
Add a single space after each comma delimiter
Loading history...
493
                ],
494
            ]
495
        );
496
497
        $form = $builder->getForm();
498
        $form->handleRequest($request);
499
500
        if ($form->isSubmitted() && $form->isValid()) {
501
            // 認証キーの登録
502
            $BaseInfo = $form->getData();
503
            $this->entityManager->flush($BaseInfo);
504
505
            $app->addSuccess('admin.plugin.authentication.setting.complete', 'admin');
506
        }
507
508
        return [
509
            'form' => $form->createView(),
510
        ];
511
    }
512
513
514
    /**
515
     * APIリクエスト処理
516
     *
517
     * @param Request $request
518
     * @param $authKey
519
     * @param string $url
520
     * @param Application $app
521
     * @return array
522
     */
523
    private function getRequestApi(Request $request, $authKey, $url, $app)
524
    {
525
        $curl = curl_init($url);
526
527
        $options = array(           // オプション配列
528
            //HEADER
529
            CURLOPT_HTTPHEADER => array(
530
                'Authorization: '.base64_encode($authKey),
531
                'x-eccube-store-url: '.base64_encode($request->getSchemeAndHttpHost().$request->getBasePath()),
532
                'x-eccube-store-version: '.base64_encode(Constant::VERSION),
533
            ),
534
            CURLOPT_HTTPGET => true,
535
            CURLOPT_SSL_VERIFYPEER => true,
536
            CURLOPT_RETURNTRANSFER => true,
537
            CURLOPT_FAILONERROR => true,
538
            CURLOPT_CAINFO => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(),
539
        );
540
541
        curl_setopt_array($curl, $options); /// オプション値を設定
542
        $result = curl_exec($curl);
543
        $info = curl_getinfo($curl);
544
545
        $message = curl_error($curl);
546
        $info['message'] = $message;
547
        curl_close($curl);
548
549
        $app->log('http get_info', $info);
550
551
        return array($result, $info);
552
    }
553
554
    /**
555
     * レスポンスのチェック
556
     *
557
     * @param $info
558
     * @return string
559
     */
560 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...
561
    {
562
        if (!empty($info)) {
563
            $statusCode = $info['http_code'];
564
            $message = $info['message'];
565
566
            $message = $statusCode.' : '.$message;
567
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
568
        } else {
569
            $message = "タイムアウトエラーまたはURLの指定に誤りがあります。";
570
        }
571
572
        return $message;
573
    }
574
575
576
    /**
577
     * フォルダ設置のみのプラグインを取得する.
578
     *
579
     * @param array $plugins
580
     * @param Application $app
581
     * @return array
582
     */
583
    protected function getUnregisteredPlugins(array $plugins, \Eccube\Application $app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
584
    {
585
        $finder = new Finder();
586
        $pluginCodes = array();
587
588
        // DB登録済みプラグインコードのみ取得
589
        foreach ($plugins as $key => $plugin) {
590
            $pluginCodes[] = $plugin->getCode();
591
        }
592
        // DB登録済みプラグインコードPluginディレクトリから排他
593
        $dirs = $finder->in($this->appConfig['plugin_realdir'])->depth(0)->directories();
594
595
        // プラグイン基本チェック
596
        $unregisteredPlugins = array();
597
        foreach ($dirs as $dir) {
598
            $pluginCode = $dir->getBasename();
599
            if (in_array($pluginCode, $pluginCodes, true)) {
600
                continue;
601
            }
602
            try {
603
                $this->pluginService->checkPluginArchiveContent($dir->getRealPath());
604
            } catch (\Eccube\Exception\PluginException $e) {
605
                //config.yamlに不備があった際は全てスキップ
606
                $this->logger->warning($e->getMessage());
607
                continue;
608
            }
609
            $config = $this->pluginService->readYml($dir->getRealPath().'/config.yml');
610
            $unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null;
611
            $unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null;
612
            $unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null;
613
            $unregisteredPlugins[$pluginCode]['enabled'] = Constant::DISABLED;
614
            $unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null;
615
        }
616
617
        return $unregisteredPlugins;
618
    }
619
}
620