From 6306d2ede3baaf954bc6c94d2f94d8dd6342ede4 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 12 Nov 2020 13:29:12 +1300 Subject: [PATCH] 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. --- src/Core/CoreKernel.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Core/CoreKernel.php b/src/Core/CoreKernel.php index d22a9b7f4..2b25428a5 100644 --- a/src/Core/CoreKernel.php +++ b/src/Core/CoreKernel.php @@ -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 ); }