From 8d10baa35fb61e038fcde42c10ac7633fb65f069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=BD=A6=E6=96=87?= Date: Mon, 6 Apr 2020 19:18:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8Denv?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=AE=89=E8=A3=85=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/install/InstallProjectCommand.php | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/extend/catcher/command/install/InstallProjectCommand.php b/extend/catcher/command/install/InstallProjectCommand.php index 7e5646a..c5bbc23 100644 --- a/extend/catcher/command/install/InstallProjectCommand.php +++ b/extend/catcher/command/install/InstallProjectCommand.php @@ -154,8 +154,13 @@ class InstallProjectCommand extends Command */ protected function secondStep(): void { - if (file_exists(root_path() . '.env')) { + if (file_exists($this->getEnvFilePath())) { $connections = \config('database.connections'); + // 因为 env file 导致安装失败 + if (!$this->databaseLink) { + unlink($this->getEnvFilePath()); + $this->execute($this->input, $this->output); + } [ $connections['mysql']['hostname'], @@ -165,7 +170,9 @@ class InstallProjectCommand extends Command $connections['mysql']['hostport'], $connections['mysql']['charset'], $connections['mysql']['prefix'], - ] = $this->databaseLink; + ] = $this->databaseLink ? : [ + env('mysql.hostname') + ]; \config([ 'connections' => $connections, @@ -283,7 +290,6 @@ class InstallProjectCommand extends Command $this->output->warning(sprintf('create database %s failed,you need create database first by yourself', $database)); } } catch (\Exception $e) { - unlink(root_path() . '.env'); $this->output->error($e->getMessage()); exit(0); } @@ -334,4 +340,15 @@ class InstallProjectCommand extends Command $this->migrateAndSeeds(); } } + + /** + * 获取 env path + * + * @time 2020年04月06日 + * @return string + */ + protected function getEnvFilePath() + { + return root_path() . '.env'; + } }