Set preferences store type to `Db` and make it non-configurable
This commit is contained in:
parent
9c6fda7b33
commit
8ff1a22df7
|
@ -71,7 +71,6 @@ class AccountController extends Controller
|
||||||
$form->setPreferences($user->getPreferences());
|
$form->setPreferences($user->getPreferences());
|
||||||
if ($config->get('config_backend', 'db') !== 'none' && isset($config->config_resource)) {
|
if ($config->get('config_backend', 'db') !== 'none' && isset($config->config_resource)) {
|
||||||
$form->setStore(PreferencesStore::create(new ConfigObject(array(
|
$form->setStore(PreferencesStore::create(new ConfigObject(array(
|
||||||
'store' => $config->get('config_backend', 'db'),
|
|
||||||
'resource' => $config->config_resource
|
'resource' => $config->config_resource
|
||||||
)), $user));
|
)), $user));
|
||||||
}
|
}
|
||||||
|
|
|
@ -378,7 +378,6 @@ class Auth
|
||||||
|
|
||||||
if ($config->get('global', 'config_backend', 'db') !== 'none') {
|
if ($config->get('global', 'config_backend', 'db') !== 'none') {
|
||||||
$preferencesConfig = new ConfigObject([
|
$preferencesConfig = new ConfigObject([
|
||||||
'store' => $config->get('global', 'config_backend', 'db'),
|
|
||||||
'resource' => $config->get('global', 'config_resource')
|
'resource' => $config->get('global', 'config_resource')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,12 @@
|
||||||
|
|
||||||
namespace Icinga\User\Preferences;
|
namespace Icinga\User\Preferences;
|
||||||
|
|
||||||
use Icinga\Application\Config;
|
|
||||||
use Icinga\Application\Logger;
|
|
||||||
use Icinga\User;
|
use Icinga\User;
|
||||||
use Icinga\User\Preferences;
|
use Icinga\User\Preferences;
|
||||||
use Icinga\Data\ConfigObject;
|
use Icinga\Data\ConfigObject;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Data\Db\DbConnection;
|
use Icinga\User\Preferences\Store\DbStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preferences store factory
|
* Preferences store factory
|
||||||
|
@ -26,7 +24,6 @@ use Icinga\Data\Db\DbConnection;
|
||||||
* // Create a INI store
|
* // Create a INI store
|
||||||
* $store = PreferencesStore::create(
|
* $store = PreferencesStore::create(
|
||||||
* new ConfigObject(
|
* new ConfigObject(
|
||||||
* 'store' => 'ini',
|
|
||||||
* 'config_path' => '/path/to/preferences'
|
* 'config_path' => '/path/to/preferences'
|
||||||
* ),
|
* ),
|
||||||
* $user // Instance of \Icinga\User
|
* $user // Instance of \Icinga\User
|
||||||
|
@ -117,27 +114,13 @@ abstract class PreferencesStore
|
||||||
*/
|
*/
|
||||||
public static function create(ConfigObject $config, User $user)
|
public static function create(ConfigObject $config, User $user)
|
||||||
{
|
{
|
||||||
$type = ucfirst(strtolower($config->get('store', 'db')));
|
|
||||||
$storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store';
|
|
||||||
if (!class_exists($storeClass)) {
|
|
||||||
throw new ConfigurationError(
|
|
||||||
'Preferences configuration defines an invalid storage type. Storage type %s not found',
|
|
||||||
$type
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type === 'Ini') {
|
|
||||||
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') {
|
|
||||||
$resourceConfig = ResourceFactory::getResourceConfig($config->resource);
|
$resourceConfig = ResourceFactory::getResourceConfig($config->resource);
|
||||||
if ($resourceConfig->db === 'mysql') {
|
if ($resourceConfig->db === 'mysql') {
|
||||||
$resourceConfig->charset = 'utf8mb4';
|
$resourceConfig->charset = 'utf8mb4';
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->connection = ResourceFactory::createResource($resourceConfig);
|
$config->connection = ResourceFactory::createResource($resourceConfig);
|
||||||
}
|
|
||||||
|
|
||||||
return new $storeClass($config, $user);
|
return new DbStore($config, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue