Failed Conditions
Pull Request — experimental/3.1 (#2222)
by chihiro
53:42
created

InstallController::getProtectedDirs()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 16
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 23
ccs 0
cts 14
cp 0
crap 12
rs 9.0856
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
                if (isset($config['trusted_proxies_connection_only'])) {
182 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...
183 1
                }
184 1
                if (isset($config['trusted_proxies'])) {
185 1
                    $trustedProxies = $config['trusted_proxies'];
186 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...
187 1
                        $sessionData['trusted_proxies'] = Str::convertLineFeed(implode("\n", $trustedProxies));
188 1
                    }
189
                }
190
                // メール設定
191
                $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...
192
                $config = Yaml::parse(file_get_contents($config_file));
193
                $mail = $config['mail'];
194
                $sessionData['mail_backend'] = $mail['transport'];
195 1
                $sessionData['smtp_host'] = $mail['host'];
196 1
                $sessionData['smtp_port'] = $mail['port'];
197
                $sessionData['smtp_username'] = $mail['username'];
198
                $sessionData['smtp_password'] = $mail['password'];
199
            } else {
200
                // 初期値にmailを設定
201
                $sessionData['mail_backend'] = 'mail';
202 1
            }
203 1
        }
204 1
205
        $form->setData($sessionData);
206
        if ($this->isValid($request, $form)) {
207
            $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...
208
209 1
            return $app->redirect($app->path('install_step4'));
210
        }
211 1
212 1
        return $app['twig']->render('step3.twig', array(
213 1
                'form' => $form->createView(),
214
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
215 1
        ));
216
    }
217 1
218
    //    データベースの設定
219 1
    public function step4(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
220 1
    {
221
        $form = $app['form.factory']
222 1
            ->createBuilder(Step4Type::class)
223
            ->getForm();
224
225 1
        $sessionData = $this->getSessionData($request);
226 1
227 1
        if (empty($sessionData['database'])) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
228 1
229 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...
230 1
            $fs = new Filesystem();
231 1
232 1
            if ($fs->exists($config_file)) {
233 1
                // すでに登録されていた場合、登録データを表示
234
                // データベース設定
235
                $config = Yaml::parse(file_get_contents($config_file));
236
                $database = $config['database'];
237
                $sessionData['database'] = $database['driver'];
238 1
                if ($database['driver'] != 'pdo_sqlite') {
239
                    $sessionData['database_host'] = $database['host'];
240 1
                    $sessionData['database_port'] = $database['port'];
241
                    $sessionData['database_name'] = $database['dbname'];
242
                    $sessionData['database_user'] = $database['user'];
243
                    $sessionData['database_password'] = $database['password'];
244
                }
245 1
            }
246 1
        }
247 1
248
        $form->setData($sessionData);
249
250
        if ($this->isValid($request, $form)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
251
252 1
            return $app->redirect($app->path('install_step5'));
253
        }
254 1
255 1
        return $app['twig']->render('step4.twig', array(
256 1
                'form' => $form->createView(),
257 1
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
258 1
        ));
259 1
    }
260 1
261
    //    データベースの初期化
262 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...
263
    {
264
        set_time_limit(0);
265
        $this->app = $app;
266
        $form = $app['form.factory']
267
            ->createBuilder(Step5Type::class)
268
            ->getForm();
269
        $sessionData = $this->getSessionData($request);
270
        $form->setData($sessionData);
271
272
        if ($this->isValid($request, $form)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
273
274
            $this
275
                ->createDatabaseYamlFile($sessionData)
276
                ->createMailYamlFile($sessionData)
277
                ->createPathYamlFile($sessionData, $request);
278
279
            if (!$form['no_update']->getData()) {
280
                set_time_limit(0);
281
                $this->createConfigYamlFile($sessionData);
282
283
                $this
284
                    ->setPDO()
285
                    ->dropTables()
286
                    ->createTables()
287
                    ->importCsv()
288
                    ->doMigrate()
289
                    ->insert();
290
            } else {
291
                // データベースを初期化しない場合、auth_magicは初期化しない
292
                $this->createConfigYamlFile($sessionData, false);
293
294
                $this
295
                    ->setPDO()
296
                    ->update();
297
            }
298
299
300
            if (isset($sessionData['agree']) && $sessionData['agree'] == '1') {
301
                $host = $request->getSchemeAndHttpHost();
302
                $basePath = $request->getBasePath();
303
                $params = array(
304
                    'http_url' => $host . $basePath,
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
305
                    'shop_name' => $sessionData['shop_name'],
306 1
                );
307 1
308 1
                $this->sendAppData($params);
309
            }
310
            $this->addInstallStatus();
311
312
            $request->getSession()->remove(self::SESSION_KEY);
313 1
314
            return $app->redirect($app->path('install_complete'));
315 1
        }
316 1
317
        return $app['twig']->render('step5.twig', array(
318 1
                'form' => $form->createView(),
319 1
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
320
        ));
321 1
    }
322
323 1
    //    インストール完了
324 1
    public function complete(InstallApplication $app, Request $request)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
325 1
    {
326
        $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...
327
        $config = Yaml::parse(file_get_contents($config_yml));
328
        $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...
329
        $path_yml = Yaml::parse(file_get_contents($config_path));
330
331
        $config = array_replace_recursive($path_yml, $config);
332
333
334
        if (isset($config['trusted_proxies_connection_only']) && !empty($config['trusted_proxies_connection_only'])) {
335
            Request::setTrustedProxies(array_merge(array($request->server->get('REMOTE_ADDR')), $config['trusted_proxies']));
336 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...
337 1
            Request::setTrustedProxies($config['trusted_proxies']);
338
        }
339 1
340 1
        $host = $request->getSchemeAndHttpHost();
341 1
        $basePath = $request->getBasePath();
342
343
        $adminUrl = $host . $basePath . '/' . $config['admin_dir'];
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
344
345 1
        return $app['twig']->render('complete.twig', array(
346
                'admin_url' => $adminUrl,
347
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
348
        ));
349 1
    }
350 1
351
    private function resetNatTimer()
352
    {
353
        // NATの無通信タイマ対策(仮)
354
        echo str_repeat(' ', 4 * 1024);
355
        ob_flush();
356 1
        flush();
357
    }
358
359
    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...
360 1
    {
361
        foreach ($this->required_modules as $module) {
362
            if (!extension_loaded($module)) {
363
                $app->addDanger('[必須] ' . $module . ' 拡張モジュールが有効になっていません。', 'install');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
364
            }
365 1
        }
366 1
367
        if (!extension_loaded('pdo_mysql') && !extension_loaded('pdo_pgsql')) {
368
            $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...
369
        }
370 1
371
        foreach ($this->recommended_module as $module) {
372
            if (!extension_loaded($module)) {
373
                if ($module == self::MCRYPT && PHP_VERSION_ID >= 70100) {
374
                    //The mcrypt extension has been deprecated in PHP 7.1.x 
375
                    //http://php.net/manual/en/migration71.deprecated.php
376 1
                    continue;
377
                }
378 1
                $app->addInfo('[推奨] '.$module.' 拡張モジュールが有効になっていません。', 'install');
379
            }
380
        }
381
382
        if ('\\' === DIRECTORY_SEPARATOR) { // for Windows
383 1
            if (!extension_loaded('wincache')) {
384
                $app->addInfo('[推奨] WinCache 拡張モジュールが有効になっていません。', 'install');
385 1
            }
386 1
        } else {
387
            if (!extension_loaded('apc')) {
388
                $app->addInfo('[推奨] APC 拡張モジュールが有効になっていません。', 'install');
389 1
            }
390 1
        }
391
392
        if (isset($_SERVER['SERVER_SOFTWARE']) && strpos('Apache', $_SERVER['SERVER_SOFTWARE']) !== false) {
393
            if (!function_exists('apache_get_modules')) {
394
                $app->addWarning('mod_rewrite が有効になっているか不明です。', 'install');
395
            } elseif (!in_array('mod_rewrite', apache_get_modules())) {
396 1
                $app->addDanger('[必須] ' . 'mod_rewriteを有効にしてください。', 'install');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
397
            }
398
        } 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...
399
            // iis
400
        } 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...
401
            // nginx
402
        }
403
    }
404
405
    private function setPDO()
406
    {
407
        $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...
408
        $config = Yaml::parse(file_get_contents($config_file));
409
410
        try {
411
            $this->PDO = \Doctrine\DBAL\DriverManager::getConnection($config['database'], new \Doctrine\DBAL\Configuration());
412
            $this->PDO->connect();
413
        } catch (\Exception $e) {
414
            $this->PDO->close();
415
            throw $e;
416
        }
417
418
        return $this;
419
    }
420
421 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...
422
    {
423
        $this->resetNatTimer();
424
425
        $em = $this->getEntityManager();
426
        $metadatas = $em->getMetadataFactory()->getAllMetadata();
427
        $schemaTool = new SchemaTool($em);
428
429
        $schemaTool->dropSchema($metadatas);
430
431
        $em->getConnection()->executeQuery('DROP TABLE IF EXISTS doctrine_migration_versions');
432
433
        return $this;
434
    }
435
436
    /**
437
     * @return EntityManager
438
     */
439
    private function getEntityManager()
440
    {
441
        if (!isset($this->app['orm.em'])) {
442
            $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...
443
            $database = Yaml::parse(file_get_contents($config_file));
444
445
            $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...
446
                'db.options' => $database['database']
447
            ));
448
449
            $ormMappings = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
450
                array(
451
                    'type' => 'yml',
452
                    'namespace' => 'Eccube\Entity',
453
                    'path' => array(
454
                        __DIR__ . '/../../Resource/doctrine',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
455
                        __DIR__ . '/../../Resource/doctrine/master',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
456
                    ),
457
                ),
458
                array(  // TODO 暫定
459
                    'type' => 'annotation',
460
                    'namespace' => 'Acme\Entity',
461
                    'path' => array(
462
                        __DIR__.'/../../../../app/Acme/Entity',
463
                    ),
464
                    'use_simple_annotation_reader' => false,
465
                )
466
            );
467
468
            // XXX 同梱したプラグインがエラーになるため暫定
469
            $pluginConfigs = PluginConfigManager::getPluginConfigAll();
470
            foreach ($pluginConfigs as $code) {
471
                $config = $code['config'];
472
                // Doctrine Extend
473
                if (isset($config['orm.path']) && is_array($config['orm.path'])) {
474
                    $paths = array();
475 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...
476
                        $paths[] = __DIR__.'/../../../../app/Plugin/'.$config['code'].$path;
477
                    }
478
                    $ormMappings[] = array(
479
                        'type' => 'annotation',
480
                        'namespace' => 'Plugin\\'.$config['code'].'\\Entity',
481
                        'path' => $paths,
482
                        'use_simple_annotation_reader' => false,
483
                    );
484
                }
485
            }
486
            $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...
487
                '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...
488
                'orm.em.options' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
489
                    'mappings' => $ormMappings
490
                )
491
            ));
492
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
493
        }
494
495
        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...
496
    }
497
498 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...
499
    {
500
        $this->resetNatTimer();
501
502
        $em = $this->getEntityManager();
503
        $metadatas = $em->getMetadataFactory()->getAllMetadata();
504
        $schemaTool = new SchemaTool($em);
505
506
        $schemaTool->createSchema($metadatas);
507
508
        return $this;
509
    }
510
511
    private function importCsv() {
512
513
        $em = $this->getEntityManager();
514
        $loader = new \Eccube\Doctrine\Common\CsvDataFixtures\Loader();
515
        $loader->loadFromDirectory(__DIR__.'/../../Resource/doctrine/import_csv');
516
        $Executor = new \Eccube\Doctrine\Common\CsvDataFixtures\Executor\DbalExecutor($em);
517
        $fixtures = $loader->getFixtures();
518
        $Executor->execute($fixtures);
519
520
        return $this;
521
    }
522
523
    private function insert()
524
    {
525
        $this->resetNatTimer();
526
527
        $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...
528
        $database = Yaml::parse(file_get_contents($config_file));
529
        $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...
530
531
        $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...
532
        $baseConfig = Yaml::parse(file_get_contents($config_file));
533
        $config['config'] = $baseConfig;
534
535
        $this->PDO->beginTransaction();
536
537
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
538
539
            $config = array(
540
                'auth_type' => '',
541
                'auth_magic' => $config['config']['auth_magic'],
542
                'password_hash_algos' => 'sha256',
543
            );
544
            $passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($config);
545
            $salt = \Eccube\Util\Str::random(32);
546
547
            $encodedPassword = $passwordEncoder->encodePassword($this->session_data['login_pass'], $salt);
548
            $sth = $this->PDO->prepare("INSERT INTO dtb_base_info (
549
                id,
550
                shop_name,
551
                email01,
552
                email02,
553
                email03,
554
                email04,
555
                update_date,
556
                option_product_tax_rule,
557
                discriminator_type
558
            ) VALUES (
559
                1,
560
                :shop_name,
561
                :admin_mail,
562
                :admin_mail,
563
                :admin_mail,
564
                :admin_mail,
565
                current_timestamp,
566
                0,
567
                'baseinfo');");
568
            $sth->execute(array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
569
                ':shop_name' => $this->session_data['shop_name'],
570
                ':admin_mail' => $this->session_data['email']
571
            ));
572
573
            $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');");
574
            $sth->execute(array(':login_id' => $this->session_data['login_id'], ':admin_pass' => $encodedPassword, ':salt' => $salt));
575
576
            $this->PDO->commit();
577
        } catch (\Exception $e) {
578
            $this->PDO->rollback();
579
            throw $e;
580
        }
581
582
        return $this;
583
    }
584
585
    private function update()
586
    {
587
        $this->resetNatTimer();
588
589
        $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...
590
        $database = Yaml::parse(file_get_contents($config_file));
591
        $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...
592
593
        $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...
594
        $baseConfig = Yaml::parse(file_get_contents($config_file));
595
        $config['config'] = $baseConfig;
596
597
        $this->PDO->beginTransaction();
598
599
        try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
600
601
            $config = array(
602
                'auth_type' => '',
603
                'auth_magic' => $config['config']['auth_magic'],
604
                'password_hash_algos' => 'sha256',
605
            );
606
            $passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($config);
607
            $salt = \Eccube\Util\Str::random(32);
608
609
            $stmt = $this->PDO->prepare("SELECT member_id FROM dtb_member WHERE login_id = :login_id;");
610
            $stmt->execute(array(':login_id' => $this->session_data['login_id']));
611
            $rs = $stmt->fetch();
612
613
            $encodedPassword = $passwordEncoder->encodePassword($this->session_data['login_pass'], $salt);
614
615
            if ($rs) {
616
                // 同一の管理者IDであればパスワードのみ更新
617
                $sth = $this->PDO->prepare("UPDATE dtb_member set password = :admin_pass, salt = :salt, update_date = current_timestamp WHERE login_id = :login_id;");
618
                $sth->execute(array(':admin_pass' => $encodedPassword, ':salt' => $salt, ':login_id' => $this->session_data['login_id']));
619
            } else {
620
                // 新しい管理者IDが入力されたらinsert
621
                $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');");
622
                $sth->execute(array(':login_id' => $this->session_data['login_id'], ':admin_pass' => $encodedPassword, ':salt' => $salt));
623
            }
624
625
            $sth = $this->PDO->prepare('UPDATE dtb_base_info set
626
                shop_name = :shop_name,
627
                email01 = :admin_mail,
628
                email02 = :admin_mail,
629
                email03 = :admin_mail,
630
                email04 = :admin_mail,
631
                update_date = current_timestamp
632
            WHERE id = 1;');
633
            $sth->execute(array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
634
                ':shop_name' => $this->session_data['shop_name'],
635
                ':admin_mail' => $this->session_data['email']
636
            ));
637
638
            $this->PDO->commit();
639
        } catch (\Exception $e) {
640
            $this->PDO->rollback();
641
            throw $e;
642
        }
643
644
        return $this;
645
    }
646
647
    private function getMigration()
648
    {
649
        $app = \Eccube\Application::getInstance();
650
        $app->initialize();
651 1
        $app->boot();
652
653 1
        $config = new Configuration($app['db']);
654 1
        $config->setMigrationsNamespace('DoctrineMigrations');
655
656 1
        $migrationDir = __DIR__ . '/../../Resource/doctrine/migration';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
657
        $config->setMigrationsDirectory($migrationDir);
658
        $config->registerMigrationsFromDirectory($migrationDir);
659
660
        $migration = new Migration($config);
661
662
        return $migration;
663
    }
664
665
    private function doMigrate()
666 1
    {
667 1
        try {
668 1
            $migration = $this->getMigration();
669
670
            // DBとのコネクションを維持するためpingさせる
671
            if (is_null($this->PDO)) {
672 1
                $this->setPDO();
673
            }
674
            $this->PDO->ping();
675
676
            // nullを渡すと最新バージョンまでマイグレートする
677
            $migration->migrate(null, false);
678
        } 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...
679
            
0 ignored issues
show
introduced by
Please trim any trailing whitespace
Loading history...
680
        }
681
682
        return $this;
683
    }
684
685
    private function getProtectedDirs()
686
    {
687
        $protectedDirs = array();
688
        $base = __DIR__ . '/../../../..';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
689
        $dirs = array(
690
            '/html',
691
            '/app',
692
            '/app/template',
693
            '/app/cache',
694
            '/app/config',
695
            '/app/config/eccube',
696
            '/app/log',
697
            '/app/Plugin',
698
        );
699
700
        foreach ($dirs as $dir) {
701
            if (!is_writable($base . $dir)) {
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
702
                $protectedDirs[] = $dir;
703
            }
704
        }
705
706
        return $protectedDirs;
707
    }
708
709
    private function createConfigYamlFile($data, $auth = true)
710
    {
711
        $fs = new Filesystem();
712
        $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...
713
714
        if ($fs->exists($config_file)) {
715
            $config = Yaml::parse(file_get_contents($config_file));
716
            $fs->remove($config_file);
717
        }
718
719
        if ($auth) {
720
            $auth_magic = Str::random(32);
721
        } else {
722
            if (isset($config['auth_magic'])) {
723
                $auth_magic = $config['auth_magic'];
724
            } else {
725
                $auth_magic = Str::random(32);
726
            }
727
        }
728
729
        $allowHost = Str::convertLineFeed($data['admin_allow_hosts']);
730
        if (empty($allowHost)) {
731
            $adminAllowHosts = array();
732
        } else {
733
            $adminAllowHosts = explode("\n", $allowHost);
734
        }
735
        $trustedProxies = Str::convertLineFeed($data['trusted_proxies']);
736
        if (empty($trustedProxies)) {
737
            $adminTrustedProxies = array();
738
        } else {
739
            $adminTrustedProxies = explode("\n", $trustedProxies);
740
            // ループバックアドレスを含める
741
            $adminTrustedProxies = array_merge($adminTrustedProxies, array('127.0.0.1/8', '::1'));
742
        }
743
        if ($data['trusted_proxies_connection_only']) {
744
            // ループバックアドレスを含める
745
            $adminTrustedProxies = array('127.0.0.1/8', '::1');
746
        }
747
748
        $target = array('${AUTH_MAGIC}', '${SHOP_NAME}', '${ECCUBE_INSTALL}', '${FORCE_SSL}');
749
        $replace = array($auth_magic, $data['shop_name'], '0', $data['admin_force_ssl']);
750
751
        $fs = new Filesystem();
752
        $content = str_replace(
753
            $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...
754
        );
755
        $fs->dumpFile($config_file, $content);
756
757
        $config = Yaml::parse(file_get_contents($config_file));
758
        $config['admin_allow_host'] = $adminAllowHosts;
759
        $config['trusted_proxies_connection_only'] = $data['trusted_proxies_connection_only'];
760
        $config['trusted_proxies'] = $adminTrustedProxies;
761
        $yml = Yaml::dump($config);
762
        file_put_contents($config_file, $yml);
763
764
        return $this;
765
    }
766
767
    private function addInstallStatus()
768
    {
769
        $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...
770
        $config = Yaml::parse(file_get_contents($config_file));
771
        $config['eccube_install'] = 1;
772
        $yml = Yaml::dump($config);
773
        file_put_contents($config_file, $yml);
774
775
        return $this;
776
    }
777
778
    private function createDatabaseYamlFile($data)
779
    {
780
        $fs = new Filesystem();
781
        $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...
782
        if ($fs->exists($config_file)) {
783
            $fs->remove($config_file);
784
        }
785
786
        if ($data['database'] != 'pdo_sqlite') {
787
            switch ($data['database'])
788
            {
789
                case 'pdo_pgsql':
790
                    if (empty($data['db_port'])) {
791
                        $data['db_port'] = '5432';
792
                    }
793
                    $data['db_driver'] = 'pdo_pgsql';
794
                    break;
795
                case 'pdo_mysql':
796
                    if (empty($data['db_port'])) {
797
                        $data['db_port'] = '3306';
798
                    }
799
                    $data['db_driver'] = 'pdo_mysql';
800
                    break;
801
            }
802
            $target = array('${DBDRIVER}', '${DBSERVER}', '${DBNAME}', '${DBPORT}', '${DBUSER}', '${DBPASS}');
803
            $replace = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
804
                $data['db_driver'],
805
                $data['database_host'],
806
                $data['database_name'],
807
                $data['database_port'],
808
                $data['database_user'],
809
                $data['database_password']
810
            );
811
812
            $fs = new Filesystem();
813
            $content = str_replace(
814
                $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...
815
            );
816
        } else {
817
            $content = Yaml::dump(
818
                    array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
819
                        'database' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
820
                            'driver' => 'pdo_sqlite',
821
                            '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...
822
                        )
823
                    )
824
            );
825
        }
826
        $fs->dumpFile($config_file, $content);
827
828
        return $this;
829
    }
830
831
    private function createMailYamlFile($data)
832
    {
833
        $fs = new Filesystem();
834
        $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...
835
        if ($fs->exists($config_file)) {
836
            $fs->remove($config_file);
837
        }
838
        $target = array('${MAIL_BACKEND}', '${MAIL_HOST}', '${MAIL_PORT}', '${MAIL_USER}', '${MAIL_PASS}');
839
        $replace = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
840
            $data['mail_backend'],
841
            $data['smtp_host'],
842
            $data['smtp_port'],
843
            $data['smtp_username'],
844
            $data['smtp_password']
845
        );
846
847
        $fs = new Filesystem();
848
        $content = str_replace(
849
            $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...
850
        );
851
        $fs->dumpFile($config_file, $content);
852
853
        return $this;
854
    }
855
856
    private function createPathYamlFile($data, Request $request)
857
    {
858
        $fs = new Filesystem();
859
        $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...
860
        if ($fs->exists($config_file)) {
861
            $fs->remove($config_file);
862
        }
863
864
        $ADMIN_ROUTE = $data['admin_dir'];
865
        $TEMPLATE_CODE = 'default';
866
        $USER_DATA_ROUTE = 'user_data';
867
        $ROOT_DIR = realpath(__DIR__ . '/../../../../');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
868
        $ROOT_URLPATH = $request->getBasePath();
869
        $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...
870
871
        $target = array('${ADMIN_ROUTE}', '${TEMPLATE_CODE}', '${USER_DATA_ROUTE}', '${ROOT_DIR}', '${ROOT_URLPATH}', '${ROOT_PUBLIC_URLPATH}');
872
        $replace = array($ADMIN_ROUTE, $TEMPLATE_CODE, $USER_DATA_ROUTE, $ROOT_DIR, $ROOT_URLPATH, $ROOT_PUBLIC_URLPATH);
873
874
        $fs = new Filesystem();
875
        $content = str_replace(
876
            $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...
877
        );
878
        $fs->dumpFile($config_file, $content);
879
880
        return $this;
881
    }
882
883
    private function sendAppData($params)
884
    {
885
        $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...
886
        $db_config = Yaml::parse(file_get_contents($config_file));
887
888
        $this->setPDO();
889
        $stmt = $this->PDO->query('select version() as v');
890
891
        $version = '';
892
        foreach ($stmt as $row) {
893
            $version = $row['v'];
894
        }
895
896
        if ($db_config['database']['driver'] === 'pdo_mysql') {
897
            $db_ver = 'MySQL:' . $version;
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
898
        } else {
899
            $db_ver = $version;
900
        }
901
902
        $data = http_build_query(
903
            array(
904
                'site_url' => $params['http_url'],
905
                'shop_name' => $params['shop_name'],
906
                'cube_ver' => Constant::VERSION,
907
                'php_ver' => phpversion(),
908
                'db_ver' => $db_ver,
909
                'os_type' => php_uname(),
910
            )
911
        );
912
913
        $header = array(
914
            'Content-Type: application/x-www-form-urlencoded',
915
            'Content-Length: ' . strlen($data),
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
916
        );
917
        $context = stream_context_create(
918
            array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
919
                'http' => array(
920
                    'method' => 'POST',
921
                    'header' => $header,
922
                    'content' => $data,
923
                )
924
            )
925
        );
926
        file_get_contents('http://www.ec-cube.net/mall/use_site.php', false, $context);
927
928
        return $this;
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(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...
940
    {
941
        return $app['twig']->render('migration.twig', array(
942
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
943
        ));
944
    }
945
946
    /**
947
     * インストール済プラグインの一覧を表示する.
948
     * プラグインがインストールされていない場合は, マイグレーション実行画面へリダイレクトする.
949
     *
950
     * @param InstallApplication $app
951
     * @param Request $request
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
952
     *
953
     * @return \Symfony\Component\HttpFoundation\Response
954
     */
955
    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...
956
    {
957
        $eccube = \Eccube\Application::getInstance();
958
        $eccube->initialize();
959
        $eccube->boot();
960
961
        $pluginRepository = $eccube['orm.em']->getRepository('Eccube\Entity\Plugin');
962
        $Plugins = $pluginRepository->findBy(array('del_flg' => Constant::DISABLED));
963
964
        if (empty($Plugins)) {
965
            // インストール済プラグインがない場合はマイグレーション実行画面へリダイレクト.
966
            return $app->redirect($app->path('migration_end'));
967
        } else {
968
            return $app['twig']->render('migration_plugin.twig', array(
969
                    'Plugins' => $Plugins,
970
                    'version' => Constant::VERSION,
971
                    'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
972
            ));
973
        }
974
    }
975
976
    /**
977
     * マイグレーションを実行し, 完了画面を表示させる
978
     *
979
     * @param InstallApplication $app
980
     * @param Request $request
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
981
     *
982
     * @return \Symfony\Component\HttpFoundation\Response
983
     */
984
    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...
985
    {
986
        $this->doMigrate();
987
988
        $config_app = new \Eccube\Application(); // install用のappだとconfigが取れないので
989
        $config_app->initialize();
990
        $config_app->boot();
991
        \Eccube\Util\Cache::clear($config_app, true);
992
993
        return $app['twig']->render('migration_end.twig', array(
994
                'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/',
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
995
        ));
996
    }
997
}
998