Failed Conditions
Push — improve/performance ( 85882a...af114f )
by Ryo
414:05 queued 405:58
created

Eccube/Controller/Admin/Store/PluginController.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Controller\AbstractController;
30
use Eccube\Exception\PluginException;
31
use Eccube\Util\Cache;
32
use Eccube\Util\Str;
33
use Symfony\Component\Filesystem\Filesystem;
34
use Symfony\Component\Finder\Finder;
35
use Symfony\Component\HttpFoundation\Request;
36
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
37
use Symfony\Component\Routing\Exception\RouteNotFoundException;
38
use Symfony\Component\Validator\Constraints as Assert;
39
use Symfony\Component\Form\FormError;
40
use Monolog\Logger;
41
42
class PluginController extends AbstractController
43
{
44
45
    /**
46
     * @var string 証明書ファイル
47
     */
48
    private $certFileName = 'cacert.pem';
49
50
    /**
51
     * インストール済プラグイン画面
52
     *
53
     * @param Application $app
54
     * @param Request $request
55
     */
56
    public function index(Application $app, Request $request)
57
    {
58
59
        $pluginForms = array();
60
        $configPages = array();
61
62
        $Plugins = $app['eccube.repository.plugin']->findBy(array(), array('name' => 'ASC'));
63
64
        // ファイル設置プラグインの取得.
65
        $unregisterdPlugins = $this->getUnregisteredPlugins($Plugins, $app);
66
        $unregisterdPluginsConfigPages = array();
67
        foreach ($unregisterdPlugins as $unregisterdPlugin) {
68
            try {
69
                $code = $unregisterdPlugin['code'];
70
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
71
                $unregisterdPluginsConfigPages[$code] = $app->url('plugin_'.$code.'_config');
72
            } catch (RouteNotFoundException $e) {
73
                // プラグインで設定画面のルートが定義されていない場合は無視
74
            }
75
        }
76
77
        $officialPlugins = array();
78
        $unofficialPlugins = array();
79
80
        foreach ($Plugins as $Plugin) {
81
82
            $form = $app['form.factory']
83
                ->createNamedBuilder('form'.$Plugin->getId(), 'plugin_management', null, array(
84
                    'plugin_id' => $Plugin->getId(),
85
                ))
86
                ->getForm();
87
88
            $pluginForms[$Plugin->getId()] = $form->createView();
89
90
            try {
91
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
92
                $configPages[$Plugin->getCode()] = $app->url('plugin_'.$Plugin->getCode().'_config');
93
            } catch (\Exception $e) {
94
                // プラグインで設定画面のルートが定義されていない場合は無視
95
            }
96
97
            if ($Plugin->getSource() == 0) {
98
                // 商品IDが設定されていない場合、非公式プラグイン
99
                $unofficialPlugins[] = $Plugin;
100
            } else {
101
                $officialPlugins[] = $Plugin;
102
            }
103
104
        }
105
106
        // オーナーズストアからダウンロード可能プラグイン情報を取得
107
        $BaseInfo = $app['eccube.repository.base_info']->get();
108
109
        $authKey = $BaseInfo->getAuthenticationKey();
110
111
        if (!is_null($authKey)) {
112
113
            // オーナーズストア通信
114
            $url = $app['config']['owners_store_url'].'?method=list';
115
            list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app);
116
117
            if ($json) {
118
119
                // 接続成功時
120
121
                $data = json_decode($json, true);
122
123
                if (isset($data['success'])) {
124
                    $success = $data['success'];
125
                    if ($success == '1') {
126
127
                        // 既にインストールされているかどうか確認
128
                        foreach ($data['item'] as $item) {
129
                            foreach ($officialPlugins as $plugin) {
130
                                if ($plugin->getSource() == $item['product_id']) {
131
                                    // 商品IDが同一の情報を設定
132
                                    $plugin->setNewVersion($item['version']);
133
                                    $plugin->setLastUpdateDate($item['last_update_date']);
134
                                    $plugin->setProductUrl($item['product_url']);
135
                                    $plugin->setEccubeVersion($item['eccube_version']);
136
137
                                    if ($plugin->getVersion() != $item['version']) {
138
                                        // バージョンが異なる
139
                                        $plugin->setUpdateStatus(3);
140
                                        break;
141
                                    }
142
                                }
143
                            }
144
                        }
145
                    }
146
                }
147
            }
148
        }
149
150
151
        return $app->render('Store/plugin.twig', array(
152
            'plugin_forms' => $pluginForms,
153
            'officialPlugins' => $officialPlugins,
154
            'unofficialPlugins' => $unofficialPlugins,
155
            'configPages' => $configPages,
156
            'unregisterdPlugins' => $unregisterdPlugins,
157
            'unregisterdPluginsConfigPages' => $unregisterdPluginsConfigPages,
158
        ));
159
160
    }
161
162
    /**
163
     * インストール済プラグインからのアップデート
164
     *
165
     * @param Application $app
166
     * @param Request $request
167
     * @param $id
168
     */
169
    public function update(Application $app, Request $request, $id)
170
    {
171
172
        $Plugin = $app['eccube.repository.plugin']->find($id);
173
174
        $form = $app['form.factory']
175
            ->createNamedBuilder('form'.$id, 'plugin_management', null, array(
176
                'plugin_id' => null, // placeHolder
177
            ))
178
            ->getForm();
179
180
        $message = '';
181
182
        if ('POST' === $request->getMethod()) {
183
            $form->handleRequest($request);
184
185
            if ($form->isValid()) {
186
187
                $tmpDir = null;
188
                try {
189
190
                    $formFile = $form['plugin_archive']->getData();
191
192
                    $tmpDir = $app['eccube.service.plugin']->createTempDir();
193
                    $tmpFile = sha1(Str::random(32)).'.'.$formFile->getClientOriginalExtension();
194
195
                    $formFile->move($tmpDir, $tmpFile);
196
                    $app['eccube.service.plugin']->update($Plugin, $tmpDir.'/'.$tmpFile);
197
198
                    $fs = new Filesystem();
199
                    $fs->remove($tmpDir);
200
201
                    $app->addSuccess('admin.plugin.update.complete', 'admin');
202
203
                    Cache::clear($app, false);
0 ignored issues
show
$app is of type object<Eccube\Application>, but the function expects a object<Eccube\Util\Application>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
204
205
                    return $app->redirect($app->url('admin_store_plugin'));
206
207
                } catch (PluginException $e) {
208
                    if (!empty($tmpDir) && file_exists($tmpDir)) {
209
                        $fs = new Filesystem();
210
                        $fs->remove($tmpDir);
211
                    }
212
                    $message = $e->getMessage();
213
                }
214
            } else {
215
                $errors = $form->getErrors(true);
216
                foreach ($errors as $error) {
217
                    $message = $error->getMessage();
218
                }
219
220
            }
221
222
        }
223
224
        $app->addError($message, 'admin');
225
226
        return $app->redirect($app->url('admin_store_plugin'));
227
    }
228
229
230
    /**
231
     * 対象のプラグインを有効にします。
232
     *
233
     * @param Application $app
234
     * @param $id
235
     */
236 View Code Duplication
    public function enable(Application $app, $id)
237
    {
238
        $this->isTokenValid($app);
239
240
        $Plugin = $app['eccube.repository.plugin']->find($id);
241
242
        if (!$Plugin) {
243
            throw new NotFoundHttpException();
244
        }
245
246
        if ($Plugin->getEnable() == Constant::ENABLED) {
247
            $app->addError('admin.plugin.already.enable', 'admin');
248
        } else {
249
            $app['eccube.service.plugin']->enable($Plugin);
250
            $app->addSuccess('admin.plugin.enable.complete', 'admin');
251
        }
252
253
        return $app->redirect($app->url('admin_store_plugin'));
254
    }
255
256
    /**
257
     * 対象のプラグインを無効にします。
258
     *
259
     * @param Application $app
260
     * @param $id
261
     */
262 View Code Duplication
    public function disable(Application $app, $id)
263
    {
264
        $this->isTokenValid($app);
265
266
        $Plugin = $app['eccube.repository.plugin']->find($id);
267
268
        if (!$Plugin) {
269
            throw new NotFoundHttpException();
270
        }
271
272
        if ($Plugin->getEnable() == Constant::ENABLED) {
273
            $app['eccube.service.plugin']->disable($Plugin);
274
            $app->addSuccess('admin.plugin.disable.complete', 'admin');
275
        } else {
276
            $app->addError('admin.plugin.already.disable', 'admin');
277
        }
278
279
        return $app->redirect($app->url('admin_store_plugin'));
280
    }
281
282
283
    /**
284
     * 対象のプラグインを削除します。
285
     *
286
     * @param Application $app
287
     * @param $id
288
     */
289
    public function uninstall(Application $app, $id)
290
    {
291
        $this->isTokenValid($app);
292
293
        $Plugin = $app['eccube.repository.plugin']->find($id);
294
295
        if (!$Plugin) {
296
            $app->deleteMessage();
297
            return $app->redirect($app->url('admin_store_plugin'));
298
        }
299
300
        $app['eccube.service.plugin']->uninstall($Plugin);
301
302
        $app->addSuccess('admin.plugin.uninstall.complete', 'admin');
303
304
        return $app->redirect($app->url('admin_store_plugin'));
305
    }
306
307
    public function handler(Application $app)
308
    {
309
        $handlers = $app['eccube.repository.plugin_event_handler']->getHandlers();
310
311
        // 一次元配列からイベント毎の二次元配列に変換する
312
        $HandlersPerEvent = array();
313
        foreach ($handlers as $handler) {
314
            $HandlersPerEvent[$handler->getEvent()][$handler->getHandlerType()][] = $handler;
315
        }
316
317
        return $app->render('Store/plugin_handler.twig', array(
318
            'handlersPerEvent' => $HandlersPerEvent
319
        ));
320
321
    }
322
323 View Code Duplication
    public function handler_up(Application $app, $handlerId)
324
    {
325
        $repo = $app['eccube.repository.plugin_event_handler'];
326
        $repo->upPriority($repo->find($handlerId));
327
328
        return $app->redirect($app->url('admin_store_plugin_handler'));
329
    }
330
331 View Code Duplication
    public function handler_down(Application $app, $handlerId)
332
    {
333
        $repo = $app['eccube.repository.plugin_event_handler'];
334
        $repo->upPriority($repo->find($handlerId), false);
335
336
        return $app->redirect($app->url('admin_store_plugin_handler'));
337
    }
338
339
    /**
340
     * プラグインファイルアップロード画面
341
     *
342
     * @param Application $app
343
     * @param Request $request
344
     */
345
    public function install(Application $app, Request $request)
346
    {
347
        $form = $app['form.factory']
348
            ->createBuilder('plugin_local_install')
349
            ->getForm();
350
351
        $errors = array();
352
353
        if ('POST' === $request->getMethod()) {
354
            $form->handleRequest($request);
355
356
            if ($form->isValid()) {
357
358
                $tmpDir = null;
359
                try {
360
                    $service = $app['eccube.service.plugin'];
361
362
                    $formFile = $form['plugin_archive']->getData();
363
364
                    $tmpDir = $service->createTempDir();
365
                    $tmpFile = sha1(Str::random(32)).'.'.$formFile->getClientOriginalExtension(); // 拡張子を付けないとpharが動かないので付ける
366
367
                    $formFile->move($tmpDir, $tmpFile);
368
369
                    $service->install($tmpDir.'/'.$tmpFile);
370
371
                    $fs = new Filesystem();
372
                    $fs->remove($tmpDir);
373
374
                    $app->addSuccess('admin.plugin.install.complete', 'admin');
375
376
                    return $app->redirect($app->url('admin_store_plugin'));
377
378
                } catch (PluginException $e) {
379
                    if (!empty($tmpDir) && file_exists($tmpDir)) {
380
                        $fs = new Filesystem();
381
                        $fs->remove($tmpDir);
382
                    }
383
                    $app['monolog']->error("plugin install failed.", array(
384
                        'original-message' => $e->getMessage()
385
                    ));
386
                    $errors[] = $e;
387
                }
388
            } else {
389
                foreach ($form->getErrors(true) as $error) {
390
                    $errors[] = $error;
391
                }
392
            }
393
        }
394
395
        return $app->render('Store/plugin_install.twig', array(
396
            'form' => $form->createView(),
397
            'errors' => $errors,
398
        ));
399
400
    }
401
402
    /**
403
     * オーナーズストアプラグインインストール画面
404
     *
405
     * @param Application $app
406
     * @param Request $request
407
     * @return \Symfony\Component\HttpFoundation\Response
408
     */
409
    public function ownersInstall(Application $app, Request $request)
410
    {
411
        // オーナーズストアからダウンロード可能プラグイン情報を取得
412
        $BaseInfo = $app['eccube.repository.base_info']->get();
413
414
        $authKey = $BaseInfo->getAuthenticationKey();
415
        $authResult = true;
416
        $success = 0;
417
        $items = array();
418
        $promotionItems = array();
419
        $message = '';
420
        if (!is_null($authKey)) {
421
422
            // オーナーズストア通信
423
            $url = $app['config']['owners_store_url'].'?method=list';
424
            list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app);
425
426
            if ($json === false) {
427
                // 接続失敗時
428
                $success = 0;
429
430
                $message = $this->getResponseErrorMessage($info);
431
432
            } else {
433
                // 接続成功時
434
435
                $data = json_decode($json, true);
436
437
                if (isset($data['success'])) {
438
                    $success = $data['success'];
439
                    if ($success == '1') {
440
                        $items = array();
441
442
                        // 既にインストールされているかどうか確認
443
                        $Plugins = $app['eccube.repository.plugin']->findAll();
444
                        $status = false;
445
                        // update_status 1 : 未インストール、2 : インストール済、 3 : 更新あり、4 : 有料購入
446
                        foreach ($data['item'] as $item) {
447
                            foreach ($Plugins as $plugin) {
448
                                if ($plugin->getSource() == $item['product_id']) {
449
                                    if ($plugin->getVersion() == $item['version']) {
450
                                        // バージョンが同じ
451
                                        $item['update_status'] = 2;
452
                                    } else {
453
                                        // バージョンが異なる
454
                                        $item['update_status'] = 3;
455
                                    }
456
                                    $items[] = $item;
457
                                    $status = true;
458
                                    break;
459
                                }
460
                            }
461
                            if (!$status) {
462
                                // 未インストール
463
                                $item['update_status'] = 1;
464
                                $items[] = $item;
465
                            }
466
                            $status = false;
467
                        }
468
469
                        // EC-CUBEのバージョンチェック
470
                        // 参照渡しをして値を追加
471
                        foreach ($items as &$item) {
472
                            if (in_array(Constant::VERSION, $item['eccube_version'])) {
473
                                // 対象バージョン
474
                                $item['version_check'] = 1;
475
                            } else {
476
                                // 未対象バージョン
477
                                $item['version_check'] = 0;
478
                            }
479
                            if ($item['price'] != '0' && $item['purchased'] == '0') {
480
                                // 有料商品で未購入
481
                                $item['update_status'] = 4;
482
                            }
483
                        }
484
                        unset($item);
485
486
                        // promotionアイテム
487
                        $i = 0;
488
                        foreach ($items as $item) {
489
                            if ($item['promotion'] == 1) {
490
                                $promotionItems[] = $item;
491
                                unset($items[$i]);
492
                            }
493
                            $i++;
494
                        }
495
496
                    } else {
497
                        $message = $data['error_code'].' : '.$data['error_message'];
498
                    }
499
                } else {
500
                    $success = 0;
501
                    $message = "EC-CUBEオーナーズストアにエラーが発生しています。";
502
                }
503
            }
504
505
        } else {
506
            $authResult = false;
507
        }
508
509
        return $app->render('Store/plugin_owners_install.twig', array(
510
            'authResult' => $authResult,
511
            'success' => $success,
512
            'items' => $items,
513
            'promotionItems' => $promotionItems,
514
            'message' => $message,
515
        ));
516
517
    }
518
519
    /**
520
     * オーナーズブラグインインストール、アップデート
521
     *
522
     * @param Application $app
523
     * @param Request $request
524
     * @param $action
525
     * @param $id
526
     * @param $version
527
     */
528
    public function upgrade(Application $app, Request $request, $action, $id, $version)
529
    {
530
531
        $BaseInfo = $app['eccube.repository.base_info']->get();
532
533
        $authKey = $BaseInfo->getAuthenticationKey();
534
        $message = '';
535
536
        if (!is_null($authKey)) {
537
538
            // オーナーズストア通信
539
            $url = $app['config']['owners_store_url'].'?method=download&product_id='.$id;
540
            list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app);
541
542
            if ($json === false) {
543
                // 接続失敗時
544
545
                $message = $this->getResponseErrorMessage($info);
546
547
            } else {
548
                // 接続成功時
549
550
                $data = json_decode($json, true);
551
552
                if (isset($data['success'])) {
553
                    $success = $data['success'];
554
                    if ($success == '1') {
555
                        $tmpDir = null;
556
                        try {
557
                            $service = $app['eccube.service.plugin'];
558
559
                            $item = $data['item'];
560
                            $file = base64_decode($item['data']);
561
                            $extension = pathinfo($item['file_name'], PATHINFO_EXTENSION);
562
563
                            $tmpDir = $service->createTempDir();
564
                            $tmpFile = sha1(Str::random(32)).'.'.$extension;
565
566
                            // ファイル作成
567
                            $fs = new Filesystem();
568
                            $fs->dumpFile($tmpDir.'/'.$tmpFile, $file);
569
570
                            if ($action == 'install') {
571
572
                                $service->install($tmpDir.'/'.$tmpFile, $id);
573
                                $app->addSuccess('admin.plugin.install.complete', 'admin');
574
575
                            } else if ($action == 'update') {
576
577
                                $Plugin = $app['eccube.repository.plugin']->findOneBy(array('source' => $id));
578
579
                                $service->update($Plugin, $tmpDir.'/'.$tmpFile);
580
                                $app->addSuccess('admin.plugin.update.complete', 'admin');
581
582
                                Cache::clear($app, false);
0 ignored issues
show
$app is of type object<Eccube\Application>, but the function expects a object<Eccube\Util\Application>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
583
584
                            }
585
586
                            $fs = new Filesystem();
587
                            $fs->remove($tmpDir);
588
589
                            // ダウンロード完了通知処理(正常終了時)
590
                            $url = $app['config']['owners_store_url'].'?method=commit&product_id='.$id.'&status=1&version='.$version;
591
                            $this->getRequestApi($request, $authKey, $url, $app);
592
593
                            return $app->redirect($app->url('admin_store_plugin'));
594
595
                        } catch (PluginException $e) {
596
                            if (!empty($tmpDir) && file_exists($tmpDir)) {
597
                                $fs = new Filesystem();
598
                                $fs->remove($tmpDir);
599
                            }
600
                            $message = $e->getMessage();
601
                        }
602
603
                    } else {
604
                        $message = $data['error_code'].' : '.$data['error_message'];
605
                    }
606
                } else {
607
                    $message = "EC-CUBEオーナーズストアにエラーが発生しています。";
608
                }
609
            }
610
        }
611
612
        // ダウンロード完了通知処理(エラー発生時)
613
        $url = $app['config']['owners_store_url'].'?method=commit&product_id='.$id.'&status=0&version='.$version.'&message='.urlencode($message);
614
        $this->getRequestApi($request, $authKey, $url, $app);
615
616
        $app->addError($message, 'admin');
617
618
        return $app->redirect($app->url('admin_store_plugin_owners_install'));
619
    }
620
621
    /**
622
     * 認証キー設定画面
623
     *
624
     * @param Application $app
625
     * @param Request $request
626
     */
627
    public function authenticationSetting(Application $app, Request $request)
628
    {
629
630
        $form = $app->form()->getForm();
631
632
        $BaseInfo = $app['eccube.repository.base_info']->get();
633
634
        // 認証キーの取得
635
        $form->add(
636
            'authentication_key', 'text', array(
637
            'label' => '認証キー',
638
            'constraints' => array(
639
                new Assert\Regex(array(
640
                    'pattern' => "/^[0-9a-zA-Z]+$/",
641
                )),
642
            ),
643
            'data' => $BaseInfo->getAuthenticationKey(),
644
        ));
645
646
        if ('POST' === $request->getMethod()) {
647
            $form->handleRequest($request);
648
649
            if ($form->isValid()) {
650
                $data = $form->getData();
651
652
                // 認証キーの登録
653
                $BaseInfo->setAuthenticationKey($data['authentication_key']);
654
                $app['orm.em']->flush($BaseInfo);
655
656
                $app->addSuccess('admin.plugin.authentication.setting.complete', 'admin');
657
658
            }
659
        }
660
661
662
        return $app->render('Store/authentication_setting.twig', array(
663
            'form' => $form->createView(),
664
        ));
665
666
    }
667
668
669
    /**
670
     * 認証キーダウンロード
671
     *
672
     * @param Application $app
673
     * @param Request $request
674
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
675
     */
676
    public function download(Application $app, Request $request)
677
    {
678
679
        $this->isTokenValid($app);
680
681
        $url = $app['config']['cacert_pem_url'];
682
683
        $curl = curl_init($url);
684
        $fileName = $app['config']['root_dir'].'/app/config/eccube/'.$this->certFileName;
685
        $fp = fopen($fileName, 'w');
686
        if ($fp === false) {
687
            $app->addError('admin.plugin.download.pem.error', 'admin');
688
            $app->log('Cannot fopen to '.$fileName, array(), Logger::ERROR);
689
            return $app->redirect($app->url('admin_store_authentication_setting'));
690
        }
691
692
        curl_setopt($curl, CURLOPT_FILE, $fp);
693
        curl_setopt($curl, CURLOPT_HEADER, 0);
694
695
        $results = curl_exec($curl);
696
        $error = curl_error($curl);
697
        curl_close($curl);
698
699
        // curl で取得できない場合は file_get_contents で取得を試みる
700
        if ($results === false) {
701
            $file = file_get_contents($url);
702
            if ($file !== false) {
703
                fwrite($fp, $file);
704
            }
705
        }
706
        fclose($fp);
707
708
        $f = new Filesystem();
709
        if ($f->exists($fileName) && filesize($fileName) > 0) {
710
            $app->addSuccess('admin.plugin.download.pem.complete', 'admin');
711
        } else {
712
            $app->addError('admin.plugin.download.pem.error', 'admin');
713
            $app->log('curl_error: '.$error, array(), Logger::ERROR);
714
        }
715
716
        return $app->redirect($app->url('admin_store_authentication_setting'));
717
718
    }
719
720
721
    /**
722
     * APIリクエスト処理
723
     *
724
     * @param Request $request
725
     * @param $authKey
726
     * @param string $url
727
     * @param Application $app
728
     * @return array
729
     */
730
    private function getRequestApi(Request $request, $authKey, $url, $app)
731
    {
732
        $curl = curl_init($url);
733
734
        $options = array(           // オプション配列
735
            //HEADER
736
            CURLOPT_HTTPHEADER => array(
737
                'Authorization: '.base64_encode($authKey),
738
                'x-eccube-store-url: '.base64_encode($request->getSchemeAndHttpHost().$request->getBasePath()),
739
                'x-eccube-store-version: '.base64_encode(Constant::VERSION),
740
            ),
741
            CURLOPT_HTTPGET => true,
742
            CURLOPT_SSL_VERIFYPEER => true,
743
            CURLOPT_RETURNTRANSFER => true,
744
            CURLOPT_FAILONERROR => true,
745
        );
746
747
        curl_setopt_array($curl, $options); /// オプション値を設定
748
749
        $certFile = $app['config']['root_dir'].'/app/config/eccube/'.$this->certFileName;
750
        if (file_exists($certFile)) {
751
            // php5.6でサーバ上に適切な証明書がなければhttps通信エラーが発生するため、
752
            // http://curl.haxx.se/ca/cacert.pem を利用して通信する
753
            curl_setopt($curl, CURLOPT_CAINFO, $certFile);
754
        }
755
756
        $result = curl_exec($curl);
757
        $info = curl_getinfo($curl);
758
759
        $message = curl_error($curl);
760
        $info['message'] = $message;
761
        curl_close($curl);
762
763
        $app->log('http get_info', $info);
764
765
        return array($result, $info);
766
    }
767
768
    /**
769
     * レスポンスのチェック
770
     *
771
     * @param $info
772
     * @return string
773
     */
774
    private function getResponseErrorMessage($info)
775
    {
776
        if (!empty($info)) {
777
            $statusCode = $info['http_code'];
778
            $message = $info['message'];
779
780
            $message = $statusCode.' : '.$message;
781
782
        } else {
783
            $message = "タイムアウトエラーまたはURLの指定に誤りがあります。";
784
        }
785
786
        return $message;
787
    }
788
789
790
    /**
791
     * フォルダ設置のみのプラグインを取得する.
792
     *
793
     * @param array $plugins
794
     * @param Application $app
795
     * @return array
796
     */
797
    protected function getUnregisteredPlugins(array $plugins, \Eccube\Application $app)
798
    {
799
        $finder = new Finder();
800
        $pluginCodes = array();
801
802
        // DB登録済みプラグインコードのみ取得
803
        foreach ($plugins as $key => $plugin) {
804
            $pluginCodes[] = $plugin->getCode();
805
        }
806
        // DB登録済みプラグインコードPluginディレクトリから排他
807
        $dirs = $finder->in($app['config']['plugin_realdir'])->depth(0)->directories();
808
809
        // プラグイン基本チェック
810
        $unregisteredPlugins = array();
811
        foreach ($dirs as $dir) {
812
            $pluginCode = $dir->getBasename();
813
            if (in_array($pluginCode, $pluginCodes, true)) {
814
                continue;
815
            }
816
            try {
817
                $app['eccube.service.plugin']->checkPluginArchiveContent($dir->getRealPath());
818
            } catch (\Eccube\Exception\PluginException $e) {
819
                //config.yamlに不備があった際は全てスキップ
820
                $app['monolog']->warning($e->getMessage());
821
                continue;
822
            }
823
            $config = $app['eccube.service.plugin']->readYml($dir->getRealPath().'/config.yml');
824
            $unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null;
825
            $unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null;
826
            $unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null;
827
            $unregisteredPlugins[$pluginCode]['enable'] = Constant::DISABLED;
828
            $unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null;
829
        }
830
831
        return $unregisteredPlugins;
832
    }
833
}
834