Use Config helper (#10339)

remove usage of global variable
This commit is contained in:
Tony Murray
2019-06-23 00:29:12 -05:00
committed by GitHub
parent 342acf50f1
commit f3ba8947f7
367 changed files with 1589 additions and 1857 deletions

View File

@@ -28,8 +28,6 @@ use LibreNMS\DB\Eloquent;
use LibreNMS\Exceptions\DatabaseConnectException;
use LibreNMS\Util\Snmpsim;
global $config;
$install_dir = realpath(__DIR__ . '/..');
$init_modules = array('web', 'discovery', 'polling', 'nodb');
@@ -73,27 +71,26 @@ if (getenv('DBTEST')) {
$connection->query("CREATE DATABASE IF NOT EXISTS $db_name CHARACTER SET utf8 COLLATE utf8_unicode_ci");
unset($connection); // close connection
\LibreNMS\DB\Eloquent::boot();
\LibreNMS\DB\Eloquent::setStrictMode();
Eloquent::boot();
Eloquent::setStrictMode();
$empty_db = (dbFetchCell("SELECT count(*) FROM `information_schema`.`tables` WHERE `table_type` = 'BASE TABLE' AND `table_schema` = ?", [$db_name]) == 0);
$cmd = $config['install_dir'] . '/build-base.php';
$cmd = Config::get('install_dir') . '/build-base.php';
exec($cmd, $schema);
Config::load(); // reload the config including database config
load_all_os();
register_shutdown_function(function () use ($empty_db, $sql_mode) {
global $config;
\LibreNMS\DB\Eloquent::boot();
Eloquent::boot();
echo "Cleaning database...\n";
$db_name = dbFetchCell('SELECT DATABASE()');
if ($empty_db) {
dbQuery("DROP DATABASE $db_name");
} elseif (isset($config['test_db_name']) && $config['test_db_name'] == $db_name) {
} elseif (Config::get('test_db_name') == $db_name) {
// truncate tables
$tables = dbFetchColumn('SHOW TABLES');