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`.
This commit is contained in:
Sukhwinder Dhillon 2022-05-17 10:14:44 +02:00
parent 9eea738540
commit acc2d2d852

View File

@ -4,10 +4,9 @@
namespace Icinga\Common; namespace Icinga\Common;
use Icinga\Application\Config as IcingaConfig; use Icinga\Application\Config as IcingaConfig;
use Icinga\Data\ResourceFactory; use Icinga\Exception\ConfigurationError;
use ipl\Sql\Config as SqlConfig; use ipl\Sql\Config as SqlConfig;
use ipl\Sql\Connection; use ipl\Sql\Connection;
use LogicException;
use PDO; use PDO;
/** /**
@ -25,12 +24,13 @@ trait Database
protected function getDb() protected function getDb()
{ {
if (! $this->hasDb()) { 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( $config = new SqlConfig(
IcingaConfig::app()->get('global', 'config_resource') IcingaConfig::app()->getSection('db')
)); );
if ($config->db === 'mysql') { if ($config->db === 'mysql') {
$config->charset = 'utf8mb4'; $config->charset = 'utf8mb4';
} }
@ -51,6 +51,6 @@ trait Database
*/ */
protected function hasDb() protected function hasDb()
{ {
return (bool) IcingaConfig::app()->get('global', 'config_resource'); return ! IcingaConfig::app()->getSection('db')->isEmpty();
} }
} }