summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2018-10-12 15:12:54 +0100
committerGreg Roach <fisharebest@webtrees.net>2018-10-12 15:12:54 +0100
commitd214f814b3f4d5841cf5f78ec42143a4c98c7f7d (patch)
tree88af6c6f65b7c886f0b48deb19d3eeef46aa5513 /index.php
parent5d7e82e289cb062fbcf8b15023a93a725c048235 (diff)
downloadwebtrees-d214f814b3f4d5841cf5f78ec42143a4c98c7f7d.tar.gz
webtrees-d214f814b3f4d5841cf5f78ec42143a4c98c7f7d.tar.bz2
webtrees-d214f814b3f4d5841cf5f78ec42143a4c98c7f7d.zip
Add error handler for invalid config.ini.php
Diffstat (limited to 'index.php')
-rw-r--r--index.php29
1 files changed, 18 insertions, 11 deletions
diff --git a/index.php b/index.php
index 7fd76f9fad..ca92b9e90e 100644
--- a/index.php
+++ b/index.php
@@ -117,22 +117,29 @@ set_error_handler(function (int $errno, string $errstr, string $errfile, int $er
DebugBar::startMeasure('init database');
-// Load our configuration file, so we can connect to the database
const WT_CONFIG_FILE = 'data/config.ini.php';
-if (!file_exists(WT_ROOT . WT_CONFIG_FILE)) {
- // No config file. Set one up.
- define('WT_DATA_DIR', 'data/');
- $request = Request::createFromGlobals();
- $response = (new SetupController())->setup($request);
- $response->prepare($request)->send();
-
- return;
-}
// Connect to the database
try {
+ // No config file? Run the setup wizard
+ if (!file_exists(WT_ROOT . WT_CONFIG_FILE)) {
+ define('WT_DATA_DIR', 'data/');
+ $request = Request::createFromGlobals();
+ $controller = new SetupController();
+ $response = $controller->setup($request);
+ $response->prepare($request)->send();
+
+ return;
+ }
+
+ $database_config = parse_ini_file(WT_ROOT . WT_CONFIG_FILE);
+
+ if ($database_config === false) {
+ throw new Exception('Invalid config file: ' . WT_CONFIG_FILE);
+ }
+
// Read the connection settings and create the database
- Database::createInstance(parse_ini_file(WT_ROOT . 'data/config.ini.php'));
+ Database::createInstance($database_config);
// Update the database schema, if necessary.
Database::updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', WT_SCHEMA_VERSION);