Merge branch 'bugfix/preferences-not-writable-exception-4529'
fixes #4529
This commit is contained in:
commit
f22a965bc4
|
@ -203,7 +203,7 @@ class GeneralForm extends Form
|
|||
'label' => 'Module Folder',
|
||||
'required' => true,
|
||||
'helptext' => 'The moduleFolder directive is currently not used anywhere but '
|
||||
. 'configureable via the frontend and ini. With feature #4607 moduleFolder '
|
||||
. 'configureable via the frontend and INI. With feature #4607 moduleFolder '
|
||||
. 'will be replaced with a configuration directive for locations of '
|
||||
. 'installed modules',
|
||||
'value' => $cfg->get('moduleFolder', $this->getConfigDir() . '/config/enabledModules')
|
||||
|
@ -275,8 +275,9 @@ class GeneralForm extends Form
|
|||
'required' => true,
|
||||
'value' => $backend,
|
||||
'multiOptions' => array(
|
||||
'ini' => 'File System (ini files)',
|
||||
'db' => 'Database'
|
||||
'ini' => 'File System (INI Files)',
|
||||
'db' => 'Database',
|
||||
'null' => 'Don\'t Store Preferences'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -21,7 +21,7 @@ The ini provider uses the directory **config/preferences** to create one ini
|
|||
file per user and persists the data into a single file. If you want to drop your
|
||||
preferences just drop the file from disk and you'll start with a new profile.
|
||||
|
||||
## Database provider
|
||||
## Database Provider
|
||||
|
||||
To be more flexible in distributed setups you can store preferences in a
|
||||
database (pgsql or mysql), a typical configuration looks like the following
|
||||
|
@ -31,6 +31,17 @@ example:
|
|||
type=db
|
||||
resource=icingaweb-pgsql
|
||||
|
||||
## Null Provider
|
||||
|
||||
The Null Provider discards all preferences and is mainly used as a fallback when no provider could be
|
||||
created (due to permission errors, database outtakes, etc.).
|
||||
|
||||
[preferences]
|
||||
type=null
|
||||
|
||||
If your preferences aren't stored it's best to take a look into the logfiles - errors during the preference setup
|
||||
are displayed as warnings here.
|
||||
|
||||
### Settings
|
||||
|
||||
* **resource**: A reference to a database declared in *resources.ini*. Please read the chapter about
|
||||
|
|
|
@ -215,6 +215,25 @@ class Web extends ApplicationBootstrap
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a NullStore as the preference provider
|
||||
*
|
||||
* @param Preferences $preferences The preference registry to attach the NullStore to
|
||||
* @param User $user The user, required for API compliance
|
||||
*
|
||||
* @see NullStore
|
||||
*/
|
||||
private function registerFallbackPreferenceProvider($preferences, $user)
|
||||
{
|
||||
$this->getConfig()->preferences->type = 'null';
|
||||
$preferenceStore = StoreFactory::create(
|
||||
$this->getConfig()->preferences,
|
||||
$user
|
||||
);
|
||||
|
||||
$preferences->attach($preferenceStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user object and inject preference interface
|
||||
*
|
||||
|
@ -261,7 +280,7 @@ class Web extends ApplicationBootstrap
|
|||
|
||||
$path = Config::resolvePath($this->getConfig()->preferences->configPath);
|
||||
if (is_dir($path) === false) {
|
||||
Logger::error(
|
||||
Logger::warn(
|
||||
'Path for preferences not found (IniStore, "%s"). Using default one: "%s"',
|
||||
$this->getConfig()->preferences->configPath,
|
||||
$this->getConfigDir('preferences')
|
||||
|
@ -277,27 +296,28 @@ class Web extends ApplicationBootstrap
|
|||
$this->getConfig()->preferences,
|
||||
$user
|
||||
);
|
||||
|
||||
$preferences->attach($preferenceStore);
|
||||
} catch (Exception $e) {
|
||||
Logger::fatal(
|
||||
'Could not create create preferences provider. '
|
||||
. 'An exception during bootstrap was thrown: %s',
|
||||
Logger::warn(
|
||||
'Could not create create preferences provider, preferences will be discarded: '
|
||||
. '"%s"',
|
||||
$e->getMessage()
|
||||
);
|
||||
$this->registerFallbackPreferenceProvider($preferences, $user);
|
||||
}
|
||||
|
||||
if ($preferencesLoaded === false && $preferenceStore instanceof LoadInterface) {
|
||||
try {
|
||||
$initialPreferences = $preferenceStore->load();
|
||||
} catch (Exception $e) {
|
||||
Logger::fatal(
|
||||
Logger::warn(
|
||||
'%s::%s: Could not load preferences from provider. '
|
||||
. 'An exception during bootstrap was thrown: %s',
|
||||
__CLASS__,
|
||||
__FUNCTION__,
|
||||
$e->getMessage()
|
||||
);
|
||||
$this->registerFallbackPreferenceProvider($preferences, $user);
|
||||
}
|
||||
|
||||
$sessionStore->writeAll($initialPreferences);
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga 2 Web.
|
||||
*
|
||||
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User\Preferences;
|
||||
|
||||
use Icinga\User;
|
||||
use SplSubject;
|
||||
|
||||
/**
|
||||
* Preference store that simply discards any settings made
|
||||
*
|
||||
* Mainly used as a fallback provider if no preferences can be created
|
||||
*/
|
||||
class NullStore implements LoadInterface, FlushObserverInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Setter for user, does nothing
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Load preferences from source, return an empty array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Receive update from subject
|
||||
*
|
||||
* @link http://php.net/manual/en/splobserver.update.php
|
||||
* @param SplSubject $subject <p>
|
||||
* The <b>SplSubject</b> notifying the observer of an update.
|
||||
* </p>
|
||||
* @return void
|
||||
*/
|
||||
public function update(SplSubject $subject)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,13 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
/*
|
||||
* Set timezone before bootstrapping the application and therefore before calling `setupTimezone()` because in case an
|
||||
* error occurred whilst, the logger calls date/time functions which would generate a warning if the php.ini lacks a
|
||||
* valid timezone.
|
||||
*/
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
require_once dirname(__FILE__). '/../library/Icinga/Application/ApplicationBootstrap.php';
|
||||
require_once dirname(__FILE__). '/../library/Icinga/Application/Web.php';
|
||||
|
||||
|
|
Loading…
Reference in New Issue