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 = new PreferenceForm();
$form->setPreferences($user->getPreferences()); $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( $form->setStore(PreferencesStore::create(new ConfigObject(array(
'resource' => $config->config_resource 'resource' => $config->config_resource
)), $user)); )), $user));

View File

@ -37,13 +37,4 @@ class GeneralConfigForm extends ConfigForm
$this->addSubForm($themingConfigForm->create($formData)); $this->addSubForm($themingConfigForm->create($formData));
$this->addSubForm($domainConfigForm->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(); $config = new Config();
} }
if ($config->get('global', 'config_backend', 'db') !== 'none') { $preferencesConfig = new ConfigObject([
$preferencesConfig = new ConfigObject([ 'resource' => $config->get('global', 'config_resource')
'resource' => $config->get('global', 'config_resource') ]);
]);
try { try {
$preferencesStore = PreferencesStore::create($preferencesConfig, $user); $preferencesStore = PreferencesStore::create($preferencesConfig, $user);
$preferences = new Preferences($preferencesStore->load()); $preferences = new Preferences($preferencesStore->load());
} catch (Exception $e) { } catch (Exception $e) {
Logger::error( Logger::error(
new IcingaException( new IcingaException(
'Cannot load preferences for user "%s". An exception was thrown: %s', 'Cannot load preferences for user "%s". An exception was thrown: %s',
$user->getUsername(), $user->getUsername(),
$e $e
) )
); );
$preferences = new Preferences();
}
} else {
$preferences = new Preferences(); $preferences = new Preferences();
} }

View File

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

View File

@ -28,9 +28,7 @@ class GeneralConfigStep extends Step
$config[$section][$property] = $value; $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 { try {
Config::fromArray($config) 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 shown to every user by default.')
: t('An exception\'s stacktrace is hidden from every user by default.') : t('An exception\'s stacktrace is hidden from every user by default.')
) . '</li>' ) . '</li>'
. '<li>' . sprintf( . '<li>' . t('Preferences will be stored using a database.') . '</li>'
$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>'
. '</ul>'; . '</ul>';
$type = $this->data['generalConfig']['logging_log']; $type = $this->data['generalConfig']['logging_log'];