commit
113658a23c
|
@ -7,7 +7,6 @@ use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget\Tab;
|
use Icinga\Web\Widget\Tab;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Forms\PreferenceForm;
|
use Icinga\Forms\PreferenceForm;
|
||||||
use Icinga\Exception\ConfigurationError;
|
|
||||||
use Icinga\User\Preferences\PreferencesStore;
|
use Icinga\User\Preferences\PreferencesStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,14 +39,13 @@ class PreferenceController extends BasePreferenceController
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
$storeConfig = Config::app()->getSection('preferences');
|
$storeConfig = Config::app()->getSection('preferences');
|
||||||
if ($storeConfig->isEmpty()) {
|
|
||||||
throw new ConfigurationError(t('You need to configure how to store preferences first.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = $this->getRequest()->getUser();
|
$user = $this->getRequest()->getUser();
|
||||||
$form = new PreferenceForm();
|
$form = new PreferenceForm();
|
||||||
$form->setPreferences($user->getPreferences());
|
$form->setPreferences($user->getPreferences());
|
||||||
|
if ($storeConfig->get('store', 'ini') !== 'none') {
|
||||||
$form->setStore(PreferencesStore::create($storeConfig, $user));
|
$form->setStore(PreferencesStore::create($storeConfig, $user));
|
||||||
|
}
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
|
|
|
@ -4,10 +4,8 @@
|
||||||
|
|
||||||
namespace Icinga\Forms\Config\General;
|
namespace Icinga\Forms\Config\General;
|
||||||
|
|
||||||
use DateTimeZone;
|
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Util\Translator;
|
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +44,7 @@ class ApplicationConfigForm extends Form
|
||||||
|
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'select',
|
'select',
|
||||||
'preferences_type',
|
'preferences_store',
|
||||||
array(
|
array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'autosubmit' => true,
|
'autosubmit' => true,
|
||||||
|
@ -54,11 +52,11 @@ class ApplicationConfigForm extends Form
|
||||||
'multiOptions' => array(
|
'multiOptions' => array(
|
||||||
'ini' => $this->translate('File System (INI Files)'),
|
'ini' => $this->translate('File System (INI Files)'),
|
||||||
'db' => $this->translate('Database'),
|
'db' => $this->translate('Database'),
|
||||||
'null' => $this->translate('Don\'t Store Preferences')
|
'none' => $this->translate('Don\'t Store Preferences')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (isset($formData['preferences_type']) && $formData['preferences_type'] === 'db') {
|
if (isset($formData['preferences_store']) && $formData['preferences_store'] === 'db') {
|
||||||
$backends = array();
|
$backends = array();
|
||||||
foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) {
|
foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) {
|
||||||
if ($resource['type'] === 'db') {
|
if ($resource['type'] === 'db') {
|
||||||
|
|
|
@ -86,7 +86,7 @@ class PreferenceForm extends Form
|
||||||
*/
|
*/
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
$this->preferences = new Preferences($this->store->load());
|
$this->preferences = new Preferences($this->store ? $this->store->load() : array());
|
||||||
|
|
||||||
$webPreferences = $this->preferences->get('icingaweb', array());
|
$webPreferences = $this->preferences->get('icingaweb', array());
|
||||||
foreach ($this->getValues() as $key => $value) {
|
foreach ($this->getValues() as $key => $value) {
|
||||||
|
@ -103,7 +103,7 @@ class PreferenceForm extends Form
|
||||||
Session::getSession()->user->setPreferences($this->preferences);
|
Session::getSession()->user->setPreferences($this->preferences);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->getElement('btn_submit_preferences')->isChecked()) {
|
if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) {
|
||||||
$this->save();
|
$this->save();
|
||||||
Notification::success($this->translate('Preferences successfully saved'));
|
Notification::success($this->translate('Preferences successfully saved'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -186,6 +186,7 @@ class PreferenceForm extends Form
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->store) {
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'submit',
|
'submit',
|
||||||
'btn_submit_preferences',
|
'btn_submit_preferences',
|
||||||
|
@ -198,6 +199,7 @@ class PreferenceForm extends Form
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'submit',
|
'submit',
|
||||||
|
|
|
@ -63,7 +63,7 @@ class Manager
|
||||||
);
|
);
|
||||||
$config = new Config();
|
$config = new Config();
|
||||||
}
|
}
|
||||||
if ($config->hasSection('preferences')) {
|
if ($config->get('preferences', 'store', 'ini') !== 'none') {
|
||||||
$preferencesConfig = $config->getSection('preferences');
|
$preferencesConfig = $config->getSection('preferences');
|
||||||
try {
|
try {
|
||||||
$preferencesStore = PreferencesStore::create(
|
$preferencesStore = PreferencesStore::create(
|
||||||
|
|
|
@ -26,7 +26,7 @@ use Icinga\Data\Db\DbConnection;
|
||||||
* // Create a INI store
|
* // Create a INI store
|
||||||
* $store = PreferencesStore::create(
|
* $store = PreferencesStore::create(
|
||||||
* new ConfigObject(
|
* new ConfigObject(
|
||||||
* 'type' => 'ini',
|
* 'store' => 'ini',
|
||||||
* 'config_path' => '/path/to/preferences'
|
* 'config_path' => '/path/to/preferences'
|
||||||
* ),
|
* ),
|
||||||
* $user // Instance of \Icinga\User
|
* $user // Instance of \Icinga\User
|
||||||
|
@ -117,13 +117,7 @@ abstract class PreferencesStore
|
||||||
*/
|
*/
|
||||||
public static function create(ConfigObject $config, User $user)
|
public static function create(ConfigObject $config, User $user)
|
||||||
{
|
{
|
||||||
if (($type = $config->type) === null) {
|
$type = ucfirst(strtolower($config->get('store', 'ini')));
|
||||||
throw new ConfigurationError(
|
|
||||||
'Preferences configuration is missing the type directive'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = ucfirst(strtolower($type));
|
|
||||||
$storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store';
|
$storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store';
|
||||||
if (!class_exists($storeClass)) {
|
if (!class_exists($storeClass)) {
|
||||||
throw new ConfigurationError(
|
throw new ConfigurationError(
|
||||||
|
|
|
@ -66,11 +66,11 @@ class PreferencesPage extends Form
|
||||||
if (Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) {
|
if (Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) {
|
||||||
$storageTypes['db'] = $this->translate('Database');
|
$storageTypes['db'] = $this->translate('Database');
|
||||||
}
|
}
|
||||||
$storageTypes['null'] = $this->translate('Don\'t Store Preferences');
|
$storageTypes['none'] = $this->translate('Don\'t Store Preferences');
|
||||||
|
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'select',
|
'select',
|
||||||
'type',
|
'store',
|
||||||
array(
|
array(
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'label' => $this->translate('User Preference Storage Type'),
|
'label' => $this->translate('User Preference Storage Type'),
|
||||||
|
|
|
@ -29,7 +29,7 @@ class GeneralConfigStep extends Step
|
||||||
$config[$section][$property] = $value;
|
$config[$section][$property] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$config['preferences']['type'] = $this->data['preferencesType'];
|
$config['preferences']['store'] = $this->data['preferencesStore'];
|
||||||
if (isset($this->data['preferencesResource'])) {
|
if (isset($this->data['preferencesResource'])) {
|
||||||
$config['preferences']['resource'] = $this->data['preferencesResource'];
|
$config['preferences']['resource'] = $this->data['preferencesResource'];
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,11 @@ class GeneralConfigStep extends Step
|
||||||
$generalHtml = ''
|
$generalHtml = ''
|
||||||
. '<ul>'
|
. '<ul>'
|
||||||
. '<li>' . sprintf(
|
. '<li>' . sprintf(
|
||||||
$this->data['preferencesType'] === 'ini' ? sprintf(
|
$this->data['preferencesStore'] === 'ini' ? sprintf(
|
||||||
t('Preferences will be stored per user account in INI files at: %s'),
|
t('Preferences will be stored per user account in INI files at: %s'),
|
||||||
Config::resolvePath('preferences')
|
Config::resolvePath('preferences')
|
||||||
) : (
|
) : (
|
||||||
$this->data['preferencesType'] === 'db' ? t('Preferences will be stored using a database.') : (
|
$this->data['preferencesStore'] === 'db' ? t('Preferences will be stored using a database.') : (
|
||||||
t('Preferences will not be persisted across browser sessions.')
|
t('Preferences will not be persisted across browser sessions.')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -293,7 +293,7 @@ class WebWizard extends Wizard implements SetupWizard
|
||||||
$setup->addStep(
|
$setup->addStep(
|
||||||
new GeneralConfigStep(array(
|
new GeneralConfigStep(array(
|
||||||
'generalConfig' => $pageData['setup_general_config'],
|
'generalConfig' => $pageData['setup_general_config'],
|
||||||
'preferencesType' => $pageData['setup_preferences_type']['type'],
|
'preferencesStore' => $pageData['setup_preferences_type']['store'],
|
||||||
'preferencesResource' => isset($pageData['setup_db_resource']['name'])
|
'preferencesResource' => isset($pageData['setup_db_resource']['name'])
|
||||||
? $pageData['setup_db_resource']['name']
|
? $pageData['setup_db_resource']['name']
|
||||||
: null
|
: null
|
||||||
|
|
Loading…
Reference in New Issue