mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
parent
03cc43a3f6
commit
95bc8a2f4f
@ -275,8 +275,9 @@ class GeneralForm extends Form
|
|||||||
'required' => true,
|
'required' => true,
|
||||||
'value' => $backend,
|
'value' => $backend,
|
||||||
'multiOptions' => array(
|
'multiOptions' => array(
|
||||||
'ini' => 'File System (ini files)',
|
'ini' => 'File System (ini Files)',
|
||||||
'db' => 'Database'
|
'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
|
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.
|
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
|
To be more flexible in distributed setups you can store preferences in a
|
||||||
database (pgsql or mysql), a typical configuration looks like the following
|
database (pgsql or mysql), a typical configuration looks like the following
|
||||||
@ -31,6 +31,17 @@ example:
|
|||||||
type=db
|
type=db
|
||||||
resource=icingaweb-pgsql
|
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
|
### Settings
|
||||||
|
|
||||||
* **resource**: A reference to a database declared in *resources.ini*. Please read the chapter about
|
* **resource**: A reference to a database declared in *resources.ini*. Please read the chapter about
|
||||||
|
@ -215,6 +215,23 @@ class Web extends ApplicationBootstrap
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a @see 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
|
||||||
|
*/
|
||||||
|
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
|
* Create user object and inject preference interface
|
||||||
*
|
*
|
||||||
@ -261,7 +278,7 @@ class Web extends ApplicationBootstrap
|
|||||||
|
|
||||||
$path = Config::resolvePath($this->getConfig()->preferences->configPath);
|
$path = Config::resolvePath($this->getConfig()->preferences->configPath);
|
||||||
if (is_dir($path) === false) {
|
if (is_dir($path) === false) {
|
||||||
Logger::error(
|
Logger::warn(
|
||||||
'Path for preferences not found (IniStore, "%s"). Using default one: "%s"',
|
'Path for preferences not found (IniStore, "%s"). Using default one: "%s"',
|
||||||
$this->getConfig()->preferences->configPath,
|
$this->getConfig()->preferences->configPath,
|
||||||
$this->getConfigDir('preferences')
|
$this->getConfigDir('preferences')
|
||||||
@ -277,14 +294,14 @@ class Web extends ApplicationBootstrap
|
|||||||
$this->getConfig()->preferences,
|
$this->getConfig()->preferences,
|
||||||
$user
|
$user
|
||||||
);
|
);
|
||||||
|
|
||||||
$preferences->attach($preferenceStore);
|
$preferences->attach($preferenceStore);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Logger::fatal(
|
Logger::warn(
|
||||||
'Could not create create preferences provider. '
|
'Could not create create preferences provider, preferences will be discarded: '
|
||||||
. 'An exception during bootstrap was thrown: %s',
|
. '"%s"',
|
||||||
$e->getMessage()
|
$e->getMessage()
|
||||||
);
|
);
|
||||||
|
$this->registerFallbackPreferenceProvider($preferences, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($preferencesLoaded === false && $preferenceStore instanceof LoadInterface) {
|
if ($preferencesLoaded === false && $preferenceStore instanceof LoadInterface) {
|
||||||
|
75
library/Icinga/User/Preferences/NullStore.php
Normal file
75
library/Icinga/User/Preferences/NullStore.php
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user