From 7ce37783780aed02eb9e67c90645d6cdea334ef6 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 26 Jul 2021 16:36:03 +0200 Subject: [PATCH 1/6] UserBackend: Always use `utf8` as db connection charset --- library/Icinga/Authentication/User/UserBackend.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Authentication/User/UserBackend.php b/library/Icinga/Authentication/User/UserBackend.php index 954356819..13e688795 100644 --- a/library/Icinga/Authentication/User/UserBackend.php +++ b/library/Icinga/Authentication/User/UserBackend.php @@ -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) { case 'db': $backend = new DbUserBackend($resource); From 517c108cc4a83cd14d9f02beec300a5c481ab771 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 26 Jul 2021 16:36:26 +0200 Subject: [PATCH 2/6] UserGroupBackend: Always use `utf8` as db connection charset --- .../Icinga/Authentication/UserGroup/UserGroupBackend.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Authentication/UserGroup/UserGroupBackend.php b/library/Icinga/Authentication/UserGroup/UserGroupBackend.php index 6513002f5..2a5948823 100644 --- a/library/Icinga/Authentication/UserGroup/UserGroupBackend.php +++ b/library/Icinga/Authentication/UserGroup/UserGroupBackend.php @@ -164,8 +164,13 @@ class UserGroupBackend $name ); } - $resource = ResourceFactory::create($backendConfig->resource); + $resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource); + if ($backendType === 'db') { + $resourceConfig->charset = 'utf8'; + } + + $resource = ResourceFactory::createResource($resourceConfig); switch ($backendType) { case 'db': $backend = new DbUserGroupBackend($resource); From 62f1fe2c3f1b8607084f7c2c5c459b41f480421e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 26 Jul 2021 16:36:48 +0200 Subject: [PATCH 3/6] PreferencesStore: Always use `utf8` as db connection charset --- library/Icinga/User/Preferences/PreferencesStore.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/Icinga/User/Preferences/PreferencesStore.php b/library/Icinga/User/Preferences/PreferencesStore.php index c88cf332d..b6d63a9ad 100644 --- a/library/Icinga/User/Preferences/PreferencesStore.php +++ b/library/Icinga/User/Preferences/PreferencesStore.php @@ -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'); $config->location = Config::resolvePath('preferences'); } 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); From aee82ad342b8fad9fb2040cef5457a7273313770 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 26 Jul 2021 16:37:11 +0200 Subject: [PATCH 4/6] Database: Always use `utf8mb4` as connection charset --- library/Icinga/Common/Database.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/Icinga/Common/Database.php b/library/Icinga/Common/Database.php index 32d21153f..fbe1e0260 100644 --- a/library/Icinga/Common/Database.php +++ b/library/Icinga/Common/Database.php @@ -31,6 +31,7 @@ trait Database $config = new SqlConfig(ResourceFactory::getResourceConfig( IcingaConfig::app()->get('global', 'config_resource') )); + $config->charset = 'utf8mb4'; $config->options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ]; if ($config->db === 'mysql') { From e8ae6c912d587ee72de0841a8fdbb43224de5ab2 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 26 Jul 2021 16:54:22 +0200 Subject: [PATCH 5/6] PreferencesCommand: Always use `utf8` as connection charset --- .../migrate/application/clicommands/PreferencesCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/migrate/application/clicommands/PreferencesCommand.php b/modules/migrate/application/clicommands/PreferencesCommand.php index 65f2b43da..fa2bad50c 100644 --- a/modules/migrate/application/clicommands/PreferencesCommand.php +++ b/modules/migrate/application/clicommands/PreferencesCommand.php @@ -35,7 +35,9 @@ class PreferencesCommand extends Command $resource = $this->params->getRequired('resource'); } - $connection = ResourceFactory::create($resource); + $resourceConfig = ResourceFactory::getResourceConfig($resource); + $resourceConfig->charset = 'utf8'; + $connection = ResourceFactory::createResource($resourceConfig); $preferencesPath = Config::resolvePath('preferences'); if (! file_exists($preferencesPath)) { From 571f59be46af898181eb4dbbd53dc1b1d4956de8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 26 Jul 2021 16:54:45 +0200 Subject: [PATCH 6/6] UserDomainMigration: Always use `utf8` as connection charset --- .../Migrate/Config/UserDomainMigration.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/migrate/library/Migrate/Config/UserDomainMigration.php b/modules/migrate/library/Migrate/Config/UserDomainMigration.php index d56722b4e..5edc93722 100644 --- a/modules/migrate/library/Migrate/Config/UserDomainMigration.php +++ b/modules/migrate/library/Migrate/Config/UserDomainMigration.php @@ -206,8 +206,11 @@ class UserDomainMigration break; case 'db': + $resourceConfig = ResourceFactory::getResourceConfig($config->get('global', 'config_resource')); + $resourceConfig->charset = 'utf8'; + /** @var DbConnection $conn */ - $conn = ResourceFactory::create($config->get('global', 'config_resource')); + $conn = ResourceFactory::createResource($resourceConfig); $query = $conn ->select() @@ -288,8 +291,11 @@ class UserDomainMigration continue; } + $resourceConfig = ResourceFactory::getResourceConfig($config->resource); + $resourceConfig->charset = 'utf8'; + /** @var DbConnection $conn */ - $conn = ResourceFactory::create($config->resource); + $conn = ResourceFactory::createResource($resourceConfig); $query = $conn ->select() @@ -336,8 +342,11 @@ class UserDomainMigration continue; } + $resourceConfig = ResourceFactory::getResourceConfig($config->resource); + $resourceConfig->charset = 'utf8'; + /** @var DbConnection $conn */ - $conn = ResourceFactory::create($config->resource); + $conn = ResourceFactory::createResource($resourceConfig); $query = $conn ->select()