Failed Conditions
Push — master ( 315ac9...8087c2 )
by k-yamamura
592:05 queued 586:03
created

PluginController::getResponseErrorMessage()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 22
rs 8.9197
cc 4
eloc 16
nc 4
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\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
40
class PluginController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
41
{
42
43
    /**
44
     * インストール済プラグイン画面
45
     *
46
     * @param Application $app
47
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
48
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
49
    public function index(Application $app, Request $request)
50
    {
51
52
        $pluginForms = array();
53
        $configPages = array();
54
55
        $Plugins = $app['eccube.repository.plugin']->findBy(array(), array('name' => 'ASC'));
56
57
        // ファイル設置プラグインの取得.
58
        $unregisterdPlugins = $this->getUnregisteredPlugins($Plugins, $app);
59
        $unregisterdPluginsConfigPages = array();
60
        foreach ($unregisterdPlugins as $unregisterdPlugin) {
61
            try {
62
                $code = $unregisterdPlugin['code'];
63
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
64
                $unregisterdPluginsConfigPages[$code] = $app->url('plugin_'.$code.'_config');
65
            } catch (RouteNotFoundException $e) {
66
                // プラグインで設定画面のルートが定義されていない場合は無視
67
            }
68
        }
69
70
        $officialPlugins = array();
71
        $unofficialPlugins = array();
72
73
        foreach ($Plugins as $Plugin) {
74
75
            $form = $app['form.factory']
76
                ->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...
77
                    'plugin_id' => $Plugin->getId(),
78
                ))
79
                ->getForm();
80
81
            $pluginForms[$Plugin->getId()] = $form->createView();
82
83
            try {
84
                // プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか)
85
                $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...
86
            } catch (\Exception $e) {
87
                // プラグインで設定画面のルートが定義されていない場合は無視
88
            }
89
90
            if ($Plugin->getSource() == 0) {
91
                // 商品IDが設定されていない場合、非公式プラグイン
92
                $unofficialPlugins[] = $Plugin;
93
            } else {
94
                $officialPlugins[] = $Plugin;
95
            }
96
97
        }
98
99
        // オーナーズストアからダウンロード可能プラグイン情報を取得
100
        $BaseInfo = $app['eccube.repository.base_info']->get();
101
102
        $authKey = $BaseInfo->getAuthenticationKey();
103
104
        if (!is_null($authKey)) {
105
106
            // オーナーズストア通信
107
            $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...
108
            list($json, $httpHeader) = $this->getRequestApi($request, $authKey, $url);
0 ignored issues
show
Unused Code introduced by
The assignment to $httpHeader 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...
109
110
            if ($json) {
111
112
                // 接続成功時
113
114
                $data = json_decode($json, true);
115
116
                if (isset($data['success'])) {
117
                    $success = $data['success'];
118
                    if ($success == '1') {
119
120
                        // 既にインストールされているかどうか確認
121
                        foreach ($data['item'] as $item) {
122
                            foreach ($officialPlugins as $plugin) {
123
                                if ($plugin->getSource() == $item['product_id']) {
124
                                    // 商品IDが同一の情報を設定
125
                                    $plugin->setNewVersion($item['version']);
126
                                    $plugin->setLastUpdateDate($item['last_update_date']);
127
                                    $plugin->setProductUrl($item['product_url']);
128
129
                                    if ($plugin->getVersion() != $item['version']) {
130
                                        // バージョンが異なる
131
                                        if (in_array(Constant::VERSION, $item['eccube_version'])) {
132
                                            // 対象バージョン
133
                                            $plugin->setUpdateStatus(3);
134
                                            break;
135
                                        }
136
                                    }
137
                                }
138
                            }
139
                        }
140
                    }
141
                }
142
            }
143
        }
144
145
146
        return $app->render('Store/plugin.twig', array(
147
            'plugin_forms' => $pluginForms,
148
            'officialPlugins' => $officialPlugins,
149
            'unofficialPlugins' => $unofficialPlugins,
150
            'configPages' => $configPages,
151
            'unregisterdPlugins' => $unregisterdPlugins,
152
            'unregisterdPluginsConfigPages' => $unregisterdPluginsConfigPages,
153
        ));
154
155
    }
156
157
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
158
     * インストール済プラグインからのアップデート
159
     *
160
     * @param Application $app
161
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
162
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
163
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
164
    public function update(Application $app, Request $request, $id)
165
    {
166
167
        $Plugin = $app['eccube.repository.plugin']->find($id);
168
169
        $form = $app['form.factory']
170
            ->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...
171
                'plugin_id' => null, // placeHolder
172
            ))
173
            ->getForm();
174
175
        $message = '';
176
177
        if ('POST' === $request->getMethod()) {
178
            $form->handleRequest($request);
179
180
            if ($form->isValid()) {
181
182
                $tmpDir = null;
183
                try {
184
185
                    $formFile = $form['plugin_archive']->getData();
186
187
                    $tmpDir = $app['eccube.service.plugin']->createTempDir();
188
                    $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...
189
190
                    $formFile->move($tmpDir, $tmpFile);
191
                    $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...
192
193
                    $fs = new Filesystem();
194
                    $fs->remove($tmpDir);
195
196
                    $app->addSuccess('admin.plugin.update.complete', 'admin');
197
198
                    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...
199
200
                    return $app->redirect($app->url('admin_store_plugin'));
201
202
                } catch (PluginException $e) {
203
                    if (!empty($tmpDir) && file_exists($tmpDir)) {
204
                        $fs = new Filesystem();
205
                        $fs->remove($tmpDir);
206
                    }
207
                    $message = $e->getMessage();
208
                }
209
            } else {
210
                $errors = $form->getErrors(true);
211
                foreach ($errors as $error) {
212
                    $message = $error->getMessage();
213
                }
214
215
            }
216
217
        }
218
219
        $app->addError($message, 'admin');
220
221
        return $app->redirect($app->url('admin_store_plugin'));
222
    }
223
224
225
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
226
     * 対象のプラグインを有効にします。
227
     *
228
     * @param Application $app
229
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
230
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
231 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...
232
    {
233
        $this->isTokenValid($app);
234
235
        $Plugin = $app['eccube.repository.plugin']->find($id);
236
237
        if (!$Plugin) {
238
            throw new NotFoundHttpException();
239
        }
240
241
        if ($Plugin->getEnable() == Constant::ENABLED) {
242
            $app->addError('admin.plugin.already.enable', 'admin');
243
        } else {
244
            $app['eccube.service.plugin']->enable($Plugin);
245
            $app->addSuccess('admin.plugin.enable.complete', 'admin');
246
        }
247
248
        return $app->redirect($app->url('admin_store_plugin'));
249
    }
250
251
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
252
     * 対象のプラグインを無効にします。
253
     *
254
     * @param Application $app
255
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
256
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
257 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...
258
    {
259
        $this->isTokenValid($app);
260
261
        $Plugin = $app['eccube.repository.plugin']->find($id);
262
263
        if (!$Plugin) {
264
            throw new NotFoundHttpException();
265
        }
266
267
        if ($Plugin->getEnable() == Constant::ENABLED) {
268
            $app['eccube.service.plugin']->disable($Plugin);
269
            $app->addSuccess('admin.plugin.disable.complete', 'admin');
270
        } else {
271
            $app->addError('admin.plugin.already.disable', 'admin');
272
        }
273
274
        return $app->redirect($app->url('admin_store_plugin'));
275
    }
276
277
278
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
279
     * 対象のプラグインを削除します。
280
     *
281
     * @param Application $app
282
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
283
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
284 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...
285
    {
286
        $this->isTokenValid($app);
287
288
        $Plugin = $app['eccube.repository.plugin']->find($id);
289
290
        if (!$Plugin) {
291
            $app->deleteMessage();
292
            return $app->redirect($app->url('admin_store_plugin'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
293
        }
294
295
        $app['eccube.service.plugin']->uninstall($Plugin);
296
297
        $app->addSuccess('admin.plugin.uninstall.complete', 'admin');
298
299
        return $app->redirect($app->url('admin_store_plugin'));
300
    }
301
302
    public function handler(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
303
    {
304
        $handlers = $app['eccube.repository.plugin_event_handler']->getHandlers();
305
306
        // 一次元配列からイベント毎の二次元配列に変換する
307
        $HandlersPerEvent = array();
308
        foreach ($handlers as $handler) {
309
            $HandlersPerEvent[$handler->getEvent()][$handler->getHandlerType()][] = $handler;
310
        }
311
312
        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...
313
            'handlersPerEvent' => $HandlersPerEvent
314
        ));
315
316
    }
317
318 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...
319
    {
320
        $repo = $app['eccube.repository.plugin_event_handler'];
321
        $repo->upPriority($repo->find($handlerId));
322
323
        return $app->redirect($app->url('admin_store_plugin_handler'));
324
    }
325
326 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...
327
    {
328
        $repo = $app['eccube.repository.plugin_event_handler'];
329
        $repo->upPriority($repo->find($handlerId), false);
330
331
        return $app->redirect($app->url('admin_store_plugin_handler'));
332
    }
333
334
    /**
335
     * プラグインファイルアップロード画面
336
     *
337
     * @param Application $app
338
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
339
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
340
    public function install(Application $app, Request $request)
341
    {
342
        $form = $app['form.factory']
343
            ->createBuilder('plugin_local_install')
344
            ->getForm();
345
346
        $errors = array();
347
348
        if ('POST' === $request->getMethod()) {
349
            $form->handleRequest($request);
350
351
            if ($form->isValid()) {
352
353
                $tmpDir = null;
354
                try {
355
                    $service = $app['eccube.service.plugin'];
356
357
                    $formFile = $form['plugin_archive']->getData();
358
359
                    $tmpDir = $service->createTempDir();
360
                    $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...
361
362
                    $formFile->move($tmpDir, $tmpFile);
363
364
                    $service->install($tmpDir . '/' . $tmpFile);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
365
366
                    $fs = new Filesystem();
367
                    $fs->remove($tmpDir);
368
369
                    $app->addSuccess('admin.plugin.install.complete', 'admin');
370
371
                    return $app->redirect($app->url('admin_store_plugin'));
372
373
                } catch (PluginException $e) {
374
                    if (!empty($tmpDir) && file_exists($tmpDir)) {
375
                        $fs = new Filesystem();
376
                        $fs->remove($tmpDir);
377
                    }
378
                    $app['monolog']->error("plugin install failed.", array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
379
                        'original-message' => $e->getMessage()
380
                    ));
381
                    $errors[] = $e;
382
                }
383
            }
384
        }
385
386
        return $app->render('Store/plugin_install.twig', array(
387
            'form' => $form->createView(),
388
            'errors' => $errors,
389
        ));
390
391
    }
392
393
    /**
394
     * オーナーズストアプラグインインストール画面
395
     *
396
     * @param Application $app
397
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
398
     * @return \Symfony\Component\HttpFoundation\Response
399
     */
400
    public function ownersInstall(Application $app, Request $request)
401
    {
402
        // オーナーズストアからダウンロード可能プラグイン情報を取得
403
        $BaseInfo = $app['eccube.repository.base_info']->get();
404
405
        $authKey = $BaseInfo->getAuthenticationKey();
406
        $authResult = true;
407
        $success = 0;
408
        $items = array();
409
        $promotionItems = array();
410
        $message = '';
411
        if (!is_null($authKey)) {
412
413
            // オーナーズストア通信
414
            $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...
415
            list($json, $httpHeader) = $this->getRequestApi($request, $authKey, $url);
416
417
            if ($json === false) {
418
                // 接続失敗時
419
                $success = 0;
420
421
                $message = $this->getResponseErrorMessage($httpHeader);
422
423
            } else {
424
                // 接続成功時
425
426
                $data = json_decode($json, true);
427
428
                if (isset($data['success'])) {
429
                    $success = $data['success'];
430
                    if ($success == '1') {
431
                        $items = array();
432
433
                        // 既にインストールされているかどうか確認
434
                        $Plugins = $app['eccube.repository.plugin']->findAll();
435
                        $status = false;
436
                        // update_status 1 : 未インストール、2 : インストール済、 3 : 更新あり、4 : 有料購入
437
                        foreach ($data['item'] as $item) {
438
                            foreach ($Plugins as $plugin) {
439
                                if ($plugin->getSource() == $item['product_id']) {
440
                                    if ($plugin->getVersion() == $item['version']) {
441
                                        // バージョンが同じ
442
                                        $item['update_status'] = 2;
443
                                    } else {
444
                                        // バージョンが異なる
445
                                        $item['update_status'] = 3;
446
                                    }
447
                                    $items[] = $item;
448
                                    $status = true;
449
                                    break;
450
                                }
451
                            }
452
                            if (!$status) {
453
                                // 未インストール
454
                                $item['update_status'] = 1;
455
                                $items[] = $item;
456
                            }
457
                            $status = false;
458
                        }
459
460
                        // EC-CUBEのバージョンチェック
461
                        // 参照渡しをして値を追加
462
                        foreach ($items as &$item) {
463
                            if (in_array(Constant::VERSION, $item['eccube_version'])) {
464
                                // 対象バージョン
465
                                $item['version_check'] = 1;
466
                            } else {
467
                                // 未対象バージョン
468
                                $item['version_check'] = 0;
469
                            }
470
                            if ($item['price'] != '0' && $item['purchased'] == '0') {
471
                                // 有料商品で未購入
472
                                $item['update_status'] = 4;
473
                            }
474
                        }
475
                        unset($item);
476
477
                        // promotionアイテム
478
                        $i = 0;
479
                        foreach ($items as $item) {
480
                            if ($item['promotion'] == 1) {
481
                                $promotionItems[] = $item;
482
                                unset($items[$i]);
483
                            }
484
                            $i++;
485
                        }
486
487
                    } else {
488
                        $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...
489
                    }
490
                } else {
491
                    $success = 0;
492
                    $message = "EC-CUBEオーナーズストアにエラーが発生しています。";
493
                }
494
            }
495
496
        } else {
497
            $authResult = false;
498
        }
499
500
        return $app->render('Store/plugin_owners_install.twig', array(
501
            'authResult' => $authResult,
502
            'success' => $success,
503
            'items' => $items,
504
            'promotionItems' => $promotionItems,
505
            'message' => $message,
506
        ));
507
508
    }
509
510
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$action" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
introduced by
Doc comment for parameter "$version" missing
Loading history...
511
     * オーナーズブラグインインストール、アップデート
512
     *
513
     * @param Application $app
514
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
515
     * @param $action
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
516
     * @param $id
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
517
     * @param $version
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
518
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
519
    public function upgrade(Application $app, Request $request, $action, $id, $version)
520
    {
521
522
        $BaseInfo = $app['eccube.repository.base_info']->get();
523
524
        $authKey = $BaseInfo->getAuthenticationKey();
525
        $message = '';
526
527
        if (!is_null($authKey)) {
528
529
            // オーナーズストア通信
530
            $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...
531
            list($json, $httpHeader) = $this->getRequestApi($request, $authKey, $url);
532
533
            if ($json === false) {
534
                // 接続失敗時
535
536
                $message = $this->getResponseErrorMessage($httpHeader);
537
538
            } else {
539
                // 接続成功時
540
541
                $data = json_decode($json, true);
542
543
                if (isset($data['success'])) {
544
                    $success = $data['success'];
545
                    if ($success == '1') {
546
                        $tmpDir = null;
547
                        try {
548
                            $service = $app['eccube.service.plugin'];
549
550
                            $item = $data['item'];
551
                            $file = base64_decode($item['data']);
552
                            $extension = pathinfo($item['file_name'], PATHINFO_EXTENSION);
553
554
                            $tmpDir = $service->createTempDir();
555
                            $tmpFile = sha1(Str::random(32)) . '.' . $extension;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
556
557
                            // ファイル作成
558
                            $fs = new Filesystem();
559
                            $fs->dumpFile($tmpDir . '/' . $tmpFile, $file);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
560
561
                            if ($action == 'install') {
562
563
                                $service->install($tmpDir . '/' . $tmpFile, $id);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
564
                                $app->addSuccess('admin.plugin.install.complete', 'admin');
565
566
                            } else if ($action == 'update') {
567
568
                                $Plugin = $app['eccube.repository.plugin']->findOneBy(array('source' => $id));
569
570
                                $service->update($Plugin, $tmpDir . '/' . $tmpFile);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
571
                                $app->addSuccess('admin.plugin.update.complete', 'admin');
572
573
                                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...
574
575
                            }
576
577
                            $fs = new Filesystem();
578
                            $fs->remove($tmpDir);
579
580
                            // ダウンロード完了通知処理(正常終了時)
581
                            $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...
582
                            $this->getRequestApi($request, $authKey, $url);
583
584
                            return $app->redirect($app->url('admin_store_plugin'));
585
586
                        } catch (PluginException $e) {
587
                            if (!empty($tmpDir) && file_exists($tmpDir)) {
588
                                $fs = new Filesystem();
589
                                $fs->remove($tmpDir);
590
                            }
591
                            $message = $e->getMessage();
592
                        }
593
594
                    } else {
595
                        $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...
596
                    }
597
                } else {
598
                    $message = "EC-CUBEオーナーズストアにエラーが発生しています。";
599
                }
600
            }
601
        }
602
603
        // ダウンロード完了通知処理(エラー発生時)
604
        $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...
605
        $this->getRequestApi($request, $authKey, $url);
606
607
        $app->addError($message, 'admin');
608
609
        return $app->redirect($app->url('admin_store_plugin_owners_install'));
610
    }
611
612
    /**
613
     * 認証キー設定画面
614
     *
615
     * @param Application $app
616
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
617
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
618
    public function authenticationSetting(Application $app, Request $request)
619
    {
620
621
        $form = $app->form()->getForm();
622
623
        $BaseInfo = $app['eccube.repository.base_info']->get();
624
625
        // 認証キーの取得
626
        $form->add(
627
            'authentication_key', 'text', array(
628
            'label' => '認証キー',
629
            'constraints' => array(
630
                new Assert\Regex(array(
631
                    'pattern' => "/^[0-9a-zA-Z]+$/",
632
                )),
633
            ),
634
            'data' => $BaseInfo->getAuthenticationKey(),
635
        ));
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...
636
637
        if ('POST' === $request->getMethod()) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 8
Loading history...
638
            $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...
639
640
            if ($form->isValid()) {
1 ignored issue
show
Coding Style introduced by
Line indented incorrectly; expected 16 spaces, found 12
Loading history...
641
                $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...
642
643
                // 認証キーの登録
644
                $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...
645
                $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...
646
647
                $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...
648
649
            }
650
        }
651
652
653
        return $app->render('Store/authentication_setting.twig', array(
654
            'form' => $form->createView(),
655
        ));
656
657
    }
658
659
660
    /**
661
     * APIリクエスト処理
662
     *
663
     * @param Request $request
664
     * @param $authKey
665
     * @param $url
666
     * @return array
667
     */
668
    private function getRequestApi(Request $request, $authKey, $url)
669
    {
670
        $opts = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
671
            'http' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
672
                'method' => 'GET',
673
                'ignore_errors' => false,
674
                'timeout' => 60,
675
                'header' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
676
                    'Authorization: ' . base64_encode($authKey),
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
677
                    '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...
678
                    '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...
679
                )
680
            )
681
        );
682
683
        $context = stream_context_create($opts);
684
685
        $json = @file_get_contents($url, false, $context);
686
687
        return array($json, $http_response_header);
688
    }
689
690
    /**
691
     * レスポンスヘッダーのチェック
692
     *
693
     * @param $httpHeader
694
     * @return string
695
     */
696
    private function getResponseErrorMessage($httpHeader)
697
    {
698
        if (!empty($httpHeader)) {
699
            list($version, $statusCode, $message) = explode(' ', $httpHeader[0], 3);
0 ignored issues
show
Unused Code introduced by
The assignment to $version 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...
700
701
            switch ($statusCode) {
702
                case '404':
703
                    $message = $statusCode . ' : ' . $message;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
704
                    break;
705
                case '500':
706
                    $message = $statusCode . ' : ' . $message;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
707
                    break;
708
                default:
709
                    $message = "EC-CUBEオーナーズストアにエラーが発生しています。";
710
                    break;
711
            }
712
        } else {
713
            $message = "タイムアウトエラーまたはURLの指定に誤りがあります。";
714
        }
715
716
        return $message;
717
    }
718
719
720
    /**
721
     * フォルダ設置のみのプラグインを取得する.
722
     *
723
     * @param array $plugins
724
     * @param Application $app
725
     * @return array
726
     */
727
    protected function getUnregisteredPlugins(array $plugins, \Eccube\Application $app)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
728
    {
729
        $finder = new Finder();
730
        $pluginCodes = array();
731
732
        // DB登録済みプラグインコードのみ取得
733
        foreach ($plugins as $key => $plugin) {
734
            $pluginCodes[] = $plugin->getCode();
735
        }
736
        // DB登録済みプラグインコードPluginディレクトリから排他
737
        $dirs = $finder->in($app['config']['plugin_realdir'])->depth(0)->directories();
738
739
        // プラグイン基本チェック
740
        $unregisteredPlugins = array();
741
        foreach ($dirs as $dir) {
742
            $pluginCode = $dir->getBasename();
743
            if (in_array($pluginCode, $pluginCodes, true)) {
744
                continue;
745
            }
746
            try {
747
                $app['eccube.service.plugin']->checkPluginArchiveContent($dir->getRealPath());
748
            } catch (\Eccube\Exception\PluginException $e) {
749
                //config.yamlに不備があった際は全てスキップ
750
                $app['monolog']->warning($e->getMessage());
751
                continue;
752
            }
753
            $config = $app['eccube.service.plugin']->readYml($dir->getRealPath().'/config.yml');
754
            $unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null;
755
            $unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null;
756
            $unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null;
757
            $unregisteredPlugins[$pluginCode]['enable'] = Constant::DISABLED;
758
            $unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null;
759
        }
760
761
        return $unregisteredPlugins;
762
    }
763
}
764