Merge branch 'bugifx/add-none-preferences-store-8234'

fixes #8234
This commit is contained in:
Johannes Meyer 2015-01-23 16:25:41 +01:00
commit 113658a23c
8 changed files with 30 additions and 38 deletions

View File

@ -7,7 +7,6 @@ use Icinga\Web\Url;
use Icinga\Web\Widget\Tab;
use Icinga\Application\Config;
use Icinga\Forms\PreferenceForm;
use Icinga\Exception\ConfigurationError;
use Icinga\User\Preferences\PreferencesStore;
/**
@ -40,14 +39,13 @@ class PreferenceController extends BasePreferenceController
public function indexAction()
{
$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();
$form = new PreferenceForm();
$form->setPreferences($user->getPreferences());
$form->setStore(PreferencesStore::create($storeConfig, $user));
if ($storeConfig->get('store', 'ini') !== 'none') {
$form->setStore(PreferencesStore::create($storeConfig, $user));
}
$form->handleRequest();
$this->view->form = $form;

View File

@ -4,10 +4,8 @@
namespace Icinga\Forms\Config\General;
use DateTimeZone;
use Icinga\Application\Icinga;
use Icinga\Data\ResourceFactory;
use Icinga\Util\Translator;
use Icinga\Web\Form;
@ -46,7 +44,7 @@ class ApplicationConfigForm extends Form
$this->addElement(
'select',
'preferences_type',
'preferences_store',
array(
'required' => true,
'autosubmit' => true,
@ -54,11 +52,11 @@ class ApplicationConfigForm extends Form
'multiOptions' => array(
'ini' => $this->translate('File System (INI Files)'),
'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();
foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) {
if ($resource['type'] === 'db') {

View File

@ -86,7 +86,7 @@ class PreferenceForm extends Form
*/
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());
foreach ($this->getValues() as $key => $value) {
@ -103,7 +103,7 @@ class PreferenceForm extends Form
Session::getSession()->user->setPreferences($this->preferences);
try {
if ($this->getElement('btn_submit_preferences')->isChecked()) {
if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) {
$this->save();
Notification::success($this->translate('Preferences successfully saved'));
} else {
@ -186,18 +186,20 @@ class PreferenceForm extends Form
)
);
$this->addElement(
'submit',
'btn_submit_preferences',
array(
'ignore' => true,
'label' => $this->translate('Save to the Preferences'),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'div'))
if ($this->store) {
$this->addElement(
'submit',
'btn_submit_preferences',
array(
'ignore' => true,
'label' => $this->translate('Save to the Preferences'),
'decorators' => array(
'ViewHelper',
array('HtmlTag', array('tag' => 'div'))
)
)
)
);
);
}
$this->addElement(
'submit',

View File

@ -63,7 +63,7 @@ class Manager
);
$config = new Config();
}
if ($config->hasSection('preferences')) {
if ($config->get('preferences', 'store', 'ini') !== 'none') {
$preferencesConfig = $config->getSection('preferences');
try {
$preferencesStore = PreferencesStore::create(

View File

@ -26,7 +26,7 @@ use Icinga\Data\Db\DbConnection;
* // Create a INI store
* $store = PreferencesStore::create(
* new ConfigObject(
* 'type' => 'ini',
* 'store' => 'ini',
* 'config_path' => '/path/to/preferences'
* ),
* $user // Instance of \Icinga\User
@ -117,13 +117,7 @@ abstract class PreferencesStore
*/
public static function create(ConfigObject $config, User $user)
{
if (($type = $config->type) === null) {
throw new ConfigurationError(
'Preferences configuration is missing the type directive'
);
}
$type = ucfirst(strtolower($type));
$type = ucfirst(strtolower($config->get('store', 'ini')));
$storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store';
if (!class_exists($storeClass)) {
throw new ConfigurationError(

View File

@ -66,11 +66,11 @@ class PreferencesPage extends Form
if (Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) {
$storageTypes['db'] = $this->translate('Database');
}
$storageTypes['null'] = $this->translate('Don\'t Store Preferences');
$storageTypes['none'] = $this->translate('Don\'t Store Preferences');
$this->addElement(
'select',
'type',
'store',
array(
'required' => true,
'label' => $this->translate('User Preference Storage Type'),

View File

@ -29,7 +29,7 @@ class GeneralConfigStep extends Step
$config[$section][$property] = $value;
}
$config['preferences']['type'] = $this->data['preferencesType'];
$config['preferences']['store'] = $this->data['preferencesStore'];
if (isset($this->data['preferencesResource'])) {
$config['preferences']['resource'] = $this->data['preferencesResource'];
}
@ -58,11 +58,11 @@ class GeneralConfigStep extends Step
$generalHtml = ''
. '<ul>'
. '<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'),
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.')
)
)

View File

@ -293,7 +293,7 @@ class WebWizard extends Wizard implements SetupWizard
$setup->addStep(
new GeneralConfigStep(array(
'generalConfig' => $pageData['setup_general_config'],
'preferencesType' => $pageData['setup_preferences_type']['type'],
'preferencesStore' => $pageData['setup_preferences_type']['store'],
'preferencesResource' => isset($pageData['setup_db_resource']['name'])
? $pageData['setup_db_resource']['name']
: null