ResourceConfigForm: if the resource being used as config backend gets renamed, update the global config
refs #9804
This commit is contained in:
parent
00880710ed
commit
647c0b4354
|
@ -3,6 +3,7 @@
|
|||
|
||||
namespace Icinga\Forms\Config;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use InvalidArgumentException;
|
||||
use Icinga\Application\Platform;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
@ -21,6 +22,13 @@ use Icinga\Web\Notification;
|
|||
|
||||
class ResourceConfigForm extends ConfigForm
|
||||
{
|
||||
/**
|
||||
* If the global config must be updated because a resource has been changed, this is the updated global config
|
||||
*
|
||||
* @var Config|null
|
||||
*/
|
||||
protected $updatedAppConfig = null;
|
||||
|
||||
/**
|
||||
* Initialize this form
|
||||
*/
|
||||
|
@ -104,6 +112,16 @@ class ResourceConfigForm extends ConfigForm
|
|||
$this->config->removeSection($name);
|
||||
unset($values['name']);
|
||||
$this->config->setSection($newName, $resourceConfig->merge($values));
|
||||
|
||||
if ($newName !== $name) {
|
||||
$appConfig = Config::app();
|
||||
$section = $appConfig->getSection('global');
|
||||
if ($section->config_resource === $name) {
|
||||
$section->config_resource = $newName;
|
||||
$this->updatedAppConfig = $appConfig->setSection('global', $section);
|
||||
}
|
||||
}
|
||||
|
||||
return $resourceConfig;
|
||||
}
|
||||
|
||||
|
@ -376,4 +394,15 @@ class ResourceConfigForm extends ConfigForm
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function writeConfig(Config $config)
|
||||
{
|
||||
parent::writeConfig($config);
|
||||
if ($this->updatedAppConfig !== null) {
|
||||
$this->updatedAppConfig->saveIni();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue