修改安装命令
This commit is contained in:
parent
e35a76a80e
commit
1ce4c7122a
@ -157,7 +157,9 @@ class BackupCommand extends Command
|
|||||||
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
|
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
|
||||||
];
|
];
|
||||||
|
|
||||||
\config($connections,'database');
|
\config([
|
||||||
|
'connections' => $connections,
|
||||||
|
],'database.connections');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use think\facade\Db;
|
|||||||
class InstallCommand extends Command
|
class InstallCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $dataInstall = true;
|
protected $databaseLink = [];
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
@ -129,6 +129,8 @@ class InstallCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->databaseLink = [$host, $database, $username, $password, $port, $charset, $prefix];
|
||||||
|
|
||||||
$this->generateEnvFile($host, $database, $username, $password, $port, $charset, $prefix);
|
$this->generateEnvFile($host, $database, $username, $password, $port, $charset, $prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,16 +143,28 @@ class InstallCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected function secondStep(): void
|
protected function secondStep(): void
|
||||||
{
|
{
|
||||||
$php = getenv('_');
|
$connections = \config('database.connections');
|
||||||
|
|
||||||
$think = root_path() . DIRECTORY_SEPARATOR . 'think';
|
[
|
||||||
|
$connections['mysql']['hostname'],
|
||||||
|
$connections['mysql']['database'],
|
||||||
|
$connections['mysql']['username'],
|
||||||
|
$connections['mysql']['password'],
|
||||||
|
$connections['mysql']['hostport'],
|
||||||
|
$connections['mysql']['charset'],
|
||||||
|
$connections['mysql']['prefix'],
|
||||||
|
] = $this->databaseLink;
|
||||||
|
|
||||||
|
\config([
|
||||||
|
'connections' => $connections,
|
||||||
|
],'database');
|
||||||
|
|
||||||
foreach (CatchAdmin::getModulesDirectory() as $directory) {
|
foreach (CatchAdmin::getModulesDirectory() as $directory) {
|
||||||
$moduleInfo = CatchAdmin::getModuleInfo($directory);
|
$moduleInfo = CatchAdmin::getModuleInfo($directory);
|
||||||
|
if (is_dir(CatchAdmin::moduleMigrationsDirectory($moduleInfo['alias']))) {
|
||||||
$this->output->info(
|
$output = Console::call('catch-migrate:run', [$moduleInfo['alias']]);
|
||||||
sprintf('module [%s] migrations ', $moduleInfo['alias']) .
|
$this->output->info(sprintf('module [%s] migrations %s', $moduleInfo['alias'], $output->fetch()));
|
||||||
exec(sprintf('%s %s catch-migrate:run %s', $php, $think, $moduleInfo['alias'])));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,6 +206,7 @@ class InstallCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected function generateEnvFile($host, $database, $username, $password, $port, $charset, $prefix): void
|
protected function generateEnvFile($host, $database, $username, $password, $port, $charset, $prefix): void
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$env = \parse_ini_file(root_path() . '.example.env', true);
|
$env = \parse_ini_file(root_path() . '.example.env', true);
|
||||||
|
|
||||||
$env['DATABASE']['HOSTNAME'] = $host;
|
$env['DATABASE']['HOSTNAME'] = $host;
|
||||||
@ -218,7 +233,6 @@ class InstallCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents(root_path() . '.env', $dotEnv);
|
|
||||||
|
|
||||||
if ($this->getEnvFile()) {
|
if ($this->getEnvFile()) {
|
||||||
$this->output->info('env file has been generated');
|
$this->output->info('env file has been generated');
|
||||||
@ -229,6 +243,12 @@ class InstallCommand extends Command
|
|||||||
} else {
|
} else {
|
||||||
$this->output->warning(sprintf('create database %s failed,you need create database first by yourself', $database));
|
$this->output->warning(sprintf('create database %s failed,you need create database first by yourself', $database));
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->output->error($e->getMessage());
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents(root_path() . '.env', $dotEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +46,8 @@ EOT
|
|||||||
}
|
}
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
|
|
||||||
|
// 重置 migrations 在循环冲无法重复使用
|
||||||
|
$this->migrations = null;
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
$output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
|
$output->writeln('<comment>All Done. Took ' . sprintf('%.4fs', $end - $start) . '</comment>');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user