mirror of https://gitee.com/karson/fastadmin.git
commit
d54583e946
|
|
@ -43,8 +43,7 @@ class Install extends Command
|
||||||
$password = $input->getOption('password');
|
$password = $input->getOption('password');
|
||||||
|
|
||||||
$installLockFile = __DIR__ . "/Install/install.lock";
|
$installLockFile = __DIR__ . "/Install/install.lock";
|
||||||
if (is_file($installLockFile) && !$force)
|
if (is_file($installLockFile) && !$force) {
|
||||||
{
|
|
||||||
throw new Exception("\nFastAdmin already installed!\nIf you need to reinstall again, use the parameter --force=true ");
|
throw new Exception("\nFastAdmin already installed!\nIf you need to reinstall again, use the parameter --force=true ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,21 +57,30 @@ class Install extends Command
|
||||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
$pdo->query("CREATE DATABASE IF NOT EXISTS `{$database}` CHARACTER SET utf8 COLLATE utf8_general_ci;");
|
$pdo->query("CREATE DATABASE IF NOT EXISTS `{$database}` CHARACTER SET utf8 COLLATE utf8_general_ci;");
|
||||||
|
|
||||||
|
// 连接install命令中指定的数据库
|
||||||
|
$instance = Db::connect([
|
||||||
|
'type' => "{$config['type']}",
|
||||||
|
'hostname' => "{$hostname}",
|
||||||
|
'hostport' => "{$hostport}",
|
||||||
|
'database' => "{$database}",
|
||||||
|
'username' => "{$username}",
|
||||||
|
'password' => "{$password}",
|
||||||
|
]);
|
||||||
|
|
||||||
// 查询一次SQL,判断连接是否正常
|
// 查询一次SQL,判断连接是否正常
|
||||||
Db::execute("SELECT 1");
|
$instance->execute("SELECT 1");
|
||||||
|
|
||||||
// 调用原生PDO对象进行批量查询
|
// 调用原生PDO对象进行批量查询
|
||||||
Db::getPdo()->exec($sql);
|
$instance->getPdo()->exec($sql);
|
||||||
|
|
||||||
file_put_contents($installLockFile, 1);
|
file_put_contents($installLockFile, 1);
|
||||||
|
|
||||||
$dbConfigFile = APP_PATH . 'database.php';
|
$dbConfigFile = APP_PATH . 'database.php';
|
||||||
$config = @file_get_contents($dbConfigFile);
|
$config = @file_get_contents($dbConfigFile);
|
||||||
$callback = function($matches) use($hostname, $hostport, $username, $password, $database, $prefix) {
|
$callback = function ($matches) use ($hostname, $hostport, $username, $password, $database, $prefix) {
|
||||||
$field = $matches[1];
|
$field = $matches[1];
|
||||||
$replace = $$field;
|
$replace = $$field;
|
||||||
if ($matches[1] == 'hostport' && $hostport == 3306)
|
if ($matches[1] == 'hostport' && $hostport == 3306) {
|
||||||
{
|
|
||||||
$replace = '';
|
$replace = '';
|
||||||
}
|
}
|
||||||
return "'{$matches[1]}'{$matches[2]}=>{$matches[3]}Env::get('database.{$matches[1]}', '{$replace}'),";
|
return "'{$matches[1]}'{$matches[2]}=>{$matches[3]}Env::get('database.{$matches[1]}', '{$replace}'),";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue