Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop ini backend support #4765

Merged
merged 16 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions application/controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ public function indexAction()

$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(
'store' => $config->get('config_backend', 'db'),
'resource' => $config->config_resource
)), $user));
}
Expand Down
66 changes: 16 additions & 50 deletions application/forms/Config/General/ApplicationConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,57 +70,23 @@ public function createElements(array $formData)
)
);

// we do not need this form for setup because we set the database there as default.
// this form is only displayed in configuration -> application if preferences backend type of ini is recognized
if (isset($formData['global_config_backend']) && $formData['global_config_backend'] === 'ini') {
$this->addElement(
'select',
'global_config_backend',
[
'required' => true,
'autosubmit' => true,
'label' => $this->translate('User Preference Storage Type'),
'multiOptions' => [
'ini' => $this->translate('File System (INI Files)'),
'db' => $this->translate('Database')
]
]
);
} else {
$this->addElement(
'hidden',
'global_config_backend',
[
'required' => true,
'value' => 'db',
'disabled' => true
]
);
}
$backends = array_keys(ResourceFactory::getResourceConfigs()->toArray());
$backends = array_combine($backends, $backends);

if (! isset($formData['global_config_backend']) || $formData['global_config_backend'] === 'db') {
$backends = array();
foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) {
if ($resource['type'] === 'db') {
$backends[$name] = $name;
}
}

$this->addElement(
'select',
'global_config_resource',
array(
'required' => true,
'multiOptions' => array_merge(
['' => sprintf(' - %s - ', $this->translate('Please choose'))],
$backends
),
'disable' => [''],
'value' => '',
'label' => $this->translate('Configuration Database')
)
);
}
$this->addElement(
'select',
'global_config_resource',
array(
'required' => true,
'multiOptions' => array_merge(
['' => sprintf(' - %s - ', $this->translate('Please choose'))],
$backends
),
'disable' => [''],
'value' => '',
'label' => $this->translate('Configuration Database')
)
);

return $this;
}
Expand Down
9 changes: 0 additions & 9 deletions application/forms/Config/GeneralConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,4 @@ public function createElements(array $formData)
$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');
}
}
}
4 changes: 1 addition & 3 deletions doc/03-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ Option | Description
-------------------------|-----------------------------------------------
show\_stacktraces | **Optional.** Whether to show debug stacktraces. Defaults to `0`.
module\_path | **Optional.** Specifies the directories where modules can be installed. Multiple directories must be separated with colons.
config\_backend | **Optional.** Select the user preference storage. Can be set to `ini` (default), `db` or `none`. If `db` is selected, this requires the `config_resource` attribute.
config\_resource | **Optional.** Specify a defined [resource](04-Resources.md#resources-configuration-database) name. Can only be used if `config_backend` is set to `db`.
config\_resource | **Required.** Specify a defined [resource](04-Resources.md#resources-configuration-database) name.


Example for storing the user preferences in the database resource `icingaweb_db`:

```
[global]
show_stacktraces = "0"
config_backend = "db"
config_resource = "icingaweb_db"
module_path = "/usr/share/icingaweb2/modules"
```
Expand Down
27 changes: 2 additions & 25 deletions doc/07-Preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,19 @@
Preferences are settings a user can set for their account only,
for example the language and time zone.

Preferences can be stored either in INI files or in a MySQL or in a PostgreSQL database. By default, Icinga Web 2 stores
preferences in INI files beneath Icinga Web 2's configuration directory.

```
/etc/icingaweb2/<username>/config.ini
```
Preferences can be stored either in a MySQL or in a PostgreSQL database. The database must be configured.

## Configuration <a id="preferences-configuration"></a>

The preference configuration backend is defined in the global [config.ini](03-Configuration.md#configuration-general-global) file.

### Store Preferences in INI Files <a id="preferences-configuration-ini"></a>

If preferences are stored in INI Files, Icinga Web 2 automatically creates one file per user using the username as
file name for storing preferences. A INI file is created once a user saves changed preferences the first time.
The files are located beneath the `preferences` directory beneath Icinga Web 2's configuration directory.

You need to add the following section to the global [config.ini](03-Configuration.md#configuration-general-global) file
in order to store preferences in a file.

```
[global]
config_backend = "ini"
```

### Store Preferences in a Database <a id="preferences-configuration-db"></a>

In order to be more flexible in distributed setups you can store preferences in a MySQL or in a PostgreSQL database.
For storing preferences in a database, you have to define a [database resource](04-Resources.md#resources-configuration-database)
You have to define a [database resource](04-Resources.md#resources-configuration-database)
which will be referenced as resource for the preferences storage.

You need to add the following section to the global [config.ini](03-Configuration.md#configuration-general-global) file
in order to store preferences in a database.

```
[global]
config_backend = "db"
config_resource = "icingaweb_db"
```
2 changes: 2 additions & 0 deletions doc/80-Upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ v2.6 to v2.8 requires to follow the instructions for v2.7 too.
## Upgrading to Icinga Web 2 2.11.x

* The Vagrant file and all its assets have been removed.
* The `IniStore` class has been removed due to the deprecation of the Preferences ini backend.
* The `DbStore` class has been removed and its methods have been added to `PreferencesStore` class.

**Database Schema**

Expand Down
33 changes: 14 additions & 19 deletions library/Icinga/Authentication/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,26 +376,21 @@ public function setupUser(User $user)
$config = new Config();
}

if ($config->get('global', 'config_backend', 'db') !== 'none') {
$preferencesConfig = new ConfigObject([
'store' => $config->get('global', 'config_backend', 'db'),
'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();
}

Expand Down
Loading