refactor: Refactor database and config init (#8527)

* Refactor database and config init
Connect to the database without loading full config
Load config completely so post-processing is always done consistently.
Erase existing $config when loading, fixes issues in case we load the config twice.
If the database is not connected, don't try to load database settings. (Fixes some db errors on install)
Attempt to remove $config access/modification before init.php
Remove usage of db_name, that might not match the connected database.
Centralize db config loading, so we consistently apply db_test database settings.
Many of these changes are influenced by Laravel port.

* Some safety so we don't assign strings to numeric port field
Smooth out phpunit bootstrap

* Fix a couple of scrutinizer warnings.
This commit is contained in:
Tony Murray
2018-04-11 10:15:13 -05:00
committed by Neil Lathwood
parent c09e44aa94
commit d841625f12
15 changed files with 190 additions and 161 deletions

View File

@@ -141,14 +141,13 @@ if (!file_exists(Config::get('install_dir').'/config.php')) {
try {
dbConnect();
// pull in the database config settings
Config::loadFromDatabase();
$validator->ok('Database connection successful', null, 'database');
} catch (\LibreNMS\Exceptions\DatabaseConnectException $e) {
$validator->fail('Error connecting to your database. '.$e->getMessage(), null, 'database');
}
Config::load();
$precheck_complete = true; // disable shutdown function
print_header($validator->getVersions());