More specific "database missing" error message

It's misleading to imply that an .env doesn't exist when it's not what the actual check looks for.
It's also poor design to hardcode an unrelated error message in a "redirect to installer" function,
which only worked because this function was called from exactly one other place where this
error message was correct.
This commit is contained in:
Ingo Schommer 2020-11-12 13:29:12 +13:00
parent b271d9dd89
commit 6306d2ede3
1 changed files with 9 additions and 4 deletions

View File

@ -270,8 +270,10 @@ class CoreKernel implements Kernel
$databaseConfig = DB::getConfig();
// Gracefully fail if no DB is configured
if (empty($databaseConfig['database'])) {
$msg = 'SilverStripe Framework requires a "database" key in DB::getConfig(). ' .
'Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?';
$this->detectLegacyEnvironment();
$this->redirectToInstaller();
$this->redirectToInstaller($msg);
}
}
@ -311,14 +313,17 @@ class CoreKernel implements Kernel
}
/**
* If missing configuration, redirect to install.php
* If missing configuration, redirect to install.php if it exists.
* Otherwise show a server error to the user.
*
* @param string $msg Optional message to show to the user on an installed project (install.php missing).
*/
protected function redirectToInstaller()
protected function redirectToInstaller($msg = '')
{
// Error if installer not available
if (!file_exists(Director::publicFolder() . '/install.php')) {
throw new HTTPResponse_Exception(
'SilverStripe Framework requires database configuration defined via .env',
$msg,
500
);
}