If enforcing a charset, DO IT ONLY IF THE DB TYPE IS CORRECT

This commit is contained in:
Johannes Meyer 2021-07-28 09:04:28 +02:00
parent 1b2cd8fdf3
commit 0b6f71c446
6 changed files with 21 additions and 8 deletions

View File

@ -224,7 +224,7 @@ class UserBackend implements ConfigAwareFactory
} }
$resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource); $resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource);
if ($backendType === 'db') { if ($backendType === 'db' && $resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8'; $resourceConfig->charset = 'utf8';
} }

View File

@ -166,7 +166,7 @@ class UserGroupBackend
} }
$resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource); $resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource);
if ($backendType === 'db') { if ($backendType === 'db' && $resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8'; $resourceConfig->charset = 'utf8';
} }

View File

@ -31,7 +31,9 @@ trait Database
$config = new SqlConfig(ResourceFactory::getResourceConfig( $config = new SqlConfig(ResourceFactory::getResourceConfig(
IcingaConfig::app()->get('global', 'config_resource') IcingaConfig::app()->get('global', 'config_resource')
)); ));
if ($config->db === 'mysql') {
$config->charset = 'utf8mb4'; $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

@ -131,7 +131,9 @@ abstract class PreferencesStore
$config->location = Config::resolvePath('preferences'); $config->location = Config::resolvePath('preferences');
} elseif ($type === 'Db') { } elseif ($type === 'Db') {
$resourceConfig = ResourceFactory::getResourceConfig($config->resource); $resourceConfig = ResourceFactory::getResourceConfig($config->resource);
if ($resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8'; $resourceConfig->charset = 'utf8';
}
$config->connection = ResourceFactory::createResource($resourceConfig); $config->connection = ResourceFactory::createResource($resourceConfig);
} }

View File

@ -37,7 +37,10 @@ class PreferencesCommand extends Command
} }
$resourceConfig = ResourceFactory::getResourceConfig($resource); $resourceConfig = ResourceFactory::getResourceConfig($resource);
if ($resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8'; $resourceConfig->charset = 'utf8';
}
$connection = ResourceFactory::createResource($resourceConfig); $connection = ResourceFactory::createResource($resourceConfig);
$preferencesPath = Config::resolvePath('preferences'); $preferencesPath = Config::resolvePath('preferences');

View File

@ -207,7 +207,9 @@ class UserDomainMigration
break; break;
case 'db': case 'db':
$resourceConfig = ResourceFactory::getResourceConfig($config->get('global', 'config_resource')); $resourceConfig = ResourceFactory::getResourceConfig($config->get('global', 'config_resource'));
if ($resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8'; $resourceConfig->charset = 'utf8';
}
/** @var DbConnection $conn */ /** @var DbConnection $conn */
$conn = ResourceFactory::createResource($resourceConfig); $conn = ResourceFactory::createResource($resourceConfig);
@ -292,7 +294,9 @@ class UserDomainMigration
} }
$resourceConfig = ResourceFactory::getResourceConfig($config->resource); $resourceConfig = ResourceFactory::getResourceConfig($config->resource);
if ($resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8'; $resourceConfig->charset = 'utf8';
}
/** @var DbConnection $conn */ /** @var DbConnection $conn */
$conn = ResourceFactory::createResource($resourceConfig); $conn = ResourceFactory::createResource($resourceConfig);
@ -343,7 +347,9 @@ class UserDomainMigration
} }
$resourceConfig = ResourceFactory::getResourceConfig($config->resource); $resourceConfig = ResourceFactory::getResourceConfig($config->resource);
if ($resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8'; $resourceConfig->charset = 'utf8';
}
/** @var DbConnection $conn */ /** @var DbConnection $conn */
$conn = ResourceFactory::createResource($resourceConfig); $conn = ResourceFactory::createResource($resourceConfig);