Remove obsolete `config_backend` option and not required code

The user preferences backend is now always a `db`.
This commit is contained in:
Sukhwinder Dhillon 2022-05-03 10:16:27 +02:00 committed by Johannes Meyer
parent e7c368b09d
commit aad2419545
5 changed files with 50 additions and 99 deletions

View File

@ -69,7 +69,7 @@ class AccountController extends Controller
$form = new PreferenceForm();
$form->setPreferences($user->getPreferences());
if ($config->get('config_backend', 'db') !== 'none' && isset($config->config_resource)) {
if (isset($config->config_resource)) {
$form->setStore(PreferencesStore::create(new ConfigObject(array(
'resource' => $config->config_resource
)), $user));

View File

@ -37,13 +37,4 @@ class GeneralConfigForm extends ConfigForm
$this->addSubForm($themingConfigForm->create($formData));
$this->addSubForm($domainConfigForm->create($formData));
}
public function onRequest()
{
parent::onRequest();
if ($this->config->get('global', 'config_backend') === 'ini') {
$this->warning('The preferences backend of type INI is deprecated and will be removed with version 2.11');
}
}
}

View File

@ -376,25 +376,21 @@ class Auth
$config = new Config();
}
if ($config->get('global', 'config_backend', 'db') !== 'none') {
$preferencesConfig = new ConfigObject([
'resource' => $config->get('global', 'config_resource')
]);
$preferencesConfig = new ConfigObject([
'resource' => $config->get('global', 'config_resource')
]);
try {
$preferencesStore = PreferencesStore::create($preferencesConfig, $user);
$preferences = new Preferences($preferencesStore->load());
} catch (Exception $e) {
Logger::error(
new IcingaException(
'Cannot load preferences for user "%s". An exception was thrown: %s',
$user->getUsername(),
$e
)
);
$preferences = new Preferences();
}
} else {
try {
$preferencesStore = PreferencesStore::create($preferencesConfig, $user);
$preferences = new Preferences($preferencesStore->load());
} catch (Exception $e) {
Logger::error(
new IcingaException(
'Cannot load preferences for user "%s". An exception was thrown: %s',
$user->getUsername(),
$e
)
);
$preferences = new Preferences();
}

View File

@ -178,80 +178,51 @@ class UserDomainMigration
{
$config = Config::app();
$type = $config->get('global', 'config_backend', 'ini');
$resourceConfig = ResourceFactory::getResourceConfig($config->get('global', 'config_resource'));
if ($resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8mb4';
}
switch ($type) {
case 'ini':
$directory = Config::resolvePath('preferences');
/** @var DbConnection $conn */
$conn = ResourceFactory::createResource($resourceConfig);
$migration = array();
$query = $conn
->select()
->from('icingaweb_user_preference', array('username'))
->group('username');
if (DirectoryIterator::isReadable($directory)) {
foreach (new DirectoryIterator($directory) as $username => $path) {
$user = new User($username);
if ($this->map !== null) {
$query->applyFilter(Filter::matchAny(Filter::where('username', array_keys($this->map))));
}
if (! $this->mustMigrate($user)) {
continue;
}
$users = $query->fetchColumn();
$migrated = $this->migrateUser($user);
$migration = array();
$migration[$path] = dirname($path) . '/' . $migrated->getUsername();
}
foreach ($users as $username) {
$user = new User($username);
foreach ($migration as $from => $to) {
rename($from, $to);
}
}
if (! $this->mustMigrate($user)) {
continue;
}
break;
case 'db':
$resourceConfig = ResourceFactory::getResourceConfig($config->get('global', 'config_resource'));
if ($resourceConfig->db === 'mysql') {
$resourceConfig->charset = 'utf8mb4';
}
$migrated = $this->migrateUser($user);
/** @var DbConnection $conn */
$conn = ResourceFactory::createResource($resourceConfig);
$migration[$username] = $migrated->getUsername();
}
$query = $conn
->select()
->from('icingaweb_user_preference', array('username'))
->group('username');
if (! empty($migration)) {
$conn->getDbAdapter()->beginTransaction();
if ($this->map !== null) {
$query->applyFilter(Filter::matchAny(Filter::where('username', array_keys($this->map))));
}
foreach ($migration as $originalUsername => $username) {
$conn->update(
'icingaweb_user_preference',
array('username' => $username),
Filter::where('username', $originalUsername)
);
}
$users = $query->fetchColumn();
$migration = array();
foreach ($users as $username) {
$user = new User($username);
if (! $this->mustMigrate($user)) {
continue;
}
$migrated = $this->migrateUser($user);
$migration[$username] = $migrated->getUsername();
}
if (! empty($migration)) {
$conn->getDbAdapter()->beginTransaction();
foreach ($migration as $originalUsername => $username) {
$conn->update(
'icingaweb_user_preference',
array('username' => $username),
Filter::where('username', $originalUsername)
);
}
$conn->getDbAdapter()->commit();
}
$conn->getDbAdapter()->commit();
}
}

View File

@ -28,9 +28,7 @@ class GeneralConfigStep extends Step
$config[$section][$property] = $value;
}
if ($config['global']['config_backend'] === 'db') {
$config['global']['config_resource'] = $this->data['resourceName'];
}
$config['global']['config_resource'] = $this->data['resourceName'];
try {
Config::fromArray($config)
@ -57,12 +55,7 @@ class GeneralConfigStep extends Step
? t('An exception\'s stacktrace is shown to every user by default.')
: t('An exception\'s stacktrace is hidden from every user by default.')
) . '</li>'
. '<li>' . sprintf(
$this->data['generalConfig']['global_config_backend'] === 'ini' ? sprintf(
t('Preferences will be stored per user account in INI files at: %s'),
Config::resolvePath('preferences')
) : t('Preferences will be stored using a database.')
) . '</li>'
. '<li>' . t('Preferences will be stored using a database.') . '</li>'
. '</ul>';
$type = $this->data['generalConfig']['logging_log'];