[icinga-checkins] icinga.org: icinga-web/master: Fix complex datatypes for cronk configuration

git at icinga.org git at icinga.org
Fri Oct 19 12:19:58 CEST 2012


Module: icinga-web
Branch: master
Commit: 2c3e528fc1f86cbd56d2e825fa6e915ce1049138
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=2c3e528fc1f86cbd56d2e825fa6e915ce1049138

Author: Marius Hein <marius.hein at netways.de>
Date:   Wed Aug 22 16:26:24 2012 +0200

Fix complex datatypes for cronk configuration

fixes #1576

---

 .../AppKit/lib/util/AppKitStringUtil.class.php     |    2 +-
 .../js/Icinga/Cronks/System/CronkListingPanel.js   |    2 +-
 .../views/System/CronkLoaderSuccessView.class.php  |   46 ++++++++++++++------
 3 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/app/modules/AppKit/lib/util/AppKitStringUtil.class.php b/app/modules/AppKit/lib/util/AppKitStringUtil.class.php
index 92a15c9..637ac70 100644
--- a/app/modules/AppKit/lib/util/AppKitStringUtil.class.php
+++ b/app/modules/AppKit/lib/util/AppKitStringUtil.class.php
@@ -120,7 +120,7 @@ class AppKitStringUtil {
      * @param string $url
      * @return boolean
      */
-    public function detectUrl($url) {
+    public static function detectUrl($url) {
         return preg_match('@^[a-z]{3,8}://.+$@', $url);
     }
 
diff --git a/app/modules/Cronks/lib/js/Icinga/Cronks/System/CronkListingPanel.js b/app/modules/Cronks/lib/js/Icinga/Cronks/System/CronkListingPanel.js
index da33602..3e96146 100644
--- a/app/modules/Cronks/lib/js/Icinga/Cronks/System/CronkListingPanel.js
+++ b/app/modules/Cronks/lib/js/Icinga/Cronks/System/CronkListingPanel.js
@@ -74,7 +74,7 @@ Ext.ns('Icinga.Cronks.System');
                                     return v;
                                 }
                                 for (var i in v) {
-                                    if (Ext.isObject(v[i])) {
+                                    if (Ext.isObject(v[i]) || Ext.isArray(v[i])) {
                                         v[i] = Ext.encode(v[i]);
                                     }
                                 }
diff --git a/app/modules/Cronks/views/System/CronkLoaderSuccessView.class.php b/app/modules/Cronks/views/System/CronkLoaderSuccessView.class.php
index 73259e8..8e26c08 100644
--- a/app/modules/Cronks/views/System/CronkLoaderSuccessView.class.php
+++ b/app/modules/Cronks/views/System/CronkLoaderSuccessView.class.php
@@ -34,22 +34,24 @@ class Cronks_System_CronkLoaderSuccessView extends CronksBaseView {
             $model = $this->getContext()->getModel('Provider.CronksData', 'Cronks');
 
             $crname = $rd->getParameter('cronk');
-
-            $parameters = array() + (array)$rd->getParameter('p', array());
-
+            
+            /*
+             * Removed accepting external parameters because if some is
+             * changed this is done via cronk build and he does this
+             * in the database. 
+             * 
+             * Ergo: No param handling here, just ignore $rd and
+             * create a plain and empty array.
+             */
+            $parameters = array();
+            
             if ($model->hasCronk($crname)) {
                 $cronk = $model->getCronk($crname);
-
+                
                 if (array_key_exists('ae:parameter', $cronk) && is_array($cronk['ae:parameter'])) {
-
-                    foreach($cronk['ae:parameter'] as $key=>$param) {
-                        if (is_array($param) || is_object($param)) {
-                            $param = json_encode($param);
-                            $cronk['ae:parameter'][$key] = $param;
-                            $parameters[$key] = $param;
-                        }
-                    }
-
+                    
+                    $cronk['ae:parameter'] = $this->rebuildComplexData($cronk['ae:parameter']);
+                    
                     $parameters = (array)$cronk['ae:parameter']
                                   + $parameters
                                   + array('module' => $cronk['module'], 'action' => $cronk['action']);
@@ -69,6 +71,24 @@ class Cronks_System_CronkLoaderSuccessView extends CronksBaseView {
 
         return 'Some strange error occured';
     }
+    
+    /**
+     * Decodes complex vars from cronk builder
+     * @param array $params
+     * @return array
+     */
+    private function rebuildComplexData(array $params) {
+        foreach($params as $key=>&$val) {
+            if (is_string($val)) {
+                $test = json_decode($val, true);
+                if ($test !== null) {
+                    $val = $test;
+                }
+            }
+        }
+        
+        return $params;
+    }
 }
 
 ?>





More information about the icinga-checkins mailing list