Merge pull request #4484 from Icinga/fix/enforce-charset-on-internal-db-queries-4446

Enforce charset on internal db queries
This commit is contained in:
Johannes Meyer 2021-07-26 17:27:21 +02:00 committed by GitHub
commit 88f2c50f0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 7 deletions

View File

@ -223,7 +223,12 @@ class UserBackend implements ConfigAwareFactory
); );
} }
$resource = ResourceFactory::create($backendConfig->resource); $resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource);
if ($backendType === 'db') {
$resourceConfig->charset = 'utf8';
}
$resource = ResourceFactory::createResource($resourceConfig);
switch ($backendType) { switch ($backendType) {
case 'db': case 'db':
$backend = new DbUserBackend($resource); $backend = new DbUserBackend($resource);

View File

@ -164,8 +164,13 @@ class UserGroupBackend
$name $name
); );
} }
$resource = ResourceFactory::create($backendConfig->resource);
$resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource);
if ($backendType === 'db') {
$resourceConfig->charset = 'utf8';
}
$resource = ResourceFactory::createResource($resourceConfig);
switch ($backendType) { switch ($backendType) {
case 'db': case 'db':
$backend = new DbUserGroupBackend($resource); $backend = new DbUserGroupBackend($resource);

View File

@ -31,6 +31,7 @@ trait Database
$config = new SqlConfig(ResourceFactory::getResourceConfig( $config = new SqlConfig(ResourceFactory::getResourceConfig(
IcingaConfig::app()->get('global', 'config_resource') IcingaConfig::app()->get('global', 'config_resource')
)); ));
$config->charset = 'utf8mb4';
$config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ]; $config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ];
if ($config->db === 'mysql') { if ($config->db === 'mysql') {

View File

@ -130,7 +130,10 @@ abstract class PreferencesStore
Logger::warning('The preferences backend of type INI is deprecated and will be removed with version 2.11'); Logger::warning('The preferences backend of type INI is deprecated and will be removed with version 2.11');
$config->location = Config::resolvePath('preferences'); $config->location = Config::resolvePath('preferences');
} elseif ($type === 'Db') { } elseif ($type === 'Db') {
$config->connection = new DbConnection(ResourceFactory::getResourceConfig($config->resource)); $resourceConfig = ResourceFactory::getResourceConfig($config->resource);
$resourceConfig->charset = 'utf8';
$config->connection = ResourceFactory::createResource($resourceConfig);
} }
return new $storeClass($config, $user); return new $storeClass($config, $user);

View File

@ -35,7 +35,9 @@ class PreferencesCommand extends Command
$resource = $this->params->getRequired('resource'); $resource = $this->params->getRequired('resource');
} }
$connection = ResourceFactory::create($resource); $resourceConfig = ResourceFactory::getResourceConfig($resource);
$resourceConfig->charset = 'utf8';
$connection = ResourceFactory::createResource($resourceConfig);
$preferencesPath = Config::resolvePath('preferences'); $preferencesPath = Config::resolvePath('preferences');
if (! file_exists($preferencesPath)) { if (! file_exists($preferencesPath)) {

View File

@ -206,8 +206,11 @@ class UserDomainMigration
break; break;
case 'db': case 'db':
$resourceConfig = ResourceFactory::getResourceConfig($config->get('global', 'config_resource'));
$resourceConfig->charset = 'utf8';
/** @var DbConnection $conn */ /** @var DbConnection $conn */
$conn = ResourceFactory::create($config->get('global', 'config_resource')); $conn = ResourceFactory::createResource($resourceConfig);
$query = $conn $query = $conn
->select() ->select()
@ -288,8 +291,11 @@ class UserDomainMigration
continue; continue;
} }
$resourceConfig = ResourceFactory::getResourceConfig($config->resource);
$resourceConfig->charset = 'utf8';
/** @var DbConnection $conn */ /** @var DbConnection $conn */
$conn = ResourceFactory::create($config->resource); $conn = ResourceFactory::createResource($resourceConfig);
$query = $conn $query = $conn
->select() ->select()
@ -336,8 +342,11 @@ class UserDomainMigration
continue; continue;
} }
$resourceConfig = ResourceFactory::getResourceConfig($config->resource);
$resourceConfig->charset = 'utf8';
/** @var DbConnection $conn */ /** @var DbConnection $conn */
$conn = ResourceFactory::create($config->resource); $conn = ResourceFactory::createResource($resourceConfig);
$query = $conn $query = $conn
->select() ->select()