[icinga-checkins] icinga.org: icingaweb2/feature/actiontable-row-handling-13115: ResourceConfigForm: if the resource being used as config backend gets renamed, update the global config

git at icinga.org git at icinga.org
Wed Nov 16 10:39:04 CET 2016


Module: icingaweb2
Branch: feature/actiontable-row-handling-13115
Commit: 647c0b43549f80626e00bda18e0066ead0e849fd
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=647c0b43549f80626e00bda18e0066ead0e849fd

Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date:   Wed Oct 19 14:09:06 2016 +0200

ResourceConfigForm: if the resource being used as config backend gets renamed, update the global config

refs #9804

---

 application/forms/Config/ResourceConfigForm.php |   29 +++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/application/forms/Config/ResourceConfigForm.php b/application/forms/Config/ResourceConfigForm.php
index 1ce12aa..dfa8852 100644
--- a/application/forms/Config/ResourceConfigForm.php
+++ b/application/forms/Config/ResourceConfigForm.php
@@ -3,6 +3,7 @@
 
 namespace Icinga\Forms\Config;
 
+use Icinga\Application\Config;
 use InvalidArgumentException;
 use Icinga\Application\Platform;
 use Icinga\Exception\ConfigurationError;
@@ -22,6 +23,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
      */
     public function init()
@@ -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();
+        }
+    }
 }



More information about the icinga-checkins mailing list