diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2018-10-12 15:12:54 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2018-10-12 15:12:54 +0100 |
| commit | d214f814b3f4d5841cf5f78ec42143a4c98c7f7d (patch) | |
| tree | 88af6c6f65b7c886f0b48deb19d3eeef46aa5513 /index.php | |
| parent | 5d7e82e289cb062fbcf8b15023a93a725c048235 (diff) | |
| download | webtrees-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.php | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -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); |
