Completed
Pull Request — 4.0 (#3630)
by Kiyotaka
07:25
created

PluginController::handler_up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
41
class PluginController extends AbstractController
42
{
43
    /**
44
     * @var PluginService
45
     */
46
    protected $pluginService;
47
48
    /**
49
     * @var BaseInfo
50
     */
51
    protected $BaseInfo;
52
53
    /**
54
     * @var PluginRepository
55
     */
56
    protected $pluginRepository;
57
58
    /**
59
     * @var PluginApiService
60
     */
61
    protected $pluginApiService;
62
63
    /**
64
     * PluginController constructor.
65
     *
66
     * @param PluginRepository $pluginRepository
67
     * @param PluginService $pluginService
68
     * @param BaseInfoRepository $baseInfoRepository
69
     * @param PluginApiService $pluginApiService
70
     *
71
     * @throws \Doctrine\ORM\NoResultException
72
     * @throws \Doctrine\ORM\NonUniqueResultException
73
     */
74
    public function __construct(PluginRepository $pluginRepository, PluginService $pluginService, BaseInfoRepository $baseInfoRepository, PluginApiService $pluginApiService)
75
    {
76
        $this->pluginRepository = $pluginRepository;
77
        $this->pluginService = $pluginService;
78
        $this->BaseInfo = $baseInfoRepository->get();
79
        $this->pluginApiService = $pluginApiService;
80
    }
81
82
    /**
83
     * インストール済プラグイン画面
84
     *
85
     * @Route("/%eccube_admin_route%/store/plugin", name="admin_store_plugin")
86
     * @Template("@admin/Store/plugin.twig")
87
     */
88
    public function index(Request $request)
89
    {
90
        $pluginForms = [];
91
        $configPages = [];
92
        $Plugins = $this->pluginRepository->findBy([], ['code' => 'ASC']);
93
94
        // ファイル設置プラグインの取得.
95
        $unregisterdPlugins = $this->getUnregisteredPlugins($Plugins);
96
        $unregisterdPluginsConfigPages = [];
97
        foreach ($unregisterdPlugins as $unregisterdPlugin) {
98
            try {
99
                $code = $unregisterdPlugin['code'];
100
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
101
                $unregisterdPluginsConfigPages[$code] = $this->generateUrl('plugin_'.$code.'_config');
102
            } catch (RouteNotFoundException $e) {
103
                // プラグインで設定画面のルートが定義されていない場合は無視
104
            }
105
        }
106
107
        $officialPlugins = [];
108
        $unofficialPlugins = [];
109
110
        foreach ($Plugins as $Plugin) {
111
            $form = $this->formFactory
112
                ->createNamedBuilder(
113
                    'form'.$Plugin->getId(),
114
                    PluginManagementType::class,
115
                    null,
116
                    [
117
                        'plugin_id' => $Plugin->getId(),
118
                    ]
119
                )
120
                ->getForm();
121
            $pluginForms[$Plugin->getId()] = $form->createView();
122
123
            try {
124
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
125
                $configPages[$Plugin->getCode()] = $this->generateUrl(Container::underscore($Plugin->getCode()).'_admin_config');
126
            } catch (\Exception $e) {
127
                // プラグインで設定画面のルートが定義されていない場合は無視
128
            }
129
            if ($Plugin->getSource() == 0) {
130
                // 商品IDが設定されていない場合、非公式プラグイン
131
                $unofficialPlugins[] = $Plugin;
132
            } else {
133
                $officialPlugins[$Plugin->getSource()] = $Plugin;
134
            }
135
        }
136
137
        // Todo: Need new authentication mechanism
138
        // オーナーズストアからダウンロード可能プラグイン情報を取得
139
        $authKey = $this->BaseInfo->getAuthenticationKey();
140
        // オーナーズストア通信
141
        // TODO: get url from api service instead of direct from controller
142
        $url = $this->eccubeConfig['eccube_package_repo_url'].'/plugins/purchased';
143
        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...
144
        $officialPluginsDetail = [];
145
        if ($json) {
146
            // 接続成功時
147
            $data = json_decode($json, true);
148
            foreach ($data as $item) {
149
                if (isset($officialPlugins[$item['id']])) {
150
                    $Plugin = $officialPlugins[$item['id']];
151
                    $officialPluginsDetail[$item['id']] = $item;
152
                    $officialPluginsDetail[$item['id']]['update_status'] = 0;
153 View Code Duplication
                    if ($this->pluginService->isUpdate($Plugin->getVersion(), $item['version'])) {
154
                        $officialPluginsDetail[$item['id']]['update_status'] = 1;
155
                    }
156
                } else {
157
                    $Plugin = new Plugin();
158
                    $Plugin->setName($item['name']);
159
                    $Plugin->setCode($item['code']);
160
                    $Plugin->setVersion($item['version']);
161
                    $Plugin->setSource($item['id']);
162
                    $Plugin->setEnabled(false);
163
                    $officialPlugins[$item['id']] = $Plugin;
164
                    $officialPluginsDetail[$item['id']] = $item;
165
                    $officialPluginsDetail[$item['id']]['update_status'] = 0;
166 View Code Duplication
                    if ($this->pluginService->isUpdate($Plugin->getVersion(), $item['version'])) {
167
                        $officialPluginsDetail[$item['id']]['update_status'] = 1;
168
                    }
169
                }
170
            }
171
        }
172
173
        return [
174
            'plugin_forms' => $pluginForms,
175
            'officialPlugins' => $officialPlugins,
176
            'unofficialPlugins' => $unofficialPlugins,
177
            'configPages' => $configPages,
178
            'unregisterdPlugins' => $unregisterdPlugins,
179
            'unregisterdPluginsConfigPages' => $unregisterdPluginsConfigPages,
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={"PUT"})
253
     *
254
     * @param Plugin $Plugin
255
     *
256
     * @return RedirectResponse
257
     */
258 View Code Duplication
    public function enable(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...
259
    {
260
        $this->isTokenValid();
261
262
        if ($Plugin->isEnabled()) {
263
            $this->addError('admin.plugin.already.enable', 'admin');
264
        } else {
265
            $requires = $this->pluginService->findRequirePluginNeedEnable($Plugin->getCode());
266
            if (!empty($requires)) {
267
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $requires[0]]);
268
                $dependName = $requires[0];
269
                if ($DependPlugin) {
270
                    $dependName = $DependPlugin->getName();
271
                }
272
                $message = trans('admin.plugin.enable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
273
                $this->addError($message, 'admin');
274
275
                return $this->redirectToRoute('admin_store_plugin');
276
            }
277
            $this->pluginService->enable($Plugin);
278
            $this->addSuccess('admin.plugin.enable.complete', 'admin');
279
        }
280
281
        // キャッシュを削除してリダイレクト
282
        // リダイレクトにredirectToRoute関数を使用していないのは、削除したキャッシュが再生成されてしまうため。
283
        $url = $this->generateUrl('admin_store_plugin');
284
        $cacheUtil->clearCache();
285
286
        return $this->redirect($url);
287
    }
288
289
    /**
290
     * 対象のプラグインを無効にします。
291
     *
292
     * @Route("/%eccube_admin_route%/store/plugin/{id}/disable", requirements={"id" = "\d+"}, name="admin_store_plugin_disable", methods={"PUT"})
293
     *
294
     * @param Plugin $Plugin
295
     *
296
     * @return RedirectResponse
297
     */
298 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...
299
    {
300
        $this->isTokenValid();
301
302
        if ($Plugin->isEnabled()) {
303
            $dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode());
304
            if (!empty($dependents)) {
305
                $dependName = $dependents[0];
306
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]);
307
                if ($DependPlugin) {
308
                    $dependName = $DependPlugin->getName();
309
                }
310
                $message = trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
311
                $this->addError($message, 'admin');
312
313
                return $this->redirectToRoute('admin_store_plugin');
314
            }
315
316
            $this->pluginService->disable($Plugin);
317
            $this->addSuccess('admin.plugin.disable.complete', 'admin');
318
        } else {
319
            $this->addError('admin.plugin.already.disable', 'admin');
320
321
            return $this->redirectToRoute('admin_store_plugin');
322
        }
323
324
        // キャッシュを削除してリダイレクト
325
        // リダイレクトにredirectToRoute関数を使用していないのは、削除したキャッシュが再生成されてしまうため。
326
        $url = $this->generateUrl('admin_store_plugin');
327
        $cacheUtil->clearCache();
328
329
        return $this->redirect($url);
330
    }
331
332
    /**
333
     * 対象のプラグインを削除します。
334
     *
335
     * @Route("/%eccube_admin_route%/store/plugin/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_uninstall", methods={"DELETE"})
336
     *
337
     * @param Plugin $Plugin
338
     *
339
     * @return RedirectResponse
340
     */
341 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...
342
    {
343
        $this->isTokenValid();
344
345
        if ($Plugin->isEnabled()) {
346
            $this->addError('admin.plugin.uninstall.error.not_disable', 'admin');
347
348
            return $this->redirectToRoute('admin_store_plugin');
349
        }
350
351
        // Check other plugin depend on it
352
        $pluginCode = $Plugin->getCode();
353
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
354
        if (!empty($otherDepend)) {
355
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
356
            $dependName = $otherDepend[0];
357
            if ($DependPlugin) {
358
                $dependName = $DependPlugin->getName();
359
            }
360
            $message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
361
            $this->addError($message, 'admin');
362
363
            return $this->redirectToRoute('admin_store_plugin');
364
        }
365
366
        $this->pluginService->uninstall($Plugin);
367
        $this->addSuccess('admin.plugin.uninstall.complete', 'admin');
368
369
        return $this->redirectToRoute('admin_store_plugin');
370
    }
371
372
    /**
373
     * プラグインファイルアップロード画面
374
     *
375
     * @Route("/%eccube_admin_route%/store/plugin/install", name="admin_store_plugin_install")
376
     * @Template("@admin/Store/plugin_install.twig")
377
     *
378
     * @param Request $request
379
     *
380
     * @return array|RedirectResponse
381
     */
382
    public function install(Request $request)
383
    {
384
        $form = $this->formFactory
385
            ->createBuilder(PluginLocalInstallType::class)
386
            ->getForm();
387
        $errors = [];
388
        $form->handleRequest($request);
389
        if ($form->isSubmitted() && $form->isValid()) {
390
            $tmpDir = null;
391
            try {
392
                $service = $this->pluginService;
393
                /** @var UploadedFile $formFile */
394
                $formFile = $form['plugin_archive']->getData();
395
                $tmpDir = $service->createTempDir();
396
                // 拡張子を付けないとpharが動かないので付ける
397
                $tmpFile = sha1(StringUtil::random(32)).'.'.$formFile->getClientOriginalExtension();
398
                $formFile->move($tmpDir, $tmpFile);
399
                $tmpPath = $tmpDir.'/'.$tmpFile;
400
                $service->install($tmpPath);
401
                // Remove tmp file
402
                $fs = new Filesystem();
403
                $fs->remove($tmpDir);
404
                $this->addSuccess('admin.plugin.install.complete', 'admin');
405
406
                return $this->redirectToRoute('admin_store_plugin');
407
            } catch (PluginException $e) {
408
                if (!empty($tmpDir) && file_exists($tmpDir)) {
409
                    $fs = new Filesystem();
410
                    $fs->remove($tmpDir);
411
                }
412
                log_error('plugin install failed.', ['original-message' => $e->getMessage()]);
413
                $errors[] = $e;
414
            } catch (\Exception $er) {
415
                // Catch composer install error | Other error
416
                if (!empty($tmpDir) && file_exists($tmpDir)) {
417
                    $fs = new Filesystem();
418
                    $fs->remove($tmpDir);
419
                }
420
                log_error('plugin install failed.', ['original-message' => $er->getMessage()]);
421
                $this->addError('admin.plugin.install.fail', 'admin');
422
            }
423
        } else {
424
            foreach ($form->getErrors(true) as $error) {
425
                $errors[] = $error;
426
            }
427
        }
428
429
        return [
430
            'form' => $form->createView(),
431
            'errors' => $errors,
432
        ];
433
    }
434
435
    /**
436
     * 認証キー設定画面
437
     *
438
     * @Route("/%eccube_admin_route%/store/plugin/authentication_setting", name="admin_store_authentication_setting")
439
     * @Template("@admin/Store/authentication_setting.twig")
440
     */
441
    public function authenticationSetting(Request $request)
442
    {
443
        $builder = $this->formFactory
444
            ->createBuilder(AuthenticationType::class, $this->BaseInfo);
445
446
        $form = $builder->getForm();
447
        $form->handleRequest($request);
448
449
        if ($form->isSubmitted() && $form->isValid()) {
450
            // 認証キーの登録 and PHP path
451
            $this->BaseInfo = $form->getData();
452
            $this->entityManager->persist($this->BaseInfo);
453
            $this->entityManager->flush();
454
455
            $this->addSuccess('admin.flash.register_completed', 'admin');
456
        }
457
458
        $builderCaptcha = $this->formFactory->createBuilder(CaptchaType::class);
459
460
        // get captcha image, save it to temp folder
461
        list($captcha, $info) = $this->pluginApiService->getCaptcha();
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...
462
        $tmpFolder = $this->eccubeConfig->get('eccube_temp_image_dir');
463
        file_put_contents($tmpFolder.'/captcha.png', $captcha);
464
465
        return [
466
            'form' => $form->createView(),
467
            'captchaForm' => $builderCaptcha->getForm()->createView(),
468
        ];
469
    }
470
471
    /**
472
     * Captcha
473
     * Todo: check fail (implement after the api defined)
474
     *
475
     * @param Request $request
476
     *
477
     * @return RedirectResponse
478
     *
479
     * @Route("/%eccube_admin_route%/store/plugin/auth/captcha", name="admin_store_auth_captcha")
480
     */
481
    public function authenticationCaptcha(Request $request)
482
    {
483
        $builder = $this->formFactory->createBuilder(CaptchaType::class);
484
        $form = $builder->getForm();
485
        $form->handleRequest($request);
486
        if ($form->isSubmitted() && $form->isValid()) {
487
            $param['captcha'] = $form['captcha']->getData();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$param was never initialized. Although not strictly required by PHP, it is generally a good practice to add $param = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
488
            list($ret, $info) = $this->pluginApiService->postApiKey($param);
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...
489
            if ($ret && $data = json_decode($ret, true)) {
490
                if (isset($data['api_key']) && !empty($data['api_key'])) {
491
                    $this->BaseInfo->setAuthenticationKey($data['api_key']);
492
                    $this->entityManager->persist($this->BaseInfo);
493
                    $this->entityManager->flush($this->BaseInfo);
0 ignored issues
show
Unused Code introduced by
The call to EntityManagerInterface::flush() has too many arguments starting with $this->BaseInfo.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
494
                    $this->addSuccess('admin.flash.register_completed', 'admin');
495
496
                    return $this->redirectToRoute('admin_store_authentication_setting');
497
                }
498
            }
499
        }
500
        $this->addError('admin.flash.register_failed', 'admin');
501
502
        return $this->redirectToRoute('admin_store_authentication_setting');
503
    }
504
505
    /**
506
     * APIリクエスト処理
507
     *
508
     * @param Request $request
509
     * @param string|null $authKey
510
     * @param string $url
511
     *
512
     * @deprecated since release, please refer PluginApiService
513
     *
514
     * @return array
515
     */
516
    private function getRequestApi(Request $request, $authKey, $url)
517
    {
518
        $curl = curl_init($url);
519
520
        $options = [// オプション配列
521
            //HEADER
522
            CURLOPT_HTTPHEADER => [
523
                'Authorization: '.base64_encode($authKey),
524
                'x-eccube-store-url: '.base64_encode($request->getSchemeAndHttpHost().$request->getBasePath()),
525
                'x-eccube-store-version: '.base64_encode(Constant::VERSION),
526
            ],
527
            CURLOPT_HTTPGET => true,
528
            CURLOPT_SSL_VERIFYPEER => true,
529
            CURLOPT_RETURNTRANSFER => true,
530
            CURLOPT_FAILONERROR => true,
531
            CURLOPT_CAINFO => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(),
532
        ];
533
534
        curl_setopt_array($curl, $options); /// オプション値を設定
535
        $result = curl_exec($curl);
536
        $info = curl_getinfo($curl);
537
538
        $message = curl_error($curl);
539
        $info['message'] = $message;
540
        curl_close($curl);
541
542
        log_info('http get_info', $info);
543
544
        return [$result, $info];
545
    }
546
547
    /**
548
     * レスポンスのチェック
549
     *
550
     * @param $info
551
     *
552
     * @return string
553
     *
554
     * @deprecated since release, please refer PluginApiService
555
     */
556 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...
557
    {
558
        if (!empty($info)) {
559
            $statusCode = $info['http_code'];
560
            $message = $info['message'];
561
562
            $message = $statusCode.' : '.$message;
563
        } else {
564
            $message = trans('plugin.text.error.timeout_or_invalid_url');
565
        }
566
567
        return $message;
568
    }
569
570
    /**
571
     * フォルダ設置のみのプラグインを取得する.
572
     *
573
     * @param array $plugins
574
     *
575
     * @return array
576
     */
577
    protected function getUnregisteredPlugins(array $plugins)
578
    {
579
        $finder = new Finder();
580
        $pluginCodes = [];
581
582
        // DB登録済みプラグインコードのみ取得
583
        foreach ($plugins as $key => $plugin) {
584
            $pluginCodes[] = $plugin->getCode();
585
        }
586
        // DB登録済みプラグインコードPluginディレクトリから排他
587
        $dirs = $finder->in($this->eccubeConfig['plugin_realdir'])->depth(0)->directories();
588
589
        // プラグイン基本チェック
590
        $unregisteredPlugins = [];
591
        foreach ($dirs as $dir) {
592
            $pluginCode = $dir->getBasename();
593
            if (in_array($pluginCode, $pluginCodes, true)) {
594
                continue;
595
            }
596
            try {
597
                $this->pluginService->checkPluginArchiveContent($dir->getRealPath());
598
            } catch (\Eccube\Exception\PluginException $e) {
599
                //config.yamlに不備があった際は全てスキップ
600
                log_warning($e->getMessage());
601
                continue;
602
            }
603
            $config = $this->pluginService->readConfig($dir->getRealPath());
604
            $unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null;
605
            $unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null;
606
            $unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null;
607
            $unregisteredPlugins[$pluginCode]['enabled'] = Constant::DISABLED;
608
            $unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null;
609
        }
610
611
        return $unregisteredPlugins;
612
    }
613
}
614