Failed Conditions
Push — sf/package-api ( 831849...a77dd1 )
by Kiyotaka
06:40
created

OwnerStoreController::apiUpdate()   A

Complexity

Conditions 2
Paths 8

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 8
nop 1
dl 23
loc 23
rs 9.552
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\Controller\AbstractController;
17
use Eccube\Entity\BaseInfo;
18
use Eccube\Entity\Master\PageMax;
19
use Eccube\Entity\Plugin;
20
use Eccube\Form\Type\Admin\SearchPluginApiType;
21
use Eccube\Repository\BaseInfoRepository;
22
use Eccube\Repository\PluginRepository;
23
use Eccube\Service\Composer\ComposerApiService;
24
use Eccube\Service\Composer\ComposerProcessService;
25
use Eccube\Service\Composer\ComposerServiceInterface;
26
use Eccube\Service\PluginApiService;
27
use Eccube\Service\PluginService;
28
use Eccube\Service\SystemService;
29
use Eccube\Util\FormUtil;
30
use Knp\Component\Pager\Paginator;
31
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
32
use Symfony\Component\HttpFoundation\RedirectResponse;
33
use Symfony\Component\HttpFoundation\Request;
34
use Symfony\Component\HttpFoundation\Response;
35
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
36
use Symfony\Component\Routing\Annotation\Route;
37
38
/**
39
 * @Route("/%eccube_admin_route%/store/plugin/api")
40
 */
41
class OwnerStoreController extends AbstractController
42
{
43
    /**
44
     * @var PluginRepository
45
     */
46
    protected $pluginRepository;
47
48
    /**
49
     * @var PluginService
50
     */
51
    protected $pluginService;
52
53
    /**
54
     * @var ComposerServiceInterface
55
     */
56
    protected $composerService;
57
58
    /**
59
     * @var SystemService
60
     */
61
    protected $systemService;
62
63
    /**
64
     * @var PluginApiService
65
     */
66
    protected $pluginApiService;
67
68
    private static $vendorName = 'ec-cube';
69
70
    /** @var BaseInfo */
71
    private $BaseInfo;
72
73
    /**
74
     * OwnerStoreController constructor.
75
     *
76
     * @param PluginRepository $pluginRepository
77
     * @param PluginService $pluginService
78
     * @param ComposerProcessService $composerProcessService
79
     * @param ComposerApiService $composerApiService
80
     * @param SystemService $systemService
81
     * @param PluginApiService $pluginApiService
82
     * @param BaseInfoRepository $baseInfoRepository
83
     * @throws \Doctrine\ORM\NoResultException
84
     * @throws \Doctrine\ORM\NonUniqueResultException
85
     */
86
    public function __construct(
87
        PluginRepository $pluginRepository,
88
        PluginService $pluginService,
89
        ComposerProcessService $composerProcessService,
90
        ComposerApiService $composerApiService,
91
        SystemService $systemService,
92
        PluginApiService $pluginApiService,
93
        BaseInfoRepository $baseInfoRepository
94
    ) {
95
        $this->pluginRepository = $pluginRepository;
96
        $this->pluginService = $pluginService;
97
        $this->systemService = $systemService;
98
        $this->pluginApiService = $pluginApiService;
99
        $this->BaseInfo = $baseInfoRepository->get();
100
101
        // TODO: Check the flow of the composer service below
102
        $memoryLimit = $this->systemService->getMemoryLimit();
103
        if ($memoryLimit == -1 or $memoryLimit >= $this->eccubeConfig['eccube_composer_memory_limit']) {
104
            $this->composerService = $composerApiService;
105
        } else {
106
            $this->composerService = $composerProcessService;
107
        }
108
    }
109
110
    /**
111
     * Owner's Store Plugin Installation Screen - Search function
112
     *
113
     * @Route("/search", name="admin_store_plugin_owners_search")
114
     * @Route("/search/page/{page_no}", name="admin_store_plugin_owners_search_page", requirements={"page_no" = "\d+"})
115
     * @Template("@admin/Store/plugin_search.twig")
116
     *
117
     * @param Request     $request
118
     * @param int $page_no
119
     * @param Paginator $paginator
120
     *
121
     * @return array
122
     */
123
    public function search(Request $request, $page_no = null, Paginator $paginator)
124
    {
125
126
        if (!$this->BaseInfo->getAuthenticationKey()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->BaseInfo->getAuthenticationKey() of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
127
            $this->addWarning('認証キーを設定してください。', 'admin');
128
            return $this->redirectToRoute('admin_store_authentication_setting');
129
        }
130
131
        // Acquire downloadable plug-in information from owners store
132
        $items = [];
133
        $message = '';
134
        $total = 0;
135
        $category = [];
136
137
        list($json, $info) = $this->pluginApiService->getCategory();
138
        if (!empty($json)) {
139
            $data = json_decode($json, true);
140
            $category = array_column($data, 'name', 'id');
141
        }
142
143
        // build form with master data
144
        $builder = $this->formFactory
145
            ->createBuilder(SearchPluginApiType::class, null, ['category' => $category]);
146
        $searchForm = $builder->getForm();
147
148
        $searchForm->handleRequest($request);
149
        $searchData = $searchForm->getData();
150
        if ($searchForm->isSubmitted()) {
151
            if ($searchForm->isValid()) {
152
                $page_no = 1;
153
                $searchData = $searchForm->getData();
154
                $this->session->set('eccube.admin.plugin_api.search', FormUtil::getViewData($searchForm));
155
                $this->session->set('eccube.admin.plugin_api.search.page_no', $page_no);
156
            }
157
        } else {
158
            // quick search
159
            if (is_numeric($categoryId = $request->get('category_id')) && array_key_exists($categoryId, $category)) {
160
                $searchForm['category_id']->setData($categoryId);
161
            }
162
            // reset page count
163
            $this->session->set('eccube.admin.plugin_api.search.page_count', $this->eccubeConfig->get('eccube_default_page_count'));
164 View Code Duplication
            if (null !== $page_no || $request->get('resume')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
165
                if ($page_no) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $page_no of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
166
                    $this->session->set('eccube.admin.plugin_api.search.page_no', (int) $page_no);
167
                } else {
168
                    $page_no = $this->session->get('eccube.admin.plugin_api.search.page_no', 1);
169
                }
170
                $viewData = $this->session->get('eccube.admin.plugin_api.search', []);
171
                $searchData = FormUtil::submitAndGetData($searchForm, $viewData);
172
            } else {
173
                $page_no = 1;
174
                // submit default value
175
                $viewData = FormUtil::getViewData($searchForm);
176
                $searchData = FormUtil::submitAndGetData($searchForm, $viewData);
177
                $this->session->set('eccube.admin.plugin_api.search', $searchData);
178
                $this->session->set('eccube.admin.plugin_api.search.page_no', $page_no);
179
            }
180
        }
181
182
        // set page count
183
        $pageCount = $this->session->get('eccube.admin.plugin_api.search.page_count', $this->eccubeConfig->get('eccube_default_page_count'));
184
        if (($PageMax = $searchForm['page_count']->getData()) instanceof PageMax) {
185
            $pageCount = $PageMax->getId();
186
            $this->session->set('eccube.admin.plugin_api.search.page_count', $pageCount);
187
        }
188
189
        // Owner's store communication
190
        $searchData['page_no'] = $page_no;
191
        $searchData['page_count'] = $pageCount;
192
        list($json, $info) = $this->pluginApiService->getPlugins($searchData);
193
        if (empty($json)) {
194
            $message = $this->pluginApiService->getResponseErrorMessage($info);
195
        } else {
196
            $data = json_decode($json, true);
197
            $total = $data['total'];
198
            if (isset($data['plugins']) && count($data['plugins']) > 0) {
199
                // Check plugin installed
200
                $pluginInstalled = $this->pluginRepository->findAll();
201
                // Update_status 1 : not install/purchased 、2 : Installed、 3 : Update、4 : not purchased
202
                foreach ($data['plugins'] as $item) {
203
                    // Not install/purchased
204
                    $item['update_status'] = 1;
205
                    /** @var Plugin $plugin */
206
                    foreach ($pluginInstalled as $plugin) {
207
                        if ($plugin->getSource() == $item['id']) {
208
                            // Installed
209
                            $item['update_status'] = 2;
210
                            if ($this->pluginService->isUpdate($plugin->getVersion(), $item['version'])) {
211
                                // Need update
212
                                $item['update_status'] = 3;
213
                            }
214
                        }
215
                    }
216
                    if ($item['purchased'] == false && (isset($item['purchase_required']) && $item['purchase_required'] == true)) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $item['purchase_required'] of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
217
                        // Not purchased with paid items
218
                        $item['update_status'] = 4;
219
                    }
220
221
                    $item = $this->pluginService->buildInfo($item);
222
                    $items[] = $item;
223
                }
224
225
                // Todo: news api will remove this?
226
                // Promotion item
227
//                $i = 0;
228
//                foreach ($items as $item) {
229
//                    if ($item['promotion'] == 1) {
230
//                        $promotionItems[] = $item;
231
//                        unset($items[$i]);
232
//                    }
233
//                    $i++;
234
//                }
235
            } else {
236
                $message = trans('ownerstore.text.error.ec_cube_error');
237
            }
238
        }
239
240
        // The usage is set because `$items` are already paged.
241
        // virtual paging
242
        $pagination = $paginator->paginate($items, 1, $pageCount);
243
        $pagination->setTotalItemCount($total);
244
        $pagination->setCurrentPageNumber($page_no);
245
        $pagination->setItemNumberPerPage($pageCount);
246
247
        return [
248
            'pagination' => $pagination,
249
            'total' => $total,
250
            'searchForm' => $searchForm->createView(),
251
            'page_no' => $page_no,
252
            'message' => $message,
253
            'Categories' => $category,
254
        ];
255
    }
256
257
    /**
258
     * Do confirm page
259
     *
260
     * @Route("/install/{id}/confirm", requirements={"id" = "\d+"}, name="admin_store_plugin_install_confirm")
261
     * @Template("@admin/Store/plugin_confirm.twig")
262
     *
263
     * @param Request $request
264
     * @return array
265
     * @throws \Eccube\Exception\PluginException
266
     */
267
    public function doConfirm(Request $request, $id)
268
    {
269
        list($json) = $this->pluginApiService->getPlugin($id);
270
        $item = [];
271
        if ($json) {
272
            $data = json_decode($json, true);
273
            $item = $this->pluginService->buildInfo($data);
274
        }
275
276
        if (empty($item)) {
277
            throw new NotFoundHttpException();
278
        }
279
280
        // Todo: need define item's dependency mechanism
281
        $requires = $this->pluginService->getPluginRequired($item);
282
283
        return [
284
            'item' => $item,
285
            'requires' => $requires,
286
            'is_update' => $request->get('is_update', false),
287
        ];
288
    }
289
290
    /**
291
     * Api Install plugin by composer connect with package repo
292
     *
293
     * @Route("/install", name="admin_store_plugin_api_install", methods={"POST"})
294
     *
295
     * @param Request $request
296
     *
297
     * @return \Symfony\Component\HttpFoundation\JsonResponse
298
     */
299
    public function apiInstall(Request $request)
300
    {
301
        $this->isTokenValid();
302
303
        $pluginCode = $request->get('pluginCode');
304
305
        $log = null;
306
        try {
307
            $log = $this->composerService->execRequire("ec-cube/".$pluginCode);
308
309
            return $this->json(['success' => true, 'log' => $log]);
310
        } catch (\Exception $e) {
311
            $log = $e->getMessage();
312
            log_error($e);
313
        }
314
315
        return $this->json(['success' => false, 'log' => $log], 500);
316
    }
317
318
    /**
319
     * Do confirm page
320
     *
321
     * @Route("/delete/{id}/confirm", requirements={"id" = "\d+"}, name="admin_store_plugin_delete_confirm")
322
     * @Template("@admin/Store/plugin_confirm_uninstall.twig")
323
     *
324
     * @param Plugin $Plugin
325
     *
326
     * @return array|RedirectResponse
327
     */
328
    public function deleteConfirm(Plugin $Plugin)
329
    {
330
        // Owner's store communication
331
        $url = $this->eccubeConfig['eccube_package_repo_url'].'/search/packages.json';
332
        list($json, $info) = $this->getRequestApi($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 preference 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...
333
        $data = json_decode($json, true);
334
        $items = $data['item'];
335
336
        // The plugin depends on it
337
        $pluginCode = $Plugin->getCode();
338
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
339
340
        if (!empty($otherDepend)) {
341
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
342
            $dependName = $otherDepend[0];
343
            if ($DependPlugin) {
344
                $dependName = $DependPlugin->getName();
345
            }
346
            $message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
347
            $this->addError($message, 'admin');
348
349
            return $this->redirectToRoute('admin_store_plugin');
350
        }
351
352
        // Check plugin in api
353
        $pluginSource = $Plugin->getSource();
354
        $index = array_search($pluginSource, array_column($items, 'product_id'));
355
        if ($index === false) {
356
            throw new NotFoundHttpException();
357
        }
358
359
        // Build info
360
        $pluginCode = $Plugin->getCode();
361
        $plugin = $this->pluginService->buildInfo($items, $pluginCode);
0 ignored issues
show
Unused Code introduced by
The call to PluginService::buildInfo() has too many arguments starting with $pluginCode.

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...
362
        $plugin['id'] = $Plugin->getId();
363
364
        return [
365
            'item' => $plugin,
366
        ];
367
    }
368
369
    /**
370
     * New ways to remove plugin: using composer command
371
     *
372
     * @Route("/delete/{id}/uninstall", requirements={"id" = "\d+"}, name="admin_store_plugin_api_uninstall", methods={"DELETE"})
373
     *
374
     * @param Plugin $Plugin
375
     *
376
     * @return \Symfony\Component\HttpFoundation\JsonResponse
377
     */
378
    public function apiUninstall(Plugin $Plugin)
379
    {
380
        $this->isTokenValid();
381
382
        if ($Plugin->isEnabled()) {
383
            return $this->json(['success' => false, 'message' => trans('admin.plugin.uninstall.error.not_disable')], 400);
384
        }
385
386
        $pluginCode = $Plugin->getCode();
387
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
388
389
        if (!empty($otherDepend)) {
390
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
391
            $dependName = $otherDepend[0];
392
            if ($DependPlugin) {
393
                $dependName = $DependPlugin->getName();
394
            }
395
            $message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
396
397
            return $this->json(['success' => false, 'message' => $message], 400);
398
        }
399
400
        $pluginCode = $Plugin->getCode();
401
        $packageName = self::$vendorName.'/'.$pluginCode;
402
        try {
403
            $log = $this->composerService->execRemove($packageName);
404
            return $this->json(['success' => false, 'log' => $log]);
405
        } catch (\Exception $e) {
406
            log_error($e);
407
            return $this->json(['success' => false, 'log' => $e->getMessage()], 500);
408
        }
409
410
    }
411
412
    /**
413
     * オーナーズブラグインインストール、アップデート
414
     *
415
     * @Route("/upgrade", name="admin_store_plugin_api_upgrade", methods={"POST"})
416
     *
417
     * @param Request $request
418
     * @return \Symfony\Component\HttpFoundation\JsonResponse
419
     */
420
    public function apiUpgrade(Request $request)
421
    {
422
        $this->isTokenValid();
423
424
        $pluginCode = $request->get('pluginCode');
425
        $version = $request->get('version');
426
427
        $log = null;
428
        try {
429
            $log = $this->composerService->execRequire("ec-cube/".$pluginCode.':'.$version);
430
431
            return $this->json(['success' => true, 'log' => $log]);
432
        } catch (\Exception $e) {
433
            $log = $e->getMessage();
434
            log_error($e);
435
        }
436
437
        return $this->json(['success' => false, 'log' => $log], 500);
438
    }
439
440
    /**
441
     * オーナーズブラグインインストール、スキーマ更新
442
     *
443
     * @Route("/schema_update", name="admin_store_plugin_api_schema_update", methods={"POST"})
444
     *
445
     * @param Request $request
446
     * @return \Symfony\Component\HttpFoundation\JsonResponse
447
     */
448 View Code Duplication
    public function apiSchemaUpdate(Request $request)
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...
449
    {
450
        $this->isTokenValid();
451
452
        $pluginCode = $request->get('pluginCode');
453
454
        try {
455
            $Plugin = $this->pluginRepository->findByCode($pluginCode);
456
            $config = $this->pluginService->readConfig($this->pluginService->calcPluginDir($Plugin->getCode()));
457
458
            ob_start();
459
            $this->pluginService->generateProxyAndUpdateSchema($Plugin, $config);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository->findByCode($pluginCode) on line 455 can be null; however, Eccube\Service\PluginSer...eProxyAndUpdateSchema() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
460
            $log = ob_get_clean();
461
            ob_end_flush();
462
463
            return $this->json(['success' => true, 'log' => $log]);
464
        } catch (\Exception $e) {
465
            $log = $e->getMessage();
466
            log_error($e);
467
            return $this->json(['success' => false, 'log' => $log], 500);
468
        }
469
470
    }
471
472
    /**
473
     * オーナーズブラグインインストール、更新処理
474
     *
475
     * @Route("/update", name="admin_store_plugin_api_update", methods={"POST"})
476
     *
477
     * @param Request $request
478
     * @return \Symfony\Component\HttpFoundation\JsonResponse
479
     */
480 View Code Duplication
    public function apiUpdate(Request $request)
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...
481
    {
482
        $this->isTokenValid();
483
484
        $pluginCode = $request->get('pluginCode');
485
486
        $log = null;
487
        try {
488
            $Plugin = $this->pluginRepository->findByCode($pluginCode);
489
            $config = $this->pluginService->readConfig($this->pluginService->calcPluginDir($Plugin->getCode()));
490
            ob_start();
491
            $this->pluginService->updatePlugin($Plugin, $config);
0 ignored issues
show
Bug introduced by
It seems like $Plugin defined by $this->pluginRepository->findByCode($pluginCode) on line 488 can be null; however, Eccube\Service\PluginService::updatePlugin() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
492
            $log = ob_get_clean();
493
            ob_end_flush();
494
495
            return $this->json(['success' => true, 'log' => $log]);
496
        } catch (\Exception $e) {
497
            $log = $e->getMessage();
498
            log_error($e);
499
        }
500
501
        return $this->json(['success' => false, 'log' => $log], 500);
502
    }
503
504
    /**
505
     * Do confirm update page
506
     *
507
     * @Route("/upgrade/{id}/confirm", requirements={"id" = "\d+"}, name="admin_store_plugin_update_confirm")
508
     * @Template("@admin/Store/plugin_confirm.twig")
509
     *
510
     * @param Request $request
511
     * @param Plugin $Plugin
512
     * @return array
513
     */
514
    public function doUpdateConfirm(Request $request, Plugin $Plugin)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
515
    {
516
        list($json) = $this->pluginApiService->getPlugin($Plugin->getSource());
517
        $item = [];
518
        if ($json) {
519
            $data = json_decode($json, true);
520
            $item = $this->pluginService->buildInfo($data);
521
        }
522
523
        if (empty($item)) {
524
            throw new NotFoundHttpException();
525
        }
526
//
527
//        // Todo: need define item's dependency mechanism
528
//        $requires = $this->pluginService->getPluginRequired($item);
529
530
        return [
531
            'item' => $item,
532
            'requires' => [],
533
            'is_update' => true,
534
            'Plugin' => $Plugin
535
        ];
536
537
    }
538
539
    /**
540
     * API request processing
541
     *
542
     * @param string $url
543
     *
544
     * @return array
545
     *
546
     * @deprecated since release, please preference PluginApiService
547
     */
548
    private function getRequestApi($url)
549
    {
550
        $curl = curl_init($url);
551
552
        // Option array
553
        $options = [
554
            // HEADER
555
            CURLOPT_HTTPGET => true,
556
            CURLOPT_SSL_VERIFYPEER => false,
557
            CURLOPT_RETURNTRANSFER => true,
558
            CURLOPT_FAILONERROR => true,
559
            CURLOPT_CAINFO => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath(),
560
        ];
561
562
        // Set option value
563
        curl_setopt_array($curl, $options);
564
        $result = curl_exec($curl);
565
        $info = curl_getinfo($curl);
566
        $message = curl_error($curl);
567
        $info['message'] = $message;
568
        curl_close($curl);
569
570
        log_info('http get_info', $info);
571
572
        return [$result, $info];
573
    }
574
575
    /**
576
     * API post request processing
577
     *
578
     * @param string $url
579
     * @param array $data
580
     *
581
     * @return array
582
     *
583
     * @deprecated since release, please preference PluginApiService
584
     */
585
    private function postRequestApi($url, $data)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
586
    {
587
        $curl = curl_init($url);
588
        curl_setopt($curl, CURLOPT_URL, $url);
589
        curl_setopt($curl, CURLOPT_POST, 1);
590
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
591
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
592
        $result = curl_exec($curl);
593
        $info = curl_getinfo($curl);
594
        $message = curl_error($curl);
595
        $info['message'] = $message;
596
        curl_close($curl);
597
        log_info('http post_info', $info);
598
599
        return [$result, $info];
600
    }
601
}
602