修复:全新环境切换共享系统数据库
This commit is contained in:
parent
614dfeb9b0
commit
53537bb9ee
@ -384,9 +384,15 @@ class SystemDatabaseConfiguration
|
||||
|
||||
protected function runFreshVerification(string $command): void
|
||||
{
|
||||
// 当前网页/Artisan 进程启动时,Laravel Dotenv 已把旧数据库值放进
|
||||
// 进程环境。若直接启动子进程,Symfony Process 会继承这些旧值,
|
||||
// 新进程便不会读取刚写入 .env 的共享库配置,导致全新环境必然误判
|
||||
// 为 bootstrap 并回滚。显式移除本次切换涉及的键,让子进程以磁盘
|
||||
// 上最新(或刚恢复)的 .env 为唯一事实来源。
|
||||
$process = new Process(
|
||||
[PHP_BINARY, base_path('artisan'), $command, '--no-ansi', '--quiet'],
|
||||
base_path()
|
||||
base_path(),
|
||||
$this->freshVerificationEnvironment()
|
||||
);
|
||||
$process->setTimeout(60);
|
||||
$process->run();
|
||||
@ -396,6 +402,28 @@ class SystemDatabaseConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, false>
|
||||
*/
|
||||
protected function freshVerificationEnvironment(): array
|
||||
{
|
||||
return array_fill_keys([
|
||||
'DB_CONNECTION',
|
||||
'DB_HOST',
|
||||
'DB_PORT',
|
||||
'DB_DATABASE',
|
||||
'DB_USERNAME',
|
||||
'DB_PASSWORD',
|
||||
'DB_PREFIX',
|
||||
'MYSQL_ATTR_SSL_CIPHER',
|
||||
'MYSQL_ATTR_SSL_CA',
|
||||
'MYSQL_ATTR_SSL_VERIFY_SERVER_CERT',
|
||||
'SYSTEM_DATABASE_MODE',
|
||||
'UPSTREAM_STORED_CONFIG_ENABLED',
|
||||
'UPSTREAM_LOCAL_CONFIG_ENABLED',
|
||||
], false);
|
||||
}
|
||||
|
||||
private function quoteIdentifier(string $identifier): string
|
||||
{
|
||||
return '`' . str_replace('`', '``', $identifier) . '`';
|
||||
|
||||
@ -87,4 +87,29 @@ class SystemDatabasePersistenceTest extends TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_fresh_verification_does_not_inherit_stale_database_environment(): void
|
||||
{
|
||||
$configuration = new class extends SystemDatabaseConfiguration {
|
||||
public function verificationEnvironment(): array
|
||||
{
|
||||
return $this->freshVerificationEnvironment();
|
||||
}
|
||||
};
|
||||
|
||||
$environment = $configuration->verificationEnvironment();
|
||||
|
||||
foreach ([
|
||||
'DB_HOST',
|
||||
'DB_DATABASE',
|
||||
'DB_PASSWORD',
|
||||
'DB_PREFIX',
|
||||
'SYSTEM_DATABASE_MODE',
|
||||
'UPSTREAM_STORED_CONFIG_ENABLED',
|
||||
'UPSTREAM_LOCAL_CONFIG_ENABLED',
|
||||
] as $key) {
|
||||
$this->assertArrayHasKey($key, $environment);
|
||||
$this->assertFalse($environment[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user