Failed Conditions
Pull Request — experimental/3.1 (#2159)
by Kentaro
88:02
created

InstallController::isValid()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 7.456

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 4
cts 10
cp 0.4
rs 9.2
cc 4
eloc 10
nc 4
nop 2
crap 7.456
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
25
namespace Eccube\Controller\Install;
26
27
use Doctrine\DBAL\Migrations\Configuration\Configuration;
28
use Doctrine\DBAL\Migrations\Migration;
29
use Doctrine\DBAL\Migrations\MigrationException;
30
use Doctrine\ORM\EntityManager;
31
use Doctrine\ORM\Tools\SchemaTool;
32
use Eccube\Common\Constant;
33
use Eccube\Form\Type\Install\Step1Type;
34
use Eccube\Form\Type\Install\Step3Type;
35
use Eccube\Form\Type\Install\Step4Type;
36
use Eccube\Form\Type\Install\Step5Type;
37
use Eccube\InstallApplication;
38
use Eccube\Plugin\ConfigManager as PluginConfigManager;
39
use Eccube\Util\Str;
40
use Symfony\Component\Filesystem\Filesystem;
41
use Symfony\Component\Finder\Finder;
42
use Symfony\Component\Form\Form;
43
use Symfony\Component\HttpFoundation\Request;
44
use Symfony\Component\Yaml\Yaml;
45
46
class InstallController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
47
{
48
49
    const MCRYPT = 'mcrypt';
50
51
    private $app;
52
    private $PDO;
53
    private $config_path;
54
    private $dist_path;
55
    private $cache_path;
56
    private $session_data;
57
    private $required_modules = array('pdo', 'phar', 'mbstring', 'zlib', 'ctype', 'session', 'JSON', 'xml', 'libxml', 'OpenSSL', 'zip', 'cURL', 'fileinfo');
58
    private $recommended_module = array('hash', self::MCRYPT);
59
60
    const SESSION_KEY = 'eccube.session.install';
61
62 7
    public function __construct()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
63
    {
64 7
        $this->config_path = __DIR__ . '/../../../../app/config/eccube';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
65 7
        $this->dist_path = __DIR__ . '/../../Resource/config';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
66 7
        $this->cache_path = __DIR__ . '/../../../../app/cache';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
67
    }
68
69 4
    private function isValid(Request $request, Form $form)
70
    {
71 4
        $session = $request->getSession();
72 4
        if ('POST' === $request->getMethod()) {
73
            $form->handleRequest($request);
74
            if ($form->isValid()) {
75
                $sessionData = $session->get(self::SESSION_KEY) ?: array();
76
                $formData = array_replace_recursive($sessionData, $form->getData());
77
                $session->set(self::SESSION_KEY, $formData);
78
79
                return true;
80
            }
81
        }
82
83 4
        return false;
84
    }
85
86 5
    private function getSessionData(Request $request)
87
    {
88 5
        return $this->session_data = $request->getSession()->get(self::SESSION_KEY);
89
    }
90
91
    // 最初からやり直す場合、SESSION情報をクリア
92 1
    public function index(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
introduced by
You must use "/**" style comments for a function comment
Loading history...
93
    {
94 1
        $request->getSession()->remove(self::SESSION_KEY);
95
96 1
        return $app->redirect($app->path('install_step1'));
97
    }
98
99
    // ようこそ
100 1
    public function step1(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
101
    {
102 1
        $form = $app['form.factory']
103 1
            ->createBuilder(Step1Type::class)
104 1
            ->getForm();
105 1
        $sessionData = $this->getSessionData($request);
106 1
        $form->setData($sessionData);
107
108 1
        if ($this->isValid($request, $form)) {
109
            return $app->redirect($app->path('install_step2'));
110
        }
111
112 1
        $this->checkModules($app);
113
114 1
        return $app['twig']->render('step1.twig', array(
115 1
                'form' => $form->createView(),
116 1
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
117
        ));
118
    }
119
120
    // 権限チェック
121 1
    public function step2(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
122
    {
123 1
        $this->getSessionData($request);
124
125 1
        $protectedDirs = $this->getProtectedDirs();
126
127
        // 権限がある場合, キャッシュディレクトリをクリア
128 1
        if (empty($protectedDirs)) {
129 1
            $finder = Finder::create()
130 1
                ->in($this->cache_path)
131 1
                ->notName('.gitkeep')
132 1
                ->files();
133 1
            $fs = new Filesystem();
134 1
            $fs->remove($finder);
135
        }
136
137 1
        return $app['twig']->render('step2.twig', array(
138 1
                'protectedDirs' => $protectedDirs,
139 1
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
140
        ));
141
    }
142
143
    //    サイトの設定
144 1
    public function step3(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
145
    {
146 1
        $form = $app['form.factory']
147 1
            ->createBuilder(Step3Type::class)
148 1
            ->getForm();
149 1
        $sessionData = $this->getSessionData($request);
150
151 1
        if (empty($sessionData['shop_name'])) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
152
153 1
            $config_file = $this->config_path . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
154 1
            $fs = new Filesystem();
155
156 1
            if ($fs->exists($config_file)) {
157
                // すでに登録されていた場合、登録データを表示
158 1
                $this->setPDO();
159 1
                $stmt = $this->PDO->query("SELECT shop_name, email01 FROM dtb_base_info WHERE id = 1;");
160
161 1
                foreach ($stmt as $row) {
162 1
                    $sessionData['shop_name'] = $row['shop_name'];
163 1
                    $sessionData['email'] = $row['email01'];
164
                }
165
166
                // セキュリティの設定
167 1
                $config_file = $this->config_path . '/path.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
168 1
                $config = Yaml::parse(file_get_contents($config_file));
169 1
                $sessionData['admin_dir'] = $config['admin_route'];
170
171 1
                $config_file = $this->config_path . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
172 1
                $config = Yaml::parse(file_get_contents($config_file));
173
174 1
                $allowHost = $config['admin_allow_host'];
175 1 View Code Duplication
                if (count($allowHost) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
176
                    $sessionData['admin_allow_hosts'] = Str::convertLineFeed(implode("\n", $allowHost));
177
                }
178 1
                $sessionData['admin_force_ssl'] = (bool) $config['force_ssl'];
179
180
                // ロードバランサー、プロキシサーバ設定
181 1
                $sessionData['trusted_proxies_connection_only'] = (bool)$config['trusted_proxies_connection_only'];
0 ignored issues
show
Coding Style introduced by
As per coding-style, a cast statement should be followed by a single space.
Loading history...
182 1
                $trustedProxies = $config['trusted_proxies'];
183 1 View Code Duplication
                if (count($trustedProxies) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
184 1
                    $sessionData['trusted_proxies'] = Str::convertLineFeed(implode("\n", $trustedProxies));
185 1
                }
186 1
187 1
                // メール設定
188 1
                $config_file = $this->config_path . '/mail.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
189
                $config = Yaml::parse(file_get_contents($config_file));
190
                $mail = $config['mail'];
191
                $sessionData['mail_backend'] = $mail['transport'];
192
                $sessionData['smtp_host'] = $mail['host'];
193
                $sessionData['smtp_port'] = $mail['port'];
194
                $sessionData['smtp_username'] = $mail['username'];
195 1
                $sessionData['smtp_password'] = $mail['password'];
196 1
            } else {
197
                // 初期値にmailを設定
198
                $sessionData['mail_backend'] = 'mail';
199
            }
200
        }
201
202 1
        $form->setData($sessionData);
203 1
        if ($this->isValid($request, $form)) {
204 1
            $data = $form->getData();
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
205
206
            return $app->redirect($app->path('install_step4'));
207
        }
208
209 1
        return $app['twig']->render('step3.twig', array(
210
                'form' => $form->createView(),
211 1
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
212 1
        ));
213 1
    }
214
215 1
    //    データベースの設定
216
    public function step4(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
217 1
    {
218
        $form = $app['form.factory']
219 1
            ->createBuilder(Step4Type::class)
220 1
            ->getForm();
221
222 1
        $sessionData = $this->getSessionData($request);
223
224
        if (empty($sessionData['database'])) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
225 1
226 1
            $config_file = $this->config_path . '/database.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
227 1
            $fs = new Filesystem();
228 1
229 1
            if ($fs->exists($config_file)) {
230 1
                // すでに登録されていた場合、登録データを表示
231 1
                // データベース設定
232 1
                $config = Yaml::parse(file_get_contents($config_file));
233 1
                $database = $config['database'];
234
                $sessionData['database'] = $database['driver'];
235
                if ($database['driver'] != 'pdo_sqlite') {
236
                    $sessionData['database_host'] = $database['host'];
237
                    $sessionData['database_port'] = $database['port'];
238 1
                    $sessionData['database_name'] = $database['dbname'];
239
                    $sessionData['database_user'] = $database['user'];
240 1
                    $sessionData['database_password'] = $database['password'];
241
                }
242
            }
243
        }
244
245 1
        $form->setData($sessionData);
246 1
247 1
        if ($this->isValid($request, $form)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
248
249
            return $app->redirect($app->path('install_step5'));
250
        }
251
252 1
        return $app['twig']->render('step4.twig', array(
253
                'form' => $form->createView(),
254 1
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
255 1
        ));
256 1
    }
257 1
258 1
    //    データベースの初期化
259 1
    public function step5(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
260 1
    {
261
        set_time_limit(0);
262 1
        $this->app = $app;
263
        $form = $app['form.factory']
264
            ->createBuilder(Step5Type::class)
265
            ->getForm();
266
        $sessionData = $this->getSessionData($request);
267
        $form->setData($sessionData);
268
269
        if ($this->isValid($request, $form)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
270
271
            $this
272
                ->createDatabaseYamlFile($sessionData)
273
                ->createMailYamlFile($sessionData)
274
                ->createPathYamlFile($sessionData, $request);
275
276
            if (!$form['no_update']->getData()) {
277
                set_time_limit(0);
278
                $this->createConfigYamlFile($sessionData);
279
280
                $this
281
                    ->setPDO()
282
                    ->dropTables()
283
                    ->createTables()
284
                    ->doMigrate()
285
                    ->insert();
286
            } else {
287
                // データベースを初期化しない場合、auth_magicは初期化しない
288
                $this->createConfigYamlFile($sessionData, false);
289
290
                $this
291
                    ->setPDO()
292
                    ->update();
293
            }
294
295
296
            if (isset($sessionData['agree']) && $sessionData['agree'] == '1') {
297
                $host = $request->getSchemeAndHttpHost();
298
                $basePath = $request->getBasePath();
299
                $params = array(
300
                    'http_url' => $host . $basePath,
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
301
                    'shop_name' => $sessionData['shop_name'],
302
                );
303
304
                $this->sendAppData($params);
305
            }
306 1
            $this->addInstallStatus();
307 1
308 1
            $request->getSession()->remove(self::SESSION_KEY);
309
310
            return $app->redirect($app->path('install_complete'));
311
        }
312
313 1
        return $app['twig']->render('step5.twig', array(
314
                'form' => $form->createView(),
315 1
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
316 1
        ));
317
    }
318 1
319 1
    //    インストール完了
320
    public function complete(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
321 1
    {
322
        $config_yml = $this->config_path . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
323 1
        $config = Yaml::parse(file_get_contents($config_yml));
324 1
        $config_path = $this->config_path . '/path.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
325 1
        $path_yml = Yaml::parse(file_get_contents($config_path));
326
327
        $config = array_replace_recursive($path_yml, $config);
328
329
330
        if (isset($config['trusted_proxies_connection_only']) && !empty($config['trusted_proxies_connection_only'])) {
331
            Request::setTrustedProxies(array_merge(array($request->server->get('REMOTE_ADDR')), $config['trusted_proxies']));
332 View Code Duplication
        } elseif (isset($config['trusted_proxies']) && !empty($config['trusted_proxies'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
333
            Request::setTrustedProxies($config['trusted_proxies']);
334
        }
335
336
        $host = $request->getSchemeAndHttpHost();
337 1
        $basePath = $request->getBasePath();
338
339 1
        $adminUrl = $host . $basePath . '/' . $config['admin_dir'];
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
340 1
341 1
        return $app['twig']->render('complete.twig', array(
342
                'admin_url' => $adminUrl,
343
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
344
        ));
345 1
    }
346
347
    private function resetNatTimer()
348
    {
349 1
        // NATの無通信タイマ対策(仮)
350 1
        echo str_repeat(' ', 4 * 1024);
351
        ob_flush();
352
        flush();
353
    }
354
355
    private function checkModules($app)
0 ignored issues
show
Coding Style introduced by
checkModules uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
356 1
    {
357
        foreach ($this->required_modules as $module) {
358
            if (!extension_loaded($module)) {
359
                $app->addDanger('[必須] ' . $module . ' 拡張モジュールが有効になっていません。', 'install');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
360 1
            }
361
        }
362
363
        if (!extension_loaded('pdo_mysql') && !extension_loaded('pdo_pgsql')) {
364
            $app->addDanger('[必須] ' . 'pdo_pgsql又はpdo_mysql 拡張モジュールを有効にしてください。', 'install');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
365 1
        }
366 1
367
        foreach ($this->recommended_module as $module) {
368
            if (!extension_loaded($module)) {
369
                if ($module == self::MCRYPT && PHP_VERSION_ID >= 70100) {
370 1
                    //The mcrypt extension has been deprecated in PHP 7.1.x 
371
                    //http://php.net/manual/en/migration71.deprecated.php
372
                    continue;
373
                }
374
                $app->addInfo('[推奨] '.$module.' 拡張モジュールが有効になっていません。', 'install');
375
            }
376 1
        }
377
378 1
        if ('\\' === DIRECTORY_SEPARATOR) { // for Windows
379
            if (!extension_loaded('wincache')) {
380
                $app->addInfo('[推奨] WinCache 拡張モジュールが有効になっていません。', 'install');
381
            }
382
        } else {
383 1
            if (!extension_loaded('apc')) {
384
                $app->addInfo('[推奨] APC 拡張モジュールが有効になっていません。', 'install');
385 1
            }
386 1
        }
387
388
        if (isset($_SERVER['SERVER_SOFTWARE']) && strpos('Apache', $_SERVER['SERVER_SOFTWARE']) !== false) {
389 1
            if (!function_exists('apache_get_modules')) {
390 1
                $app->addWarning('mod_rewrite が有効になっているか不明です。', 'install');
391
            } elseif (!in_array('mod_rewrite', apache_get_modules())) {
392
                $app->addDanger('[必須] ' . 'mod_rewriteを有効にしてください。', 'install');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
393
            }
394
        } elseif (isset($_SERVER['SERVER_SOFTWARE']) && strpos('Microsoft-IIS', $_SERVER['SERVER_SOFTWARE']) !== false) {
0 ignored issues
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
395
            // iis
396 1
        } elseif (isset($_SERVER['SERVER_SOFTWARE']) && strpos('nginx', $_SERVER['SERVER_SOFTWARE']) !== false) {
0 ignored issues
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
397
            // nginx
398
        }
399
    }
400
401
    private function setPDO()
402
    {
403
        $config_file = $this->config_path . '/database.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
404
        $config = Yaml::parse(file_get_contents($config_file));
405
406
        try {
407
            $this->PDO = \Doctrine\DBAL\DriverManager::getConnection($config['database'], new \Doctrine\DBAL\Configuration());
408
            $this->PDO->connect();
409
        } catch (\Exception $e) {
410
            $this->PDO->close();
411
            throw $e;
412
        }
413
414
        return $this;
415
    }
416
417 View Code Duplication
    private function dropTables()
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...
418
    {
419
        $this->resetNatTimer();
420
421
        $em = $this->getEntityManager();
422
        $metadatas = $em->getMetadataFactory()->getAllMetadata();
423
        $schemaTool = new SchemaTool($em);
424
425
        $schemaTool->dropSchema($metadatas);
426
427
        $em->getConnection()->executeQuery('DROP TABLE IF EXISTS doctrine_migration_versions');
428
429
        return $this;
430
    }
431
432
    /**
433
     * @return EntityManager
434
     */
435
    private function getEntityManager()
436
    {
437
        if (!isset($this->app['orm.em'])) {
438
            $config_file = $this->config_path . '/database.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
439
            $database = Yaml::parse(file_get_contents($config_file));
440
441
            $this->app->register(new \Silex\Provider\DoctrineServiceProvider(), array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
442
                'db.options' => $database['database']
443
            ));
444
445
            $ormMappings = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
446
                array(
447
                    'type' => 'yml',
448
                    'namespace' => 'Eccube\Entity',
449
                    'path' => array(
450
                        __DIR__ . '/../../Resource/doctrine',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
451
                        __DIR__ . '/../../Resource/doctrine/master',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
452
                    ),
453
                ),
454
                array(  // TODO 暫定
455
                    'type' => 'annotation',
456
                    'namespace' => 'Acme\Entity',
457
                    'path' => array(
458
                        __DIR__.'/../../../../app/Acme/Entity',
459
                    ),
460
                    'use_simple_annotation_reader' => false,
461
                )
462
            );
463
464
            // XXX 同梱したプラグインがエラーになるため暫定
465
            $pluginConfigs = PluginConfigManager::getPluginConfigAll();
466
            foreach ($pluginConfigs as $code) {
467
                $config = $code['config'];
468
                // Doctrine Extend
469
                if (isset($config['orm.path']) && is_array($config['orm.path'])) {
470
                    $paths = array();
471 View Code Duplication
                    foreach ($config['orm.path'] as $path) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
472
                        $paths[] = __DIR__.'/../../../../app/Plugin/'.$config['code'].$path;
473
                    }
474
                    $ormMappings[] = array(
475
                        'type' => 'annotation',
476
                        'namespace' => 'Plugin\\'.$config['code'].'\\Entity',
477
                        'path' => $paths,
478
                        'use_simple_annotation_reader' => false,
479
                    );
480
                }
481
            }
482
            $this->app->register(new \Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
483
                'orm.proxies_dir' => __DIR__ . '/../../app/cache/doctrine',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
484
                'orm.em.options' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
485
                    'mappings' => $ormMappings
486
                )
487
            ));
488
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
489
        }
490
491
        return $em = $this->app['orm.em'];
0 ignored issues
show
Unused Code introduced by
$em is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
492
    }
493
494 View Code Duplication
    private function createTables()
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...
495
    {
496
        $this->resetNatTimer();
497
498
        $em = $this->getEntityManager();
499
        $metadatas = $em->getMetadataFactory()->getAllMetadata();
500
        $schemaTool = new SchemaTool($em);
501
502
        $schemaTool->createSchema($metadatas);
503
504
        return $this;
505
    }
506
507
    private function insert()
508
    {
509
        $this->resetNatTimer();
510
511
        $config_file = $this->config_path . '/database.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
512
        $database = Yaml::parse(file_get_contents($config_file));
513
        $config['database'] = $database['database'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$config was never initialized. Although not strictly required by PHP, it is generally a good practice to add $config = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
514
515
        $config_file = $this->config_path . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
516
        $baseConfig = Yaml::parse(file_get_contents($config_file));
517
        $config['config'] = $baseConfig;
518
519
        $this->PDO->beginTransaction();
520
521
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
522
523
            $config = array(
524
                'auth_type' => '',
525
                'auth_magic' => $config['config']['auth_magic'],
526
                'password_hash_algos' => 'sha256',
527
            );
528
            $passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($config);
529
            $salt = \Eccube\Util\Str::random(32);
530
531
            $encodedPassword = $passwordEncoder->encodePassword($this->session_data['login_pass'], $salt);
532
            $sth = $this->PDO->prepare("INSERT INTO dtb_base_info (
533
                id,
534
                shop_name,
535
                email01,
536
                email02,
537
                email03,
538
                email04,
539
                update_date,
540
                option_product_tax_rule,
541
                discriminator_type
542
            ) VALUES (
543
                1,
544
                :shop_name,
545
                :admin_mail,
546
                :admin_mail,
547
                :admin_mail,
548
                :admin_mail,
549
                current_timestamp,
550
                0,
551
                'baseinfo');");
552
            $sth->execute(array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
553
                ':shop_name' => $this->session_data['shop_name'],
554
                ':admin_mail' => $this->session_data['email']
555
            ));
556
557
            $sth = $this->PDO->prepare("INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department, discriminator_type) VALUES (2, :login_id, :admin_pass , :salt , '1', '0', '0', '1', '1', current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP', 'member');");
558
            $sth->execute(array(':login_id' => $this->session_data['login_id'], ':admin_pass' => $encodedPassword, ':salt' => $salt));
559
560
            $this->PDO->commit();
561
        } catch (\Exception $e) {
562
            $this->PDO->rollback();
563
            throw $e;
564
        }
565
566
        return $this;
567
    }
568
569
    private function update()
570
    {
571
        $this->resetNatTimer();
572
573
        $config_file = $this->config_path . '/database.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
574
        $database = Yaml::parse(file_get_contents($config_file));
575
        $config['database'] = $database['database'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$config was never initialized. Although not strictly required by PHP, it is generally a good practice to add $config = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
576
577
        $config_file = $this->config_path . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
578
        $baseConfig = Yaml::parse(file_get_contents($config_file));
579
        $config['config'] = $baseConfig;
580
581
        $this->PDO->beginTransaction();
582
583
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
584
585
            $config = array(
586
                'auth_type' => '',
587
                'auth_magic' => $config['config']['auth_magic'],
588
                'password_hash_algos' => 'sha256',
589
            );
590
            $passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($config);
591
            $salt = \Eccube\Util\Str::random(32);
592
593
            $stmt = $this->PDO->prepare("SELECT member_id FROM dtb_member WHERE login_id = :login_id;");
594
            $stmt->execute(array(':login_id' => $this->session_data['login_id']));
595
            $rs = $stmt->fetch();
596
597
            $encodedPassword = $passwordEncoder->encodePassword($this->session_data['login_pass'], $salt);
598
599
            if ($rs) {
600
                // 同一の管理者IDであればパスワードのみ更新
601
                $sth = $this->PDO->prepare("UPDATE dtb_member set password = :admin_pass, salt = :salt, update_date = current_timestamp WHERE login_id = :login_id;");
602
                $sth->execute(array(':admin_pass' => $encodedPassword, ':salt' => $salt, ':login_id' => $this->session_data['login_id']));
603
            } else {
604
                // 新しい管理者IDが入力されたらinsert
605
                $sth = $this->PDO->prepare("INSERT INTO dtb_member (login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department,discriminator_type) VALUES (:login_id, :admin_pass , :salt , '1', '0', '0', '1', '1', current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP', 'member');");
606
                $sth->execute(array(':login_id' => $this->session_data['login_id'], ':admin_pass' => $encodedPassword, ':salt' => $salt));
607
            }
608
609
            $sth = $this->PDO->prepare('UPDATE dtb_base_info set
610
                shop_name = :shop_name,
611
                email01 = :admin_mail,
612
                email02 = :admin_mail,
613
                email03 = :admin_mail,
614
                email04 = :admin_mail,
615
                update_date = current_timestamp
616
            WHERE id = 1;');
617
            $sth->execute(array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
618
                ':shop_name' => $this->session_data['shop_name'],
619
                ':admin_mail' => $this->session_data['email']
620
            ));
621
622
            $this->PDO->commit();
623
        } catch (\Exception $e) {
624
            $this->PDO->rollback();
625
            throw $e;
626
        }
627
628
        return $this;
629
    }
630
631
    private function getMigration()
632
    {
633
        $app = \Eccube\Application::getInstance();
634
        $app->initialize();
635
        $app->boot();
636
637
        $config = new Configuration($app['db']);
638
        $config->setMigrationsNamespace('DoctrineMigrations');
639
640
        $migrationDir = __DIR__ . '/../../Resource/doctrine/migration';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
641
        $config->setMigrationsDirectory($migrationDir);
642
        $config->registerMigrationsFromDirectory($migrationDir);
643
644
        $migration = new Migration($config);
645
646
        return $migration;
647
    }
648
649
    private function doMigrate()
650
    {
651 1
        try {
652
            $migration = $this->getMigration();
653 1
654 1
            // DBとのコネクションを維持するためpingさせる
655
            if (is_null($this->PDO)) {
656 1
                $this->setPDO();
657
            }
658
            $this->PDO->ping();
659
660
            // nullを渡すと最新バージョンまでマイグレートする
661
            $migration->migrate(null, false);
662
        } catch (MigrationException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Coding Style introduced by
Blank line found at start of control structure
Loading history...
663
            
0 ignored issues
show
introduced by
Please trim any trailing whitespace
Loading history...
664
        }
665
666 1
        return $this;
667 1
    }
668 1
669
    private function getProtectedDirs()
670
    {
671
        $protectedDirs = array();
672 1
        $base = __DIR__ . '/../../../..';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
673
        $dirs = array(
674
            '/html',
675
            '/app',
676
            '/app/template',
677
            '/app/cache',
678
            '/app/config',
679
            '/app/config/eccube',
680
            '/app/log',
681
            '/app/Plugin',
682
        );
683
684
        foreach ($dirs as $dir) {
685
            if (!is_writable($base . $dir)) {
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
686
                $protectedDirs[] = $dir;
687
            }
688
        }
689
690
        return $protectedDirs;
691
    }
692
693
    private function createConfigYamlFile($data, $auth = true)
694
    {
695
        $fs = new Filesystem();
696
        $config_file = $this->config_path . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
697
698
        if ($fs->exists($config_file)) {
699
            $config = Yaml::parse(file_get_contents($config_file));
700
            $fs->remove($config_file);
701
        }
702
703
        if ($auth) {
704
            $auth_magic = Str::random(32);
705
        } else {
706
            if (isset($config['auth_magic'])) {
707
                $auth_magic = $config['auth_magic'];
708
            } else {
709
                $auth_magic = Str::random(32);
710
            }
711
        }
712
713
        $allowHost = Str::convertLineFeed($data['admin_allow_hosts']);
714
        if (empty($allowHost)) {
715
            $adminAllowHosts = array();
716
        } else {
717
            $adminAllowHosts = explode("\n", $allowHost);
718
        }
719
        $trustedProxies = Str::convertLineFeed($data['trusted_proxies']);
720
        if (empty($trustedProxies)) {
721
            $adminTrustedProxies = array();
722
        } else {
723
            $adminTrustedProxies = explode("\n", $trustedProxies);
724
            // ループバックアドレスを含める
725
            $adminTrustedProxies = array_merge($adminTrustedProxies, array('127.0.0.1/8', '::1'));
726
        }
727
        if ($data['trusted_proxies_connection_only']) {
728
            // ループバックアドレスを含める
729
            $adminTrustedProxies = array('127.0.0.1/8', '::1');
730
        }
731
732
        $target = array('${AUTH_MAGIC}', '${SHOP_NAME}', '${ECCUBE_INSTALL}', '${FORCE_SSL}');
733
        $replace = array($auth_magic, $data['shop_name'], '0', $data['admin_force_ssl']);
734
735
        $fs = new Filesystem();
736
        $content = str_replace(
737
            $target, $replace, file_get_contents($this->dist_path . '/config.yml.dist')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
738
        );
739
        $fs->dumpFile($config_file, $content);
740
741
        $config = Yaml::parse(file_get_contents($config_file));
742
        $config['admin_allow_host'] = $adminAllowHosts;
743
        $config['trusted_proxies_connection_only'] = $data['trusted_proxies_connection_only'];
744
        $config['trusted_proxies'] = $adminTrustedProxies;
745
        $yml = Yaml::dump($config);
746
        file_put_contents($config_file, $yml);
747
748
        return $this;
749
    }
750
751
    private function addInstallStatus()
752
    {
753
        $config_file = $this->config_path . '/config.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
754
        $config = Yaml::parse(file_get_contents($config_file));
755
        $config['eccube_install'] = 1;
756
        $yml = Yaml::dump($config);
757
        file_put_contents($config_file, $yml);
758
759
        return $this;
760
    }
761
762
    private function createDatabaseYamlFile($data)
763
    {
764
        $fs = new Filesystem();
765
        $config_file = $this->config_path . '/database.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
766
        if ($fs->exists($config_file)) {
767
            $fs->remove($config_file);
768
        }
769
770
        if ($data['database'] != 'pdo_sqlite') {
771
            switch ($data['database'])
772
            {
773
                case 'pdo_pgsql':
774
                    if (empty($data['db_port'])) {
775
                        $data['db_port'] = '5432';
776
                    }
777
                    $data['db_driver'] = 'pdo_pgsql';
778
                    break;
779
                case 'pdo_mysql':
780
                    if (empty($data['db_port'])) {
781
                        $data['db_port'] = '3306';
782
                    }
783
                    $data['db_driver'] = 'pdo_mysql';
784
                    break;
785
            }
786
            $target = array('${DBDRIVER}', '${DBSERVER}', '${DBNAME}', '${DBPORT}', '${DBUSER}', '${DBPASS}');
787
            $replace = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
788
                $data['db_driver'],
789
                $data['database_host'],
790
                $data['database_name'],
791
                $data['database_port'],
792
                $data['database_user'],
793
                $data['database_password']
794
            );
795
796
            $fs = new Filesystem();
797
            $content = str_replace(
798
                $target, $replace, file_get_contents($this->dist_path . '/database.yml.dist')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
799
            );
800
        } else {
801
            $content = Yaml::dump(
802
                    array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
803
                        'database' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
804
                            'driver' => 'pdo_sqlite',
805
                            'path' => realpath($this->config_path . '/eccube.db')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
806
                        )
807
                    )
808
            );
809
        }
810
        $fs->dumpFile($config_file, $content);
811
812
        return $this;
813
    }
814
815
    private function createMailYamlFile($data)
816
    {
817
        $fs = new Filesystem();
818
        $config_file = $this->config_path . '/mail.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
819
        if ($fs->exists($config_file)) {
820
            $fs->remove($config_file);
821
        }
822
        $target = array('${MAIL_BACKEND}', '${MAIL_HOST}', '${MAIL_PORT}', '${MAIL_USER}', '${MAIL_PASS}');
823
        $replace = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
824
            $data['mail_backend'],
825
            $data['smtp_host'],
826
            $data['smtp_port'],
827
            $data['smtp_username'],
828
            $data['smtp_password']
829
        );
830
831
        $fs = new Filesystem();
832
        $content = str_replace(
833
            $target, $replace, file_get_contents($this->dist_path . '/mail.yml.dist')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
834
        );
835
        $fs->dumpFile($config_file, $content);
836
837
        return $this;
838
    }
839
840
    private function createPathYamlFile($data, Request $request)
841
    {
842
        $fs = new Filesystem();
843
        $config_file = $this->config_path . '/path.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
844
        if ($fs->exists($config_file)) {
845
            $fs->remove($config_file);
846
        }
847
848
        $ADMIN_ROUTE = $data['admin_dir'];
849
        $TEMPLATE_CODE = 'default';
850
        $USER_DATA_ROUTE = 'user_data';
851
        $ROOT_DIR = realpath(__DIR__ . '/../../../../');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
852
        $ROOT_URLPATH = $request->getBasePath();
853
        $ROOT_PUBLIC_URLPATH = $ROOT_URLPATH . RELATIVE_PUBLIC_DIR_PATH;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
854
855
        $target = array('${ADMIN_ROUTE}', '${TEMPLATE_CODE}', '${USER_DATA_ROUTE}', '${ROOT_DIR}', '${ROOT_URLPATH}', '${ROOT_PUBLIC_URLPATH}');
856
        $replace = array($ADMIN_ROUTE, $TEMPLATE_CODE, $USER_DATA_ROUTE, $ROOT_DIR, $ROOT_URLPATH, $ROOT_PUBLIC_URLPATH);
857
858
        $fs = new Filesystem();
859
        $content = str_replace(
860
            $target, $replace, file_get_contents($this->dist_path . '/path.yml.dist')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
861
        );
862
        $fs->dumpFile($config_file, $content);
863
864
        return $this;
865
    }
866
867
    private function sendAppData($params)
868
    {
869
        $config_file = $this->config_path . '/database.yml';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
870
        $db_config = Yaml::parse(file_get_contents($config_file));
871
872
        $this->setPDO();
873
        $stmt = $this->PDO->query('select version() as v');
874
875
        $version = '';
876
        foreach ($stmt as $row) {
877
            $version = $row['v'];
878
        }
879
880
        if ($db_config['database']['driver'] === 'pdo_mysql') {
881
            $db_ver = 'MySQL:' . $version;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
882
        } else {
883
            $db_ver = $version;
884
        }
885
886
        $data = http_build_query(
887
            array(
888
                'site_url' => $params['http_url'],
889
                'shop_name' => $params['shop_name'],
890
                'cube_ver' => Constant::VERSION,
891
                'php_ver' => phpversion(),
892
                'db_ver' => $db_ver,
893
                'os_type' => php_uname(),
894
            )
895
        );
896
897
        $header = array(
898
            'Content-Type: application/x-www-form-urlencoded',
899
            'Content-Length: ' . strlen($data),
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
900
        );
901
        $context = stream_context_create(
902
            array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
903
                'http' => array(
904
                    'method' => 'POST',
905
                    'header' => $header,
906
                    'content' => $data,
907
                )
908
            )
909
        );
910
        file_get_contents('http://www.ec-cube.net/mall/use_site.php', false, $context);
911
912
        return $this;
913
    }
914
915
    /**
916
     * マイグレーション画面を表示する.
917
     *
918
     * @param InstallApplication $app
919
     * @param Request $request
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
920
     *
921
     * @return \Symfony\Component\HttpFoundation\Response
922
     */
923
    public function migration(InstallApplication $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...
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
924
    {
925
        return $app['twig']->render('migration.twig', array(
926
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
927
        ));
928
    }
929
930
    /**
931
     * インストール済プラグインの一覧を表示する.
932
     * プラグインがインストールされていない場合は, マイグレーション実行画面へリダイレクトする.
933
     *
934
     * @param InstallApplication $app
935
     * @param Request $request
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
936
     *
937
     * @return \Symfony\Component\HttpFoundation\Response
938
     */
939
    public function migration_plugin(InstallApplication $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...
Coding Style introduced by
Method name "InstallController::migration_plugin" is not in camel caps format
Loading history...
940
    {
941
        $eccube = \Eccube\Application::getInstance();
942
        $eccube->initialize();
943
        $eccube->boot();
944
945
        $pluginRepository = $eccube['orm.em']->getRepository('Eccube\Entity\Plugin');
946
        $Plugins = $pluginRepository->findBy(array('del_flg' => Constant::DISABLED));
947
948
        if (empty($Plugins)) {
949
            // インストール済プラグインがない場合はマイグレーション実行画面へリダイレクト.
950
            return $app->redirect($app->path('migration_end'));
951
        } else {
952
            return $app['twig']->render('migration_plugin.twig', array(
953
                    'Plugins' => $Plugins,
954
                    'version' => Constant::VERSION,
955
                    'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
956
            ));
957
        }
958
    }
959
960
    /**
961
     * マイグレーションを実行し, 完了画面を表示させる
962
     *
963
     * @param InstallApplication $app
964
     * @param Request $request
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
965
     *
966
     * @return \Symfony\Component\HttpFoundation\Response
967
     */
968
    public function migration_end(InstallApplication $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...
Coding Style introduced by
Method name "InstallController::migration_end" is not in camel caps format
Loading history...
969
    {
970
        $this->doMigrate();
971
972
        $config_app = new \Eccube\Application(); // install用のappだとconfigが取れないので
973
        $config_app->initialize();
974
        $config_app->boot();
975
        \Eccube\Util\Cache::clear($config_app, true);
976
977
        return $app['twig']->render('migration_end.twig', array(
978
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
979
        ));
980
    }
981
}
982