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\InstallApplication; |
34
|
|
|
use Eccube\Util\Str; |
35
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
36
|
|
|
use Symfony\Component\Finder\Finder; |
37
|
|
|
use Symfony\Component\Form\Form; |
38
|
|
|
use Symfony\Component\HttpFoundation\Request; |
39
|
|
|
use Symfony\Component\Yaml\Yaml; |
40
|
|
|
|
41
|
|
|
class InstallController |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
const MCRYPT = 'mcrypt'; |
45
|
|
|
|
46
|
|
|
private $app; |
47
|
|
|
private $PDO; |
48
|
|
|
private $config_path; |
49
|
|
|
private $dist_path; |
50
|
|
|
private $cache_path; |
51
|
|
|
private $session_data; |
52
|
|
|
private $required_modules = array('pdo', 'phar', 'mbstring', 'zlib', 'ctype', 'session', 'JSON', 'xml', 'libxml', 'OpenSSL', 'zip', 'cURL', 'fileinfo'); |
53
|
|
|
private $recommended_module = array('hash', self::MCRYPT); |
54
|
|
|
|
55
|
|
|
const SESSION_KEY = 'eccube.session.install'; |
56
|
|
|
|
57
|
7 |
|
public function __construct() |
|
|
|
|
58
|
|
|
{ |
59
|
7 |
|
$this->config_path = __DIR__ . '/../../../../app/config/eccube'; |
|
|
|
|
60
|
7 |
|
$this->dist_path = __DIR__ . '/../../Resource/config'; |
|
|
|
|
61
|
7 |
|
$this->cache_path = __DIR__ . '/../../../../app/cache'; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
4 |
|
private function isValid(Request $request, Form $form) |
65
|
|
|
{ |
66
|
4 |
|
$session = $request->getSession(); |
67
|
4 |
|
if ('POST' === $request->getMethod()) { |
68
|
|
|
$form->handleRequest($request); |
69
|
|
|
if ($form->isValid()) { |
70
|
|
|
$sessionData = $session->get(self::SESSION_KEY) ?: array(); |
71
|
|
|
$formData = array_replace_recursive($sessionData, $form->getData()); |
72
|
|
|
$session->set(self::SESSION_KEY, $formData); |
73
|
|
|
|
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
4 |
|
return false; |
79
|
|
|
} |
80
|
|
|
|
81
|
5 |
|
private function getSessionData(Request $request) |
82
|
|
|
{ |
83
|
5 |
|
return $this->session_data = $request->getSession()->get(self::SESSION_KEY); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// 最初からやり直す場合、SESSION情報をクリア |
87
|
1 |
|
public function index(InstallApplication $app, Request $request) |
|
|
|
|
88
|
|
|
{ |
89
|
1 |
|
$request->getSession()->remove(self::SESSION_KEY); |
90
|
|
|
|
91
|
1 |
|
return $app->redirect($app->url('install_step1')); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// ようこそ |
95
|
1 |
|
public function step1(InstallApplication $app, Request $request) |
|
|
|
|
96
|
|
|
{ |
97
|
1 |
|
$form = $app['form.factory'] |
98
|
1 |
|
->createBuilder('install_step1') |
99
|
1 |
|
->getForm(); |
100
|
1 |
|
$sessionData = $this->getSessionData($request); |
101
|
1 |
|
$form->setData($sessionData); |
102
|
|
|
|
103
|
1 |
|
if ($this->isValid($request, $form)) { |
104
|
|
|
return $app->redirect($app->url('install_step2')); |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
$this->checkModules($app); |
108
|
|
|
|
109
|
1 |
|
return $app['twig']->render('step1.twig', array( |
110
|
1 |
|
'form' => $form->createView(), |
111
|
1 |
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
112
|
|
|
)); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
// 権限チェック |
116
|
1 |
|
public function step2(InstallApplication $app, Request $request) |
|
|
|
|
117
|
|
|
{ |
118
|
1 |
|
$this->getSessionData($request); |
119
|
|
|
|
120
|
1 |
|
$protectedDirs = $this->getProtectedDirs(); |
121
|
|
|
|
122
|
|
|
// 権限がある場合, キャッシュディレクトリをクリア |
123
|
1 |
|
if (empty($protectedDirs)) { |
124
|
1 |
|
$finder = Finder::create() |
125
|
1 |
|
->in($this->cache_path) |
126
|
1 |
|
->directories() |
127
|
1 |
|
->depth(0); |
128
|
1 |
|
$fs = new Filesystem(); |
129
|
1 |
|
$fs->remove($finder); |
130
|
|
|
} |
131
|
|
|
|
132
|
1 |
|
return $app['twig']->render('step2.twig', array( |
133
|
1 |
|
'protectedDirs' => $protectedDirs, |
134
|
1 |
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
135
|
|
|
)); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
// サイトの設定 |
139
|
1 |
|
public function step3(InstallApplication $app, Request $request) |
|
|
|
|
140
|
|
|
{ |
141
|
1 |
|
$form = $app['form.factory'] |
142
|
1 |
|
->createBuilder('install_step3') |
143
|
1 |
|
->getForm(); |
144
|
1 |
|
$sessionData = $this->getSessionData($request); |
145
|
|
|
|
146
|
1 |
|
if (empty($sessionData['shop_name'])) { |
|
|
|
|
147
|
|
|
|
148
|
1 |
|
$config_file = $this->config_path . '/config.yml'; |
|
|
|
|
149
|
1 |
|
$fs = new Filesystem(); |
150
|
|
|
|
151
|
1 |
|
if ($fs->exists($config_file)) { |
152
|
|
|
// すでに登録されていた場合、登録データを表示 |
153
|
1 |
|
$this->setPDO(); |
154
|
1 |
|
$stmt = $this->PDO->query("SELECT shop_name, email01 FROM dtb_base_info WHERE id = 1;"); |
155
|
|
|
|
156
|
1 |
|
foreach ($stmt as $row) { |
157
|
1 |
|
$sessionData['shop_name'] = $row['shop_name']; |
158
|
1 |
|
$sessionData['email'] = $row['email01']; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
// セキュリティの設定 |
162
|
1 |
|
$config_file = $this->config_path . '/path.yml'; |
|
|
|
|
163
|
1 |
|
$config = Yaml::parse(file_get_contents($config_file)); |
164
|
1 |
|
$sessionData['admin_dir'] = $config['admin_route']; |
165
|
|
|
|
166
|
1 |
|
$config_file = $this->config_path . '/config.yml'; |
|
|
|
|
167
|
1 |
|
$config = Yaml::parse(file_get_contents($config_file)); |
168
|
|
|
|
169
|
1 |
|
$allowHost = $config['admin_allow_host']; |
170
|
1 |
|
if (count($allowHost) > 0) { |
171
|
|
|
$sessionData['admin_allow_hosts'] = Str::convertLineFeed(implode("\n", $allowHost)); |
172
|
|
|
} |
173
|
1 |
|
$sessionData['admin_force_ssl'] = (bool) $config['force_ssl']; |
174
|
|
|
|
175
|
|
|
// メール設定 |
176
|
1 |
|
$config_file = $this->config_path . '/mail.yml'; |
|
|
|
|
177
|
1 |
|
$config = Yaml::parse(file_get_contents($config_file)); |
178
|
1 |
|
$mail = $config['mail']; |
179
|
1 |
|
$sessionData['mail_backend'] = $mail['transport']; |
180
|
1 |
|
$sessionData['smtp_host'] = $mail['host']; |
181
|
1 |
|
$sessionData['smtp_port'] = $mail['port']; |
182
|
1 |
|
$sessionData['smtp_username'] = $mail['username']; |
183
|
1 |
|
$sessionData['smtp_password'] = $mail['password']; |
184
|
|
|
} else { |
185
|
|
|
// 初期値にmailを設定 |
186
|
|
|
$sessionData['mail_backend'] = 'mail'; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
1 |
|
$form->setData($sessionData); |
191
|
1 |
|
if ($this->isValid($request, $form)) { |
192
|
|
|
$data = $form->getData(); |
|
|
|
|
193
|
|
|
|
194
|
|
|
return $app->redirect($app->url('install_step4')); |
195
|
|
|
} |
196
|
|
|
|
197
|
1 |
|
return $app['twig']->render('step3.twig', array( |
198
|
1 |
|
'form' => $form->createView(), |
199
|
1 |
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
200
|
|
|
)); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
// データベースの設定 |
204
|
1 |
|
public function step4(InstallApplication $app, Request $request) |
|
|
|
|
205
|
|
|
{ |
206
|
1 |
|
$form = $app['form.factory'] |
207
|
1 |
|
->createBuilder('install_step4') |
208
|
1 |
|
->getForm(); |
209
|
|
|
|
210
|
1 |
|
$sessionData = $this->getSessionData($request); |
211
|
|
|
|
212
|
1 |
|
if (empty($sessionData['database'])) { |
|
|
|
|
213
|
|
|
|
214
|
1 |
|
$config_file = $this->config_path . '/database.yml'; |
|
|
|
|
215
|
1 |
|
$fs = new Filesystem(); |
216
|
|
|
|
217
|
1 |
|
if ($fs->exists($config_file)) { |
218
|
|
|
// すでに登録されていた場合、登録データを表示 |
219
|
|
|
// データベース設定 |
220
|
1 |
|
$config = Yaml::parse(file_get_contents($config_file)); |
221
|
1 |
|
$database = $config['database']; |
222
|
1 |
|
$sessionData['database'] = $database['driver']; |
223
|
1 |
|
if ($database['driver'] != 'pdo_sqlite') { |
224
|
1 |
|
$sessionData['database_host'] = $database['host']; |
225
|
1 |
|
$sessionData['database_port'] = $database['port']; |
226
|
1 |
|
$sessionData['database_name'] = $database['dbname']; |
227
|
1 |
|
$sessionData['database_user'] = $database['user']; |
228
|
1 |
|
$sessionData['database_password'] = $database['password']; |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
233
|
1 |
|
$form->setData($sessionData); |
234
|
|
|
|
235
|
1 |
|
if ($this->isValid($request, $form)) { |
|
|
|
|
236
|
|
|
|
237
|
|
|
return $app->redirect($app->url('install_step5')); |
238
|
|
|
} |
239
|
|
|
|
240
|
1 |
|
return $app['twig']->render('step4.twig', array( |
241
|
1 |
|
'form' => $form->createView(), |
242
|
1 |
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
243
|
|
|
)); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
// データベースの初期化 |
247
|
1 |
|
public function step5(InstallApplication $app, Request $request) |
|
|
|
|
248
|
|
|
{ |
249
|
1 |
|
set_time_limit(0); |
250
|
1 |
|
$this->app = $app; |
251
|
1 |
|
$form = $app['form.factory'] |
252
|
1 |
|
->createBuilder('install_step5') |
253
|
1 |
|
->getForm(); |
254
|
1 |
|
$sessionData = $this->getSessionData($request); |
255
|
1 |
|
$form->setData($sessionData); |
256
|
|
|
|
257
|
1 |
|
if ($this->isValid($request, $form)) { |
|
|
|
|
258
|
|
|
|
259
|
|
|
$this |
260
|
|
|
->createDatabaseYamlFile($sessionData) |
261
|
|
|
->createMailYamlFile($sessionData) |
262
|
|
|
->createPathYamlFile($sessionData, $request); |
263
|
|
|
|
264
|
|
|
if (!$form['no_update']->getData()) { |
265
|
|
|
set_time_limit(0); |
266
|
|
|
$this->createConfigYamlFile($sessionData); |
267
|
|
|
|
268
|
|
|
$this |
269
|
|
|
->setPDO() |
270
|
|
|
->dropTables() |
271
|
|
|
->createTables() |
272
|
|
|
->doMigrate() |
273
|
|
|
->insert(); |
274
|
|
|
} else { |
275
|
|
|
// データベースを初期化しない場合、auth_magicは初期化しない |
276
|
|
|
$this->createConfigYamlFile($sessionData, false); |
277
|
|
|
|
278
|
|
|
$this |
279
|
|
|
->setPDO() |
280
|
|
|
->update(); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
if (isset($sessionData['agree']) && $sessionData['agree'] == '1') { |
285
|
|
|
$host = $request->getSchemeAndHttpHost(); |
286
|
|
|
$basePath = $request->getBasePath(); |
287
|
|
|
$params = array( |
288
|
|
|
'http_url' => $host . $basePath, |
|
|
|
|
289
|
|
|
'shop_name' => $sessionData['shop_name'], |
290
|
|
|
); |
291
|
|
|
|
292
|
|
|
$this->sendAppData($params); |
293
|
|
|
} |
294
|
|
|
$this->addInstallStatus(); |
295
|
|
|
|
296
|
|
|
$request->getSession()->remove(self::SESSION_KEY); |
297
|
|
|
|
298
|
|
|
return $app->redirect($app->url('install_complete')); |
299
|
|
|
} |
300
|
|
|
|
301
|
1 |
|
return $app['twig']->render('step5.twig', array( |
302
|
1 |
|
'form' => $form->createView(), |
303
|
1 |
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
304
|
|
|
)); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
// インストール完了 |
308
|
1 |
|
public function complete(InstallApplication $app, Request $request) |
|
|
|
|
309
|
|
|
{ |
310
|
1 |
|
$config_file = $this->config_path . '/path.yml'; |
|
|
|
|
311
|
1 |
|
$config = Yaml::parse(file_get_contents($config_file)); |
312
|
|
|
|
313
|
1 |
|
$host = $request->getSchemeAndHttpHost(); |
314
|
1 |
|
$basePath = $request->getBasePath(); |
315
|
|
|
|
316
|
1 |
|
$adminUrl = $host . $basePath . '/' . $config['admin_dir']; |
|
|
|
|
317
|
|
|
|
318
|
1 |
|
return $app['twig']->render('complete.twig', array( |
319
|
1 |
|
'admin_url' => $adminUrl, |
320
|
1 |
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
321
|
|
|
)); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
private function resetNatTimer() |
325
|
|
|
{ |
326
|
|
|
// NATの無通信タイマ対策(仮) |
327
|
|
|
echo str_repeat(' ', 4 * 1024); |
328
|
|
|
ob_flush(); |
329
|
|
|
flush(); |
330
|
|
|
} |
331
|
|
|
|
332
|
1 |
|
private function checkModules($app) |
|
|
|
|
333
|
|
|
{ |
334
|
1 |
|
foreach ($this->required_modules as $module) { |
335
|
1 |
|
if (!extension_loaded($module)) { |
336
|
1 |
|
$app->addDanger('[必須] ' . $module . ' 拡張モジュールが有効になっていません。', 'install'); |
|
|
|
|
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
340
|
1 |
|
if (!extension_loaded('pdo_mysql') && !extension_loaded('pdo_pgsql')) { |
341
|
|
|
$app->addDanger('[必須] ' . 'pdo_pgsql又はpdo_mysql 拡張モジュールを有効にしてください。', 'install'); |
|
|
|
|
342
|
|
|
} |
343
|
|
|
|
344
|
1 |
|
foreach ($this->recommended_module as $module) { |
345
|
1 |
|
if (!extension_loaded($module)) { |
346
|
|
|
if ($module == self::MCRYPT && PHP_VERSION_ID >= 70100) { |
347
|
|
|
//The mcrypt extension has been deprecated in PHP 7.1.x |
348
|
|
|
//http://php.net/manual/en/migration71.deprecated.php |
349
|
|
|
continue; |
350
|
|
|
} |
351
|
1 |
|
$app->addInfo('[推奨] '.$module.' 拡張モジュールが有効になっていません。', 'install'); |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
|
355
|
1 |
|
if ('\\' === DIRECTORY_SEPARATOR) { // for Windows |
356
|
|
|
if (!extension_loaded('wincache')) { |
357
|
|
|
$app->addInfo('[推奨] WinCache 拡張モジュールが有効になっていません。', 'install'); |
358
|
|
|
} |
359
|
|
|
} else { |
360
|
1 |
|
if (!extension_loaded('apc')) { |
361
|
1 |
|
$app->addInfo('[推奨] APC 拡張モジュールが有効になっていません。', 'install'); |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
|
365
|
1 |
|
if (isset($_SERVER['SERVER_SOFTWARE']) && strpos('Apache', $_SERVER['SERVER_SOFTWARE']) !== false) { |
366
|
|
|
if (!function_exists('apache_get_modules')) { |
367
|
|
|
$app->addWarning('mod_rewrite が有効になっているか不明です。', 'install'); |
368
|
|
|
} elseif (!in_array('mod_rewrite', apache_get_modules())) { |
369
|
|
|
$app->addDanger('[必須] ' . 'mod_rewriteを有効にしてください。', 'install'); |
|
|
|
|
370
|
|
|
} |
371
|
1 |
|
} elseif (isset($_SERVER['SERVER_SOFTWARE']) && strpos('Microsoft-IIS', $_SERVER['SERVER_SOFTWARE']) !== false) { |
|
|
|
|
372
|
|
|
// iis |
373
|
1 |
|
} elseif (isset($_SERVER['SERVER_SOFTWARE']) && strpos('nginx', $_SERVER['SERVER_SOFTWARE']) !== false) { |
|
|
|
|
374
|
|
|
// nginx |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
378
|
1 |
|
private function setPDO() |
379
|
|
|
{ |
380
|
1 |
|
$config_file = $this->config_path . '/database.yml'; |
|
|
|
|
381
|
1 |
|
$config = Yaml::parse(file_get_contents($config_file)); |
382
|
|
|
|
383
|
|
|
try { |
384
|
1 |
|
$this->PDO = \Doctrine\DBAL\DriverManager::getConnection($config['database'], new \Doctrine\DBAL\Configuration()); |
385
|
1 |
|
$this->PDO->connect(); |
386
|
|
|
} catch (\Exception $e) { |
387
|
|
|
$this->PDO->close(); |
388
|
|
|
throw $e; |
389
|
|
|
} |
390
|
|
|
|
391
|
1 |
|
return $this; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
View Code Duplication |
private function dropTables() |
|
|
|
|
395
|
|
|
{ |
396
|
|
|
$this->resetNatTimer(); |
397
|
|
|
|
398
|
|
|
$em = $this->getEntityManager(); |
399
|
|
|
$metadatas = $em->getMetadataFactory()->getAllMetadata(); |
400
|
|
|
$schemaTool = new SchemaTool($em); |
401
|
|
|
|
402
|
|
|
$schemaTool->dropSchema($metadatas); |
403
|
|
|
|
404
|
|
|
$em->getConnection()->executeQuery('DROP TABLE IF EXISTS doctrine_migration_versions'); |
405
|
|
|
|
406
|
|
|
return $this; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @return EntityManager |
411
|
|
|
*/ |
412
|
|
|
private function getEntityManager() |
413
|
|
|
{ |
414
|
|
|
$config_file = $this->config_path . '/database.yml'; |
|
|
|
|
415
|
|
|
$database = Yaml::parse(file_get_contents($config_file)); |
416
|
|
|
|
417
|
|
|
$this->app->register(new \Silex\Provider\DoctrineServiceProvider(), array( |
|
|
|
|
418
|
|
|
'db.options' => $database['database'] |
419
|
|
|
)); |
420
|
|
|
|
421
|
|
|
$this->app->register(new \Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array( |
|
|
|
|
422
|
|
|
'orm.proxies_dir' => __DIR__ . '/../../app/cache/doctrine', |
|
|
|
|
423
|
|
|
'orm.em.options' => array( |
424
|
|
|
'mappings' => array( |
425
|
|
|
array( |
426
|
|
|
'type' => 'yml', |
427
|
|
|
'namespace' => 'Eccube\Entity', |
428
|
|
|
'path' => array( |
429
|
|
|
__DIR__ . '/../../Resource/doctrine', |
|
|
|
|
430
|
|
|
__DIR__ . '/../../Resource/doctrine/master', |
|
|
|
|
431
|
|
|
), |
432
|
|
|
), |
433
|
|
|
), |
434
|
|
|
) |
435
|
|
|
)); |
436
|
|
|
|
437
|
|
|
return $em = $this->app['orm.em']; |
|
|
|
|
438
|
|
|
} |
439
|
|
|
|
440
|
|
View Code Duplication |
private function createTables() |
|
|
|
|
441
|
|
|
{ |
442
|
|
|
$this->resetNatTimer(); |
443
|
|
|
|
444
|
|
|
$em = $this->getEntityManager(); |
445
|
|
|
$metadatas = $em->getMetadataFactory()->getAllMetadata(); |
446
|
|
|
$schemaTool = new SchemaTool($em); |
447
|
|
|
|
448
|
|
|
$schemaTool->createSchema($metadatas); |
449
|
|
|
|
450
|
|
|
return $this; |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
private function insert() |
454
|
|
|
{ |
455
|
|
|
$this->resetNatTimer(); |
456
|
|
|
|
457
|
|
|
$config_file = $this->config_path . '/database.yml'; |
|
|
|
|
458
|
|
|
$database = Yaml::parse(file_get_contents($config_file)); |
459
|
|
|
$config['database'] = $database['database']; |
|
|
|
|
460
|
|
|
|
461
|
|
|
$config_file = $this->config_path . '/config.yml'; |
|
|
|
|
462
|
|
|
$baseConfig = Yaml::parse(file_get_contents($config_file)); |
463
|
|
|
$config['config'] = $baseConfig; |
464
|
|
|
|
465
|
|
|
$this->PDO->beginTransaction(); |
466
|
|
|
|
467
|
|
|
try { |
|
|
|
|
468
|
|
|
|
469
|
|
|
$config = array( |
470
|
|
|
'auth_type' => '', |
471
|
|
|
'auth_magic' => $config['config']['auth_magic'], |
472
|
|
|
'password_hash_algos' => 'sha256', |
473
|
|
|
); |
474
|
|
|
$passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($config); |
475
|
|
|
$salt = \Eccube\Util\Str::random(32); |
476
|
|
|
|
477
|
|
|
$encodedPassword = $passwordEncoder->encodePassword($this->session_data['login_pass'], $salt); |
478
|
|
|
$sth = $this->PDO->prepare('INSERT INTO dtb_base_info ( |
479
|
|
|
id, |
480
|
|
|
shop_name, |
481
|
|
|
email01, |
482
|
|
|
email02, |
483
|
|
|
email03, |
484
|
|
|
email04, |
485
|
|
|
update_date, |
486
|
|
|
option_product_tax_rule |
487
|
|
|
) VALUES ( |
488
|
|
|
1, |
489
|
|
|
:shop_name, |
490
|
|
|
:admin_mail, |
491
|
|
|
:admin_mail, |
492
|
|
|
:admin_mail, |
493
|
|
|
:admin_mail, |
494
|
|
|
current_timestamp, |
495
|
|
|
0);'); |
496
|
|
|
$sth->execute(array( |
|
|
|
|
497
|
|
|
':shop_name' => $this->session_data['shop_name'], |
498
|
|
|
':admin_mail' => $this->session_data['email'] |
499
|
|
|
)); |
500
|
|
|
|
501
|
|
|
$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) VALUES (2, :login_id, :admin_pass , :salt , '1', '0', '0', '1', '1', current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP');"); |
502
|
|
|
$sth->execute(array(':login_id' => $this->session_data['login_id'], ':admin_pass' => $encodedPassword, ':salt' => $salt)); |
503
|
|
|
|
504
|
|
|
$this->PDO->commit(); |
505
|
|
|
} catch (\Exception $e) { |
506
|
|
|
$this->PDO->rollback(); |
507
|
|
|
throw $e; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
return $this; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
private function update() |
514
|
|
|
{ |
515
|
|
|
$this->resetNatTimer(); |
516
|
|
|
|
517
|
|
|
$config_file = $this->config_path . '/database.yml'; |
|
|
|
|
518
|
|
|
$database = Yaml::parse(file_get_contents($config_file)); |
519
|
|
|
$config['database'] = $database['database']; |
|
|
|
|
520
|
|
|
|
521
|
|
|
$config_file = $this->config_path . '/config.yml'; |
|
|
|
|
522
|
|
|
$baseConfig = Yaml::parse(file_get_contents($config_file)); |
523
|
|
|
$config['config'] = $baseConfig; |
524
|
|
|
|
525
|
|
|
$this->PDO->beginTransaction(); |
526
|
|
|
|
527
|
|
|
try { |
|
|
|
|
528
|
|
|
|
529
|
|
|
$config = array( |
530
|
|
|
'auth_type' => '', |
531
|
|
|
'auth_magic' => $config['config']['auth_magic'], |
532
|
|
|
'password_hash_algos' => 'sha256', |
533
|
|
|
); |
534
|
|
|
$passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($config); |
535
|
|
|
$salt = \Eccube\Util\Str::random(32); |
536
|
|
|
|
537
|
|
|
$stmt = $this->PDO->prepare("SELECT member_id FROM dtb_member WHERE login_id = :login_id;"); |
538
|
|
|
$stmt->execute(array(':login_id' => $this->session_data['login_id'])); |
539
|
|
|
$rs = $stmt->fetch(); |
540
|
|
|
|
541
|
|
|
$encodedPassword = $passwordEncoder->encodePassword($this->session_data['login_pass'], $salt); |
542
|
|
|
|
543
|
|
|
if ($rs) { |
544
|
|
|
// 同一の管理者IDであればパスワードのみ更新 |
545
|
|
|
$sth = $this->PDO->prepare("UPDATE dtb_member set password = :admin_pass, salt = :salt, update_date = current_timestamp WHERE login_id = :login_id;"); |
546
|
|
|
$sth->execute(array(':admin_pass' => $encodedPassword, ':salt' => $salt, ':login_id' => $this->session_data['login_id'])); |
547
|
|
|
} else { |
548
|
|
|
// 新しい管理者IDが入力されたらinsert |
549
|
|
|
$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) VALUES (:login_id, :admin_pass , :salt , '1', '0', '0', '1', '1', current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP');"); |
550
|
|
|
$sth->execute(array(':login_id' => $this->session_data['login_id'], ':admin_pass' => $encodedPassword, ':salt' => $salt)); |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
$sth = $this->PDO->prepare('UPDATE dtb_base_info set |
554
|
|
|
shop_name = :shop_name, |
555
|
|
|
email01 = :admin_mail, |
556
|
|
|
email02 = :admin_mail, |
557
|
|
|
email03 = :admin_mail, |
558
|
|
|
email04 = :admin_mail, |
559
|
|
|
update_date = current_timestamp |
560
|
|
|
WHERE id = 1;'); |
561
|
|
|
$sth->execute(array( |
|
|
|
|
562
|
|
|
':shop_name' => $this->session_data['shop_name'], |
563
|
|
|
':admin_mail' => $this->session_data['email'] |
564
|
|
|
)); |
565
|
|
|
|
566
|
|
|
$this->PDO->commit(); |
567
|
|
|
} catch (\Exception $e) { |
568
|
|
|
$this->PDO->rollback(); |
569
|
|
|
throw $e; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
return $this; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
private function getMigration() |
576
|
|
|
{ |
577
|
|
|
$app = \Eccube\Application::getInstance(); |
578
|
|
|
$app->initialize(); |
579
|
|
|
$app->boot(); |
580
|
|
|
|
581
|
|
|
$config = new Configuration($app['db']); |
582
|
|
|
$config->setMigrationsNamespace('DoctrineMigrations'); |
583
|
|
|
|
584
|
|
|
$migrationDir = __DIR__ . '/../../Resource/doctrine/migration'; |
|
|
|
|
585
|
|
|
$config->setMigrationsDirectory($migrationDir); |
586
|
|
|
$config->registerMigrationsFromDirectory($migrationDir); |
587
|
|
|
|
588
|
|
|
$migration = new Migration($config); |
589
|
|
|
|
590
|
|
|
return $migration; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
private function doMigrate() |
594
|
|
|
{ |
595
|
|
|
try { |
596
|
|
|
$migration = $this->getMigration(); |
597
|
|
|
|
598
|
|
|
// DBとのコネクションを維持するためpingさせる |
599
|
|
|
if (is_null($this->PDO)) { |
600
|
|
|
$this->setPDO(); |
601
|
|
|
} |
602
|
|
|
$this->PDO->ping(); |
603
|
|
|
|
604
|
|
|
// nullを渡すと最新バージョンまでマイグレートする |
605
|
|
|
$migration->migrate(null, false); |
606
|
|
|
} catch (MigrationException $e) { |
|
|
|
|
607
|
|
|
|
|
|
|
|
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
return $this; |
611
|
|
|
} |
612
|
|
|
|
613
|
1 |
|
private function getProtectedDirs() |
614
|
|
|
{ |
615
|
1 |
|
$protectedDirs = array(); |
616
|
1 |
|
$base = __DIR__ . '/../../../..'; |
|
|
|
|
617
|
|
|
$dirs = array( |
618
|
1 |
|
'/html', |
619
|
|
|
'/app', |
620
|
|
|
'/app/template', |
621
|
|
|
'/app/cache', |
622
|
|
|
'/app/config', |
623
|
|
|
'/app/config/eccube', |
624
|
|
|
'/app/log', |
625
|
|
|
'/app/Plugin', |
626
|
|
|
); |
627
|
|
|
|
628
|
1 |
|
foreach ($dirs as $dir) { |
629
|
1 |
|
if (!is_writable($base . $dir)) { |
|
|
|
|
630
|
1 |
|
$protectedDirs[] = $dir; |
631
|
|
|
} |
632
|
|
|
} |
633
|
|
|
|
634
|
1 |
|
return $protectedDirs; |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
private function createConfigYamlFile($data, $auth = true) |
638
|
|
|
{ |
639
|
|
|
$fs = new Filesystem(); |
640
|
|
|
$config_file = $this->config_path . '/config.yml'; |
|
|
|
|
641
|
|
|
|
642
|
|
|
if ($fs->exists($config_file)) { |
643
|
|
|
$config = Yaml::parse(file_get_contents($config_file)); |
644
|
|
|
$fs->remove($config_file); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
if ($auth) { |
648
|
|
|
$auth_magic = Str::random(32); |
649
|
|
|
} else { |
650
|
|
|
if (isset($config['auth_magic'])) { |
651
|
|
|
$auth_magic = $config['auth_magic']; |
652
|
|
|
} else { |
653
|
|
|
$auth_magic = Str::random(32); |
654
|
|
|
} |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
$allowHost = Str::convertLineFeed($data['admin_allow_hosts']); |
658
|
|
|
if (empty($allowHost)) { |
659
|
|
|
$adminAllowHosts = array(); |
660
|
|
|
} else { |
661
|
|
|
$adminAllowHosts = explode("\n", $allowHost); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
$target = array('${AUTH_MAGIC}', '${SHOP_NAME}', '${ECCUBE_INSTALL}', '${FORCE_SSL}'); |
665
|
|
|
$replace = array($auth_magic, $data['shop_name'], '0', $data['admin_force_ssl']); |
666
|
|
|
|
667
|
|
|
$fs = new Filesystem(); |
668
|
|
|
$content = str_replace( |
669
|
|
|
$target, $replace, file_get_contents($this->dist_path . '/config.yml.dist') |
|
|
|
|
670
|
|
|
); |
671
|
|
|
$fs->dumpFile($config_file, $content); |
672
|
|
|
|
673
|
|
|
$config = Yaml::parse(file_get_contents($config_file)); |
674
|
|
|
$config['admin_allow_host'] = $adminAllowHosts; |
675
|
|
|
$yml = Yaml::dump($config); |
676
|
|
|
file_put_contents($config_file, $yml); |
677
|
|
|
|
678
|
|
|
return $this; |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
private function addInstallStatus() |
682
|
|
|
{ |
683
|
|
|
$config_file = $this->config_path . '/config.yml'; |
|
|
|
|
684
|
|
|
$config = Yaml::parse(file_get_contents($config_file)); |
685
|
|
|
$config['eccube_install'] = 1; |
686
|
|
|
$yml = Yaml::dump($config); |
687
|
|
|
file_put_contents($config_file, $yml); |
688
|
|
|
|
689
|
|
|
return $this; |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
private function createDatabaseYamlFile($data) |
693
|
|
|
{ |
694
|
|
|
$fs = new Filesystem(); |
695
|
|
|
$config_file = $this->config_path . '/database.yml'; |
|
|
|
|
696
|
|
|
if ($fs->exists($config_file)) { |
697
|
|
|
$fs->remove($config_file); |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
if ($data['database'] != 'pdo_sqlite') { |
701
|
|
|
switch ($data['database']) |
702
|
|
|
{ |
703
|
|
|
case 'pdo_pgsql': |
704
|
|
|
if (empty($data['db_port'])) { |
705
|
|
|
$data['db_port'] = '5432'; |
706
|
|
|
} |
707
|
|
|
$data['db_driver'] = 'pdo_pgsql'; |
708
|
|
|
break; |
709
|
|
|
case 'pdo_mysql': |
710
|
|
|
if (empty($data['db_port'])) { |
711
|
|
|
$data['db_port'] = '3306'; |
712
|
|
|
} |
713
|
|
|
$data['db_driver'] = 'pdo_mysql'; |
714
|
|
|
break; |
715
|
|
|
} |
716
|
|
|
$target = array('${DBDRIVER}', '${DBSERVER}', '${DBNAME}', '${DBPORT}', '${DBUSER}', '${DBPASS}'); |
717
|
|
|
$replace = array( |
|
|
|
|
718
|
|
|
$data['db_driver'], |
719
|
|
|
$data['database_host'], |
720
|
|
|
$data['database_name'], |
721
|
|
|
$data['database_port'], |
722
|
|
|
$data['database_user'], |
723
|
|
|
$data['database_password'] |
724
|
|
|
); |
725
|
|
|
|
726
|
|
|
$fs = new Filesystem(); |
727
|
|
|
$content = str_replace( |
728
|
|
|
$target, $replace, file_get_contents($this->dist_path . '/database.yml.dist') |
|
|
|
|
729
|
|
|
); |
730
|
|
|
} else { |
731
|
|
|
$content = Yaml::dump( |
732
|
|
|
array( |
|
|
|
|
733
|
|
|
'database' => array( |
|
|
|
|
734
|
|
|
'driver' => 'pdo_sqlite', |
735
|
|
|
'path' => realpath($this->config_path . '/eccube.db') |
|
|
|
|
736
|
|
|
) |
737
|
|
|
) |
738
|
|
|
); |
739
|
|
|
} |
740
|
|
|
$fs->dumpFile($config_file, $content); |
741
|
|
|
|
742
|
|
|
return $this; |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
private function createMailYamlFile($data) |
746
|
|
|
{ |
747
|
|
|
$fs = new Filesystem(); |
748
|
|
|
$config_file = $this->config_path . '/mail.yml'; |
|
|
|
|
749
|
|
|
if ($fs->exists($config_file)) { |
750
|
|
|
$fs->remove($config_file); |
751
|
|
|
} |
752
|
|
|
$target = array('${MAIL_BACKEND}', '${MAIL_HOST}', '${MAIL_PORT}', '${MAIL_USER}', '${MAIL_PASS}'); |
753
|
|
|
$replace = array( |
|
|
|
|
754
|
|
|
$data['mail_backend'], |
755
|
|
|
$data['smtp_host'], |
756
|
|
|
$data['smtp_port'], |
757
|
|
|
$data['smtp_username'], |
758
|
|
|
$data['smtp_password'] |
759
|
|
|
); |
760
|
|
|
|
761
|
|
|
$fs = new Filesystem(); |
762
|
|
|
$content = str_replace( |
763
|
|
|
$target, $replace, file_get_contents($this->dist_path . '/mail.yml.dist') |
|
|
|
|
764
|
|
|
); |
765
|
|
|
$fs->dumpFile($config_file, $content); |
766
|
|
|
|
767
|
|
|
return $this; |
768
|
|
|
} |
769
|
|
|
|
770
|
|
|
private function createPathYamlFile($data, Request $request) |
771
|
|
|
{ |
772
|
|
|
$fs = new Filesystem(); |
773
|
|
|
$config_file = $this->config_path . '/path.yml'; |
|
|
|
|
774
|
|
|
if ($fs->exists($config_file)) { |
775
|
|
|
$fs->remove($config_file); |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
$ADMIN_ROUTE = $data['admin_dir']; |
779
|
|
|
$TEMPLATE_CODE = 'default'; |
780
|
|
|
$USER_DATA_ROUTE = 'user_data'; |
781
|
|
|
$ROOT_DIR = realpath(__DIR__ . '/../../../../'); |
|
|
|
|
782
|
|
|
$ROOT_URLPATH = $request->getBasePath(); |
783
|
|
|
$ROOT_PUBLIC_URLPATH = $ROOT_URLPATH . RELATIVE_PUBLIC_DIR_PATH; |
|
|
|
|
784
|
|
|
|
785
|
|
|
$target = array('${ADMIN_ROUTE}', '${TEMPLATE_CODE}', '${USER_DATA_ROUTE}', '${ROOT_DIR}', '${ROOT_URLPATH}', '${ROOT_PUBLIC_URLPATH}'); |
786
|
|
|
$replace = array($ADMIN_ROUTE, $TEMPLATE_CODE, $USER_DATA_ROUTE, $ROOT_DIR, $ROOT_URLPATH, $ROOT_PUBLIC_URLPATH); |
787
|
|
|
|
788
|
|
|
$fs = new Filesystem(); |
789
|
|
|
$content = str_replace( |
790
|
|
|
$target, $replace, file_get_contents($this->dist_path . '/path.yml.dist') |
|
|
|
|
791
|
|
|
); |
792
|
|
|
$fs->dumpFile($config_file, $content); |
793
|
|
|
|
794
|
|
|
return $this; |
795
|
|
|
} |
796
|
|
|
|
797
|
|
|
private function sendAppData($params) |
798
|
|
|
{ |
799
|
|
|
$config_file = $this->config_path . '/database.yml'; |
|
|
|
|
800
|
|
|
$db_config = Yaml::parse(file_get_contents($config_file)); |
801
|
|
|
|
802
|
|
|
$this->setPDO(); |
803
|
|
|
$stmt = $this->PDO->query('select version() as v'); |
804
|
|
|
|
805
|
|
|
$version = ''; |
806
|
|
|
foreach ($stmt as $row) { |
807
|
|
|
$version = $row['v']; |
808
|
|
|
} |
809
|
|
|
|
810
|
|
|
if ($db_config['database']['driver'] === 'pdo_mysql') { |
811
|
|
|
$db_ver = 'MySQL:' . $version; |
|
|
|
|
812
|
|
|
} else { |
813
|
|
|
$db_ver = $version; |
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
$data = http_build_query( |
817
|
|
|
array( |
818
|
|
|
'site_url' => $params['http_url'], |
819
|
|
|
'shop_name' => $params['shop_name'], |
820
|
|
|
'cube_ver' => Constant::VERSION, |
821
|
|
|
'php_ver' => phpversion(), |
822
|
|
|
'db_ver' => $db_ver, |
823
|
|
|
'os_type' => php_uname(), |
824
|
|
|
) |
825
|
|
|
); |
826
|
|
|
|
827
|
|
|
$header = array( |
828
|
|
|
'Content-Type: application/x-www-form-urlencoded', |
829
|
|
|
'Content-Length: ' . strlen($data), |
|
|
|
|
830
|
|
|
); |
831
|
|
|
$context = stream_context_create( |
832
|
|
|
array( |
|
|
|
|
833
|
|
|
'http' => array( |
834
|
|
|
'method' => 'POST', |
835
|
|
|
'header' => $header, |
836
|
|
|
'content' => $data, |
837
|
|
|
) |
838
|
|
|
) |
839
|
|
|
); |
840
|
|
|
file_get_contents('http://www.ec-cube.net/mall/use_site.php', false, $context); |
841
|
|
|
|
842
|
|
|
return $this; |
843
|
|
|
} |
844
|
|
|
|
845
|
|
|
/** |
846
|
|
|
* マイグレーション画面を表示する. |
847
|
|
|
* |
848
|
|
|
* @param InstallApplication $app |
849
|
|
|
* @param Request $request |
|
|
|
|
850
|
|
|
* |
851
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
852
|
|
|
*/ |
853
|
|
|
public function migration(InstallApplication $app, Request $request) |
|
|
|
|
854
|
|
|
{ |
855
|
|
|
return $app['twig']->render('migration.twig', array( |
856
|
|
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
857
|
|
|
)); |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
/** |
861
|
|
|
* インストール済プラグインの一覧を表示する. |
862
|
|
|
* プラグインがインストールされていない場合は, マイグレーション実行画面へリダイレクトする. |
863
|
|
|
* |
864
|
|
|
* @param InstallApplication $app |
865
|
|
|
* @param Request $request |
|
|
|
|
866
|
|
|
* |
867
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
868
|
|
|
*/ |
869
|
|
|
public function migration_plugin(InstallApplication $app, Request $request) |
|
|
|
|
870
|
|
|
{ |
871
|
|
|
$eccube = \Eccube\Application::getInstance(); |
872
|
|
|
$eccube->initialize(); |
873
|
|
|
$eccube->boot(); |
874
|
|
|
|
875
|
|
|
$pluginRepository = $eccube['orm.em']->getRepository('Eccube\Entity\Plugin'); |
876
|
|
|
$Plugins = $pluginRepository->findBy(array('del_flg' => Constant::DISABLED)); |
877
|
|
|
|
878
|
|
|
if (empty($Plugins)) { |
879
|
|
|
// インストール済プラグインがない場合はマイグレーション実行画面へリダイレクト. |
880
|
|
|
return $app->redirect($app->url('migration_end')); |
881
|
|
|
} else { |
882
|
|
|
return $app['twig']->render('migration_plugin.twig', array( |
883
|
|
|
'Plugins' => $Plugins, |
884
|
|
|
'version' => Constant::VERSION, |
885
|
|
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
886
|
|
|
)); |
887
|
|
|
} |
888
|
|
|
} |
889
|
|
|
|
890
|
|
|
/** |
891
|
|
|
* マイグレーションを実行し, 完了画面を表示させる |
892
|
|
|
* |
893
|
|
|
* @param InstallApplication $app |
894
|
|
|
* @param Request $request |
|
|
|
|
895
|
|
|
* |
896
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
897
|
|
|
*/ |
898
|
|
|
public function migration_end(InstallApplication $app, Request $request) |
|
|
|
|
899
|
|
|
{ |
900
|
|
|
$this->doMigrate(); |
901
|
|
|
|
902
|
|
|
$config_app = new \Eccube\Application(); // install用のappだとconfigが取れないので |
903
|
|
|
$config_app->initialize(); |
904
|
|
|
$config_app->boot(); |
905
|
|
|
\Eccube\Util\Cache::clear($config_app, true); |
906
|
|
|
|
907
|
|
|
return $app['twig']->render('migration_end.twig', array( |
908
|
|
|
'publicPath' => '..' . RELATIVE_PUBLIC_DIR_PATH . '/', |
|
|
|
|
909
|
|
|
)); |
910
|
|
|
} |
911
|
|
|
} |
912
|
|
|
|