[icinga-checkins] icinga.org: icingaweb2-module-director/feature/job-scheduling-11627: KickstartForm: fix exception catching...

git at icinga.org git at icinga.org
Mon May 2 11:09:52 CEST 2016


Module: icingaweb2-module-director
Branch: feature/job-scheduling-11627
Commit: 31163b070831946024d2be81102e433e923f9360
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=31163b070831946024d2be81102e433e923f9360

Author: Thomas Gelf <thomas at gelf.net>
Date:   Mon May  2 11:08:18 2016 +0200

KickstartForm: fix exception catching...

...element ordering and give more hints when storing config is not
possible

fixes #11653

---

 application/forms/KickstartForm.php |   39 ++++++++++++++++++++++++++---------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/application/forms/KickstartForm.php b/application/forms/KickstartForm.php
index b9b8d4d..b1da43c 100644
--- a/application/forms/KickstartForm.php
+++ b/application/forms/KickstartForm.php
@@ -27,9 +27,10 @@ class KickstartForm extends QuickForm
         $this->migrateDbLabel   = $this->translate('Apply schema migrations');
 
         $this->addResourceConfigElements();
+        $this->addResourceDisplayGroup();
+
         if (!$this->config()->get('db', 'resource')
             || ($this->config()->get('db', 'resource') !== $this->getResourceName())) {
-            $this->addResourceDisplayGroup();
             return;
         }
 
@@ -66,6 +67,9 @@ class KickstartForm extends QuickForm
             ));
 
             $this->addHtmlHint($hint, array('name' => 'HINT_ready'));
+            $this->getDisplayGroup('config')->addElements(
+                array($this->getElement('HINT_ready'))
+            );
 
             return;
         }
@@ -168,7 +172,6 @@ class KickstartForm extends QuickForm
 
                 $this->addHtmlHint($hint, array('name' => 'HINT_db_perms'));
             }
-
         }
     }
 
@@ -214,10 +217,11 @@ class KickstartForm extends QuickForm
     {
         $elements = array(
             'HINT_no_resource',
-            'HINT_ready',
             'resource',
+            'HINT_ready',
             'HINT_schema',
-            'HINT_db_perms'
+            'HINT_db_perms',
+            'HINT_config_store'
         );
 
         $this->addDisplayGroup($elements, 'config', array(
@@ -258,26 +262,41 @@ class KickstartForm extends QuickForm
         try {
             $config->saveIni();
             $this->setSuccessMessage($this->translate('Configuration has been stored'));
+
+            return true;
         } catch (Exception $e) {
             $this->getElement('resource')->addError(
                 sprintf(
-                    $this->translate('Unable to store the configuration to "%s"'),
+                    $this->translate(
+                        'Unable to store the configuration to "%s". Please check'
+                        . ' file permissions or manually store the content shown below'
+                    ),
                     $config->getConfigFile()
                 )
-            )->removeDecorator('description');
+            );
             $this->addHtmlHint(
-                '<pre>' . $config . '</pre>'
+                '<pre>' . $config . '</pre>',
+                array('name' => 'HINT_config_store')
             );
-        }
 
+            $this->getDisplayGroup('config')->addElements(
+                array($this->getElement('HINT_config_store'))
+            );
+            $this->removeElement('HINT_ready');
+
+            return false;
+        }
     }
 
     public function onSuccess()
     {
         try {
             if ($this->getSubmitLabel() === $this->storeConfigLabel) {
-                $this->storeResourceConfig();
-                return parent::onSuccess();
+                if ($this->storeResourceConfig()) {
+                    return parent::onSuccess();
+                } else {
+                    return;
+                }
             }
 
             if ($this->getSubmitLabel() === $this->createDbLabel



More information about the icinga-checkins mailing list