|
@@ -199,19 +199,23 @@ class Install extends Command |
|
@@ -199,19 +199,23 @@ class Install extends Command |
199
|
// 后台入口文件
|
199
|
// 后台入口文件
|
200
|
$adminFile = ROOT_PATH . 'public' . DS . 'admin.php';
|
200
|
$adminFile = ROOT_PATH . 'public' . DS . 'admin.php';
|
201
|
|
201
|
|
202
|
- // 生成数据库Env配置文件
|
|
|
203
|
- $envFile = ROOT_PATH . '.env.sample';
|
|
|
204
|
- $envStr = @file_get_contents($envFile);
|
202
|
+ // 数据库配置文件
|
|
|
203
|
+ $dbConfigFile = APP_PATH . 'database.php';
|
|
|
204
|
+ $config = @file_get_contents($dbConfigFile);
|
205
|
$callback = function ($matches) use ($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase, $mysqlPrefix) {
|
205
|
$callback = function ($matches) use ($mysqlHostname, $mysqlHostport, $mysqlUsername, $mysqlPassword, $mysqlDatabase, $mysqlPrefix) {
|
206
|
$field = "mysql" . ucfirst($matches[1]);
|
206
|
$field = "mysql" . ucfirst($matches[1]);
|
207
|
$replace = $$field;
|
207
|
$replace = $$field;
|
208
|
- return "{$matches[1]} = {$replace}" . PHP_EOL;
|
208
|
+ if ($matches[1] == 'hostport' && $mysqlHostport == 3306) {
|
|
|
209
|
+ $replace = '';
|
|
|
210
|
+ }
|
|
|
211
|
+ return "'{$matches[1]}'{$matches[2]}=>{$matches[3]}Env::get('database.{$matches[1]}', '{$replace}'),";
|
209
|
};
|
212
|
};
|
210
|
- $envConf = preg_replace_callback('/(hostname|database|username|password|hostport|prefix)\s*=\s*(.*?)\n/', $callback, $envStr);
|
213
|
+ $config = preg_replace_callback("/'(hostname|database|username|password|hostport|prefix)'(\s+)=>(\s+)Env::get\((.*)\)\,/", $callback, $config);
|
211
|
|
214
|
|
212
|
- $result = @file_put_contents(ROOT_PATH . '.env', $envConf);
|
215
|
+ // 检测能否成功写入数据库配置
|
|
|
216
|
+ $result = @file_put_contents($dbConfigFile, $config);
|
213
|
if (!$result) {
|
217
|
if (!$result) {
|
214
|
- throw new Exception(__('The current permissions are insufficient to write the file %s', '.env'));
|
218
|
+ throw new Exception(__('The current permissions are insufficient to write the file %s', 'application/database.php'));
|
215
|
}
|
219
|
}
|
216
|
|
220
|
|
217
|
// 变更默认管理员密码
|
221
|
// 变更默认管理员密码
|
|
@@ -275,15 +279,17 @@ class Install extends Command |
|
@@ -275,15 +279,17 @@ class Install extends Command |
275
|
'public' . DS . 'assets' . DS . 'libs'
|
279
|
'public' . DS . 'assets' . DS . 'libs'
|
276
|
];
|
280
|
];
|
277
|
|
281
|
|
|
|
282
|
+ //数据库配置文件
|
|
|
283
|
+ $dbConfigFile = APP_PATH . 'database.php';
|
|
|
284
|
+
|
278
|
if (version_compare(PHP_VERSION, '7.0.0', '<')) {
|
285
|
if (version_compare(PHP_VERSION, '7.0.0', '<')) {
|
279
|
throw new Exception(__("The current version %s is too low, please use PHP 7.0 or higher", PHP_VERSION));
|
286
|
throw new Exception(__("The current version %s is too low, please use PHP 7.0 or higher", PHP_VERSION));
|
280
|
}
|
287
|
}
|
281
|
if (!extension_loaded("PDO")) {
|
288
|
if (!extension_loaded("PDO")) {
|
282
|
throw new Exception(__("PDO is not currently installed and cannot be installed"));
|
289
|
throw new Exception(__("PDO is not currently installed and cannot be installed"));
|
283
|
}
|
290
|
}
|
284
|
- $envConfFile = ROOT_PATH . '.env';
|
|
|
285
|
- if (is_file($envConfFile) && !is_really_writable($envConfFile)) {
|
|
|
286
|
- throw new Exception(__('The current permissions are insufficient to write the file %s', '.env'));
|
291
|
+ if (!is_really_writable($dbConfigFile)) {
|
|
|
292
|
+ throw new Exception(__('The current permissions are insufficient to write the configuration file application/database.php'));
|
287
|
}
|
293
|
}
|
288
|
foreach ($checkDirs as $k => $v) {
|
294
|
foreach ($checkDirs as $k => $v) {
|
289
|
if (!is_dir(ROOT_PATH . $v)) {
|
295
|
if (!is_dir(ROOT_PATH . $v)) {
|