Failed Conditions
Pull Request — master (#1461)
by k-yamamura
92:48 queued 40:30
created

PluginController::handler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
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\HttpFoundation\Request;
35
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
36
use Symfony\Component\Validator\Constraints as Assert;
37
38
class PluginController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
39
{
40
41
    /**
42
     * @var string 証明書ファイル
43
     */
44
    private $certFileName = 'cacert.pem';
45
46
    /**
47
     * インストール済プラグイン画面
48
     *
49
     * @param Application $app
50
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
51
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
52
    public function index(Application $app, Request $request)
53
    {
54
55
        $pluginForms = array();
56
        $configPages = array();
57
58
        $Plugins = $app['eccube.repository.plugin']->findBy(array(), array('name' => 'ASC'));
59
60
        $officialPlugins = array();
61
        $unofficialPlugins = array();
62
63
        foreach ($Plugins as $Plugin) {
64
65
            $form = $app['form.factory']
66
                ->createNamedBuilder('form' . $Plugin->getId(), 'plugin_management', null, array(
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
67
                    'plugin_id' => $Plugin->getId(),
68
                ))
69
                ->getForm();
70
71
            $pluginForms[$Plugin->getId()] = $form->createView();
72
73
            try {
74
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
75
                $configPages[$Plugin->getCode()] = $app->url('plugin_' . $Plugin->getCode() . '_config');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
76
            } catch (\Exception $e) {
77
                // プラグインで設定画面のルートが定義されていない場合は無視
78
            }
79
80
            if ($Plugin->getSource() == 0) {
81
                // 商品IDが設定されていない場合、非公式プラグイン
82
                $unofficialPlugins[] = $Plugin;
83
            } else {
84
                $officialPlugins[] = $Plugin;
85
            }
86
87
        }
88
89
        // オーナーズストアからダウンロード可能プラグイン情報を取得
90
        $BaseInfo = $app['eccube.repository.base_info']->get();
91
92
        $authKey = $BaseInfo->getAuthenticationKey();
93
94
        if (!is_null($authKey)) {
95
96
            // オーナーズストア通信
97
            $url = $app['config']['owners_store_url'] . '?method=list';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
98
            list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app);
0 ignored issues
show
Unused Code introduced by
The assignment to $info is unused. Consider omitting it like so list($first,,$third).

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

Consider the following code example.

<?php

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

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

print $a . " - " . $c;

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

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
99
100
            if ($json) {
101
102
                // 接続成功時
103
104
                $data = json_decode($json, true);
105
106
                if (isset($data['success'])) {
107
                    $success = $data['success'];
108
                    if ($success == '1') {
109
110
                        // 既にインストールされているかどうか確認
111
                        foreach ($data['item'] as $item) {
112
                            foreach ($officialPlugins as $plugin) {
113
                                if ($plugin->getSource() == $item['product_id']) {
114
                                    // 商品IDが同一の情報を設定
115
                                    $plugin->setNewVersion($item['version']);
116
                                    $plugin->setLastUpdateDate($item['last_update_date']);
117
                                    $plugin->setProductUrl($item['product_url']);
118
119
                                    if ($plugin->getVersion() != $item['version']) {
120
                                        // バージョンが異なる
121
                                        if (in_array(Constant::VERSION, $item['eccube_version'])) {
122
                                            // 対象バージョン
123
                                            $plugin->setUpdateStatus(3);
124
                                            break;
125
                                        }
126
                                    }
127
                                }
128
                            }
129
                        }
130
                    }
131
                }
132
            }
133
        }
134
135
136
        return $app->render('Store/plugin.twig', array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
137
            'plugin_forms' => $pluginForms,
138
            'officialPlugins' => $officialPlugins,
139
            'unofficialPlugins' => $unofficialPlugins,
140
            'configPages' => $configPages
141
        ));
142
143
    }
144
145
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
146
     * インストール済プラグインからのアップデート
147
     *
148
     * @param Application $app
149
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
150
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
151
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
152
    public function update(Application $app, Request $request, $id)
153
    {
154
155
        $Plugin = $app['eccube.repository.plugin']->find($id);
156
157
        $form = $app['form.factory']
158
            ->createNamedBuilder('form' . $id, 'plugin_management', null, array(
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
159
                'plugin_id' => null, // placeHolder
160
            ))
161
            ->getForm();
162
163
        $message = '';
164
165
        if ('POST' === $request->getMethod()) {
166
            $form->handleRequest($request);
167
168
            if ($form->isValid()) {
169
170
                $tmpDir = null;
171
                try {
172
173
                    $formFile = $form['plugin_archive']->getData();
174
175
                    $tmpDir = $app['eccube.service.plugin']->createTempDir();
176
                    $tmpFile = sha1(Str::random(32)) . '.' . $formFile->getClientOriginalExtension();
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
177
178
                    $formFile->move($tmpDir, $tmpFile);
179
                    $app['eccube.service.plugin']->update($Plugin, $tmpDir . '/' . $tmpFile);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
180
181
                    $fs = new Filesystem();
182
                    $fs->remove($tmpDir);
183
184
                    $app->addSuccess('admin.plugin.update.complete', 'admin');
185
186
                    Cache::clear($app, false);
0 ignored issues
show
Documentation introduced by
$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...
187
188
                    return $app->redirect($app->url('admin_store_plugin'));
189
190
                } catch (PluginException $e) {
191
                    if (!empty($tmpDir) && file_exists($tmpDir)) {
192
                        $fs = new Filesystem();
193
                        $fs->remove($tmpDir);
194
                    }
195
                    $message = $e->getMessage();
196
                }
197
            } else {
198
                $errors = $form->getErrors(true);
199
                foreach ($errors as $error) {
200
                    $message = $error->getMessage();
201
                }
202
203
            }
204
205
        }
206
207
        $app->addError($message, 'admin');
208
209
        return $app->redirect($app->url('admin_store_plugin'));
210
    }
211
212
213
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
214
     * 対象のプラグインを有効にします。
215
     *
216
     * @param Application $app
217
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
218
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
219 View Code Duplication
    public function enable(Application $app, $id)
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...
220
    {
221
        $this->isTokenValid($app);
222
223
        $Plugin = $app['eccube.repository.plugin']->find($id);
224
225
        if (!$Plugin) {
226
            throw new NotFoundHttpException();
227
        }
228
229
        if ($Plugin->getEnable() == Constant::ENABLED) {
230
            $app->addError('admin.plugin.already.enable', 'admin');
231
        } else {
232
            $app['eccube.service.plugin']->enable($Plugin);
233
            $app->addSuccess('admin.plugin.enable.complete', 'admin');
234
        }
235
236
        return $app->redirect($app->url('admin_store_plugin'));
237
    }
238
239
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
240
     * 対象のプラグインを無効にします。
241
     *
242
     * @param Application $app
243
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
244
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
245 View Code Duplication
    public function disable(Application $app, $id)
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...
246
    {
247
        $this->isTokenValid($app);
248
249
        $Plugin = $app['eccube.repository.plugin']->find($id);
250
251
        if (!$Plugin) {
252
            throw new NotFoundHttpException();
253
        }
254
255
        if ($Plugin->getEnable() == Constant::ENABLED) {
256
            $app['eccube.service.plugin']->disable($Plugin);
257
            $app->addSuccess('admin.plugin.disable.complete', 'admin');
258
        } else {
259
            $app->addError('admin.plugin.already.disable', 'admin');
260
        }
261
262
        return $app->redirect($app->url('admin_store_plugin'));
263
    }
264
265
266
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
267
     * 対象のプラグインを削除します。
268
     *
269
     * @param Application $app
270
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
271
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
272 View Code Duplication
    public function uninstall(Application $app, $id)
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...
273
    {
274
        $this->isTokenValid($app);
275
276
        $Plugin = $app['eccube.repository.plugin']->find($id);
277
278
        if (!$Plugin) {
279
            $app->deleteMessage();
280
            return $app->redirect($app->url('admin_store_plugin'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
281
        }
282
283
        $app['eccube.service.plugin']->uninstall($Plugin);
284
285
        $app->addSuccess('admin.plugin.uninstall.complete', 'admin');
286
287
        return $app->redirect($app->url('admin_store_plugin'));
288
    }
289
290
    public function handler(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
291
    {
292
        $handlers = $app['eccube.repository.plugin_event_handler']->getHandlers();
293
294
        // 一次元配列からイベント毎の二次元配列に変換する
295
        $HandlersPerEvent = array();
296
        foreach ($handlers as $handler) {
297
            $HandlersPerEvent[$handler->getEvent()][$handler->getHandlerType()][] = $handler;
298
        }
299
300
        return $app->render('Store/plugin_handler.twig', array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
301
            'handlersPerEvent' => $HandlersPerEvent
302
        ));
303
304
    }
305
306 View Code Duplication
    public function handler_up(Application $app, $handlerId)
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...
introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Method name "PluginController::handler_up" is not in camel caps format
Loading history...
307
    {
308
        $repo = $app['eccube.repository.plugin_event_handler'];
309
        $repo->upPriority($repo->find($handlerId));
310
311
        return $app->redirect($app->url('admin_store_plugin_handler'));
312
    }
313
314 View Code Duplication
    public function handler_down(Application $app, $handlerId)
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...
introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Method name "PluginController::handler_down" is not in camel caps format
Loading history...
315
    {
316
        $repo = $app['eccube.repository.plugin_event_handler'];
317
        $repo->upPriority($repo->find($handlerId), false);
318
319
        return $app->redirect($app->url('admin_store_plugin_handler'));
320
    }
321
322
    /**
323
     * プラグインファイルアップロード画面
324
     *
325
     * @param Application $app
326
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
327
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
328
    public function install(Application $app, Request $request)
329
    {
330
        $form = $app['form.factory']
331
            ->createBuilder('plugin_local_install')
332
            ->getForm();
333
334
        $errors = array();
335
336
        if ('POST' === $request->getMethod()) {
337
            $form->handleRequest($request);
338
339
            if ($form->isValid()) {
340
341
                $tmpDir = null;
342
                try {
343
                    $service = $app['eccube.service.plugin'];
344
345
                    $formFile = $form['plugin_archive']->getData();
346
347
                    $tmpDir = $service->createTempDir();
348
                    $tmpFile = sha1(Str::random(32)) . '.' . $formFile->getClientOriginalExtension(); // 拡張子を付けないとpharが動かないので付ける
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
349
350
                    $formFile->move($tmpDir, $tmpFile);
351
352
                    $service->install($tmpDir . '/' . $tmpFile);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
353
354
                    $fs = new Filesystem();
355
                    $fs->remove($tmpDir);
356
357
                    $app->addSuccess('admin.plugin.install.complete', 'admin');
358
359
                    return $app->redirect($app->url('admin_store_plugin'));
360
361
                } catch (PluginException $e) {
362
                    if (!empty($tmpDir) && file_exists($tmpDir)) {
363
                        $fs = new Filesystem();
364
                        $fs->remove($tmpDir);
365
                    }
366
                    $errors[] = $e;
367
                }
368
            }
369
        }
370
371
        return $app->render('Store/plugin_install.twig', array(
372
            'form' => $form->createView(),
373
            'errors' => $errors,
374
        ));
375
376
    }
377
378
    /**
379
     * オーナーズストアプラグインインストール画面
380
     *
381
     * @param Application $app
382
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
383
     * @return \Symfony\Component\HttpFoundation\Response
384
     */
385
    public function ownersInstall(Application $app, Request $request)
386
    {
387
        // オーナーズストアからダウンロード可能プラグイン情報を取得
388
        $BaseInfo = $app['eccube.repository.base_info']->get();
389
390
        $authKey = $BaseInfo->getAuthenticationKey();
391
        $authResult = true;
392
        $success = 0;
393
        $items = array();
394
        $promotionItems = array();
395
        $message = '';
396
        if (!is_null($authKey)) {
397
398
            // オーナーズストア通信
399
            $url = $app['config']['owners_store_url'] . '?method=list';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
400
            list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app);
401
402
            if ($json === false) {
403
                // 接続失敗時
404
                $success = 0;
405
406
                $message = $this->getResponseErrorMessage($info);
407
408
            } else {
409
                // 接続成功時
410
411
                $data = json_decode($json, true);
412
413
                if (isset($data['success'])) {
414
                    $success = $data['success'];
415
                    if ($success == '1') {
416
                        $items = array();
417
418
                        // 既にインストールされているかどうか確認
419
                        $Plugins = $app['eccube.repository.plugin']->findAll();
420
                        $status = false;
421
                        // update_status 1 : 未インストール、2 : インストール済、 3 : 更新あり、4 : 有料購入
422
                        foreach ($data['item'] as $item) {
423
                            foreach ($Plugins as $plugin) {
424
                                if ($plugin->getSource() == $item['product_id']) {
425
                                    if ($plugin->getVersion() == $item['version']) {
426
                                        // バージョンが同じ
427
                                        $item['update_status'] = 2;
428
                                    } else {
429
                                        // バージョンが異なる
430
                                        $item['update_status'] = 3;
431
                                    }
432
                                    $items[] = $item;
433
                                    $status = true;
434
                                    break;
435
                                }
436
                            }
437
                            if (!$status) {
438
                                // 未インストール
439
                                $item['update_status'] = 1;
440
                                $items[] = $item;
441
                            }
442
                            $status = false;
443
                        }
444
445
                        // EC-CUBEのバージョンチェック
446
                        // 参照渡しをして値を追加
447
                        foreach ($items as &$item) {
448
                            if (in_array(Constant::VERSION, $item['eccube_version'])) {
449
                                // 対象バージョン
450
                                $item['version_check'] = 1;
451
                            } else {
452
                                // 未対象バージョン
453
                                $item['version_check'] = 0;
454
                            }
455
                            if ($item['price'] != '0' && $item['purchased'] == '0') {
456
                                // 有料商品で未購入
457
                                $item['update_status'] = 4;
458
                            }
459
                        }
460
                        unset($item);
461
462
                        // promotionアイテム
463
                        $i = 0;
464
                        foreach ($items as $item) {
465
                            if ($item['promotion'] == 1) {
466
                                $promotionItems[] = $item;
467
                                unset($items[$i]);
468
                            }
469
                            $i++;
470
                        }
471
472
                    } else {
473
                        $message = $data['error_code'] . ' : ' . $data['error_message'];
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
474
                    }
475
                } else {
476
                    $success = 0;
477
                    $message = "EC-CUBEオーナーズストアにエラーが発生しています。";
478
                }
479
            }
480
481
        } else {
482
            $authResult = false;
483
        }
484
485
        return $app->render('Store/plugin_owners_install.twig', array(
486
            'authResult' => $authResult,
487
            'success' => $success,
488
            'items' => $items,
489
            'promotionItems' => $promotionItems,
490
            'message' => $message,
491
        ));
492
493
    }
494
495
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$action" missing
Loading history...
introduced by
Doc comment for parameter "$version" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
496
     * オーナーズブラグインインストール、アップデート
497
     *
498
     * @param Application $app
499
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
500
     * @param $action
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
501
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
502
     * @param $version
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
503
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
504
    public function upgrade(Application $app, Request $request, $action, $id, $version)
505
    {
506
507
        $BaseInfo = $app['eccube.repository.base_info']->get();
508
509
        $authKey = $BaseInfo->getAuthenticationKey();
510
        $message = '';
511
512
        if (!is_null($authKey)) {
513
514
            // オーナーズストア通信
515
            $url = $app['config']['owners_store_url'] . '?method=download&product_id=' . $id;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
516
            list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app);
517
518
            if ($json === false) {
519
                // 接続失敗時
520
521
                $message = $this->getResponseErrorMessage($info);
522
523
            } else {
524
                // 接続成功時
525
526
                $data = json_decode($json, true);
527
528
                if (isset($data['success'])) {
529
                    $success = $data['success'];
530
                    if ($success == '1') {
531
                        $tmpDir = null;
532
                        try {
533
                            $service = $app['eccube.service.plugin'];
534
535
                            $item = $data['item'];
536
                            $file = base64_decode($item['data']);
537
                            $extension = pathinfo($item['file_name'], PATHINFO_EXTENSION);
538
539
                            $tmpDir = $service->createTempDir();
540
                            $tmpFile = sha1(Str::random(32)) . '.' . $extension;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
541
542
                            // ファイル作成
543
                            $fs = new Filesystem();
544
                            $fs->dumpFile($tmpDir . '/' . $tmpFile, $file);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
545
546
                            if ($action == 'install') {
547
548
                                $service->install($tmpDir . '/' . $tmpFile, $id);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
549
                                $app->addSuccess('admin.plugin.install.complete', 'admin');
550
551
                            } else if ($action == 'update') {
552
553
                                $Plugin = $app['eccube.repository.plugin']->findOneBy(array('source' => $id));
554
555
                                $service->update($Plugin, $tmpDir . '/' . $tmpFile);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
556
                                $app->addSuccess('admin.plugin.update.complete', 'admin');
557
558
                                Cache::clear($app, false);
0 ignored issues
show
Documentation introduced by
$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...
559
560
                            }
561
562
                            $fs = new Filesystem();
563
                            $fs->remove($tmpDir);
564
565
                            // ダウンロード完了通知処理(正常終了時)
566
                            $url = $app['config']['owners_store_url'] . '?method=commit&product_id=' . $id . '&status=1&version=' . $version;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
567
                            $this->getRequestApi($request, $authKey, $url, $app);
568
569
                            return $app->redirect($app->url('admin_store_plugin'));
570
571
                        } catch (PluginException $e) {
572
                            if (!empty($tmpDir) && file_exists($tmpDir)) {
573
                                $fs = new Filesystem();
574
                                $fs->remove($tmpDir);
575
                            }
576
                            $message = $e->getMessage();
577
                        }
578
579
                    } else {
580
                        $message = $data['error_code'] . ' : ' . $data['error_message'];
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
581
                    }
582
                } else {
583
                    $message = "EC-CUBEオーナーズストアにエラーが発生しています。";
584
                }
585
            }
586
        }
587
588
        // ダウンロード完了通知処理(エラー発生時)
589
        $url = $app['config']['owners_store_url'] . '?method=commit&product_id=' . $id . '&status=0&version=' . $version . '&message=' . urlencode($message);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
590
        $this->getRequestApi($request, $authKey, $url, $app);
591
592
        $app->addError($message, 'admin');
593
594
        return $app->redirect($app->url('admin_store_plugin_owners_install'));
595
    }
596
597
    /**
598
     * 認証キー設定画面
599
     *
600
     * @param Application $app
601
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
602
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
603
    public function authenticationSetting(Application $app, Request $request)
604
    {
605
606
        $form = $app->form()->getForm();
607
608
        $BaseInfo = $app['eccube.repository.base_info']->get();
609
610
        // 認証キーの取得
611
        $form->add(
612
            'authentication_key', 'text', array(
613
            'label' => '認証キー',
614
            'constraints' => array(
615
                new Assert\Regex(array(
616
                    'pattern' => "/^[0-9a-zA-Z]+$/",
617
                )),
618
            ),
619
            'data' => $BaseInfo->getAuthenticationKey(),
620
        ));
1 ignored issue
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 12 spaces, but found 8).
Loading history...
621
622
        if ('POST' === $request->getMethod()) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 8
Loading history...
623
            $form->handleRequest($request);
1 ignored issue
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 16 spaces, but found 12).
Loading history...
624
625
            if ($form->isValid()) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 12
Loading history...
626
                $data = $form->getData();
1 ignored issue
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 20 spaces, but found 16).
Loading history...
627
628
                // 認証キーの登録
629
                $BaseInfo->setAuthenticationKey($data['authentication_key']);
1 ignored issue
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 20 spaces, but found 16).
Loading history...
630
                $app['orm.em']->flush($BaseInfo);
1 ignored issue
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 20 spaces, but found 16).
Loading history...
631
632
                $app->addSuccess('admin.plugin.authentication.setting.complete', 'admin');
1 ignored issue
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 20 spaces, but found 16).
Loading history...
633
634
            }
635
        }
636
637
638
        return $app->render('Store/authentication_setting.twig', array(
639
            'form' => $form->createView(),
640
        ));
641
642
    }
643
644
645
    /**
646
     * 認証キーダウンロード
647
     *
648
     * @param Application $app
649
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
650
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
651
     */
652
    public function download(Application $app, Request $request)
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...
653
    {
654
        $url = $app['config']['cacert_pem_url'];
655
656
        $curl = curl_init($url);
657
        $fileName = $app['config']['root_dir'] . '/app/config/eccube/' . $this->certFileName;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
658
        $fp = fopen($fileName, 'w');
659
660
        curl_setopt($curl, CURLOPT_FILE, $fp);
661
        curl_setopt($curl, CURLOPT_HEADER, 0);
662
663
        curl_exec($curl);
664
        curl_close($curl);
665
        fclose($fp);
666
667
        $f = new Filesystem();
668
        if (!$f->exists($fileName)) {
669
            $app->addSuccess('admin.plugin.download.pem.complete', 'admin');
670
        } else {
671
            $app->addError('admin.plugin.download.pem.error', 'admin');
672
        }
673
674
        return $app->redirect($app->url('admin_store_authentication_setting'));
675
676
    }
677
678
679
    /**
680
     * APIリクエスト処理
681
     *
682
     * @param Request $request
683
     * @param $authKey
684
     * @param $url
685
     * @param $app
686
     * @return array
687
     */
688
    private function getRequestApi(Request $request, $authKey, $url, $app)
689
    {
690
        $curl = curl_init($url);
691
692
        $options = array(           // オプション配列
693
            //HEADER
694
            CURLOPT_HTTPHEADER => array(
695
                'Authorization: ' . base64_encode($authKey),
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
696
                'x-eccube-store-url: ' . base64_encode($request->getSchemeAndHttpHost() . $request->getBasePath()),
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
697
                'x-eccube-store-version: ' . base64_encode(Constant::VERSION),
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
698
            ),
699
            CURLOPT_HTTPGET => true,
700
            CURLOPT_SSL_VERIFYPEER => true,
701
            CURLOPT_RETURNTRANSFER => true,
702
            CURLOPT_FAILONERROR => true,
703
        );
704
705
        curl_setopt_array($curl, $options); /// オプション値を設定
706
707
        $certFile = $app['config']['root_dir'] . '/app/config/eccube/'. $this->certFileName;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
708
        if (file_exists($certFile)) {
709
            // php5.6でサーバ上に適切な証明書がなければhttps通信エラーが発生するため、
710
            // http://curl.haxx.se/ca/cacert.pem を利用して通信する
711
            curl_setopt($curl, CURLOPT_CAINFO, $certFile);
712
        }
713
714
        $result = curl_exec($curl);
715
        $info = curl_getinfo($curl);
716
717
        $message = curl_error($curl);
718
        $info['message'] = $message;
719
        curl_close($curl);
720
721
        $app->log('http get_info', $info);
722
723
        return array($result, $info);
724
    }
725
726
    /**
727
     * レスポンスのチェック
728
     *
729
     * @param $info
730
     * @return string
731
     */
732
    private function getResponseErrorMessage($info)
733
    {
734
        if (!empty($info)) {
735
            $statusCode = $info['http_code'];
736
            $message = $info['message'];
737
738
            $message = $statusCode.' : '.$message;
739
740
        } else {
741
            $message = "タイムアウトエラーまたはURLの指定に誤りがあります。";
742
        }
743
744
        return $message;
745
    }
746
747
}
748