parent
a0efdd0a68
commit
a500937b7d
|
@ -6,7 +6,6 @@ namespace Icinga\Forms\Config;
|
|||
use Icinga\Forms\Config\General\ApplicationConfigForm;
|
||||
use Icinga\Forms\Config\General\LoggingConfigForm;
|
||||
use Icinga\Forms\ConfigForm;
|
||||
use Icinga\Web\Notification;
|
||||
|
||||
/**
|
||||
* Form class for application-wide and logging specific settings
|
||||
|
@ -32,43 +31,4 @@ class GeneralConfigForm extends ConfigForm
|
|||
$this->addElements($appConfigForm->createElements($formData)->getElements());
|
||||
$this->addElements($loggingConfigForm->createElements($formData)->getElements());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Form::onSuccess()
|
||||
*/
|
||||
public function onSuccess()
|
||||
{
|
||||
$sections = array();
|
||||
foreach ($this->getValues() as $sectionAndPropertyName => $value) {
|
||||
list($section, $property) = explode('_', $sectionAndPropertyName, 2);
|
||||
if (! isset($sections[$section])) {
|
||||
$sections[$section] = array();
|
||||
}
|
||||
$sections[$section][$property] = $value;
|
||||
}
|
||||
foreach ($sections as $section => $config) {
|
||||
$this->config->setSection($section, $config);
|
||||
}
|
||||
|
||||
if ($this->save()) {
|
||||
Notification::success($this->translate('New configuration has successfully been stored'));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Form::onRequest()
|
||||
*/
|
||||
public function onRequest()
|
||||
{
|
||||
$values = array();
|
||||
foreach ($this->config as $section => $properties) {
|
||||
foreach ($properties as $name => $value) {
|
||||
$values[$section . '_' . $name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$this->populate($values);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,10 +163,10 @@ class ResourceConfigForm extends ConfigForm
|
|||
return false;
|
||||
}
|
||||
}
|
||||
$this->add($this->getValues());
|
||||
$this->add(array_filter($this->getValues()));
|
||||
$message = $this->translate('Resource "%s" has been successfully created');
|
||||
} else { // edit existing resource
|
||||
$this->edit($resource, $this->getValues());
|
||||
$this->edit($resource, array_filter($this->getValues()));
|
||||
$message = $this->translate('Resource "%s" has been successfully changed');
|
||||
}
|
||||
} catch (InvalidArgumentException $e) {
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Icinga\Forms;
|
|||
use Exception;
|
||||
use Zend_Form_Decorator_Abstract;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Application\Config;
|
||||
|
||||
/**
|
||||
|
@ -33,6 +34,47 @@ class ConfigForm extends Form
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onSuccess()
|
||||
{
|
||||
$sections = array();
|
||||
foreach ($this->getValues() as $sectionAndPropertyName => $value) {
|
||||
if ($value === '') {
|
||||
$value = null; // Causes the config writer to unset it
|
||||
}
|
||||
|
||||
list($section, $property) = explode('_', $sectionAndPropertyName, 2);
|
||||
$sections[$section][$property] = $value;
|
||||
}
|
||||
|
||||
foreach ($sections as $section => $config) {
|
||||
$this->config->setSection($section, $config);
|
||||
}
|
||||
|
||||
if ($this->save()) {
|
||||
Notification::success($this->translate('New configuration has successfully been stored'));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onRequest()
|
||||
{
|
||||
$values = array();
|
||||
foreach ($this->config as $section => $properties) {
|
||||
foreach ($properties as $name => $value) {
|
||||
$values[$section . '_' . $name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$this->populate($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the current configuration to disk
|
||||
*
|
||||
|
|
|
@ -130,7 +130,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
|||
'username' => $this->config->username,
|
||||
'password' => $this->config->password,
|
||||
'dbname' => $this->config->dbname,
|
||||
'charset' => $this->config->charset,
|
||||
'charset' => $this->config->charset ?: null,
|
||||
'persistent' => (bool) $this->config->get('persistent', false),
|
||||
'options' => & $genericAdapterOptions,
|
||||
'driver_options' => & $driverOptions
|
||||
|
|
Loading…
Reference in New Issue