From acc2d2d85235a8b262b632ea2e5e0c5797722c0d Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 17 May 2022 10:14:44 +0200 Subject: [PATCH] Database: Read sql config from section `[db]` of `config.ini` Since the whole `resources.ini` should be stored in the db in the future, the main configuration of the icingaweb2 database is moved to the `config.ini`. --- library/Icinga/Common/Database.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/Icinga/Common/Database.php b/library/Icinga/Common/Database.php index 4c977653c..c0c1789ed 100644 --- a/library/Icinga/Common/Database.php +++ b/library/Icinga/Common/Database.php @@ -4,10 +4,9 @@ namespace Icinga\Common; use Icinga\Application\Config as IcingaConfig; -use Icinga\Data\ResourceFactory; +use Icinga\Exception\ConfigurationError; use ipl\Sql\Config as SqlConfig; use ipl\Sql\Connection; -use LogicException; use PDO; /** @@ -25,12 +24,13 @@ trait Database protected function getDb() { if (! $this->hasDb()) { - throw new LogicException('Please check if a db instance exists at all'); + throw new ConfigurationError('Cannot load resource config "db". Resource does not exist'); } - $config = new SqlConfig(ResourceFactory::getResourceConfig( - IcingaConfig::app()->get('global', 'config_resource') - )); + $config = new SqlConfig( + IcingaConfig::app()->getSection('db') + ); + if ($config->db === 'mysql') { $config->charset = 'utf8mb4'; } @@ -51,6 +51,6 @@ trait Database */ protected function hasDb() { - return (bool) IcingaConfig::app()->get('global', 'config_resource'); + return ! IcingaConfig::app()->getSection('db')->isEmpty(); } }