[icinga-checkins] icinga.org: icingaweb2-module-director/master: ShowController: try hard to render erraneous...

git at icinga.org git at icinga.org
Mon Oct 10 12:00:29 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: 3423ddf60518b0895baf7c616cdeb231878f545d
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=3423ddf60518b0895baf7c616cdeb231878f545d

Author: Thomas Gelf <thomas at gelf.net>
Date:   Sun Oct  9 13:12:18 2016 +0000

ShowController: try hard to render erraneous...

...activity log entries

---

 application/controllers/ShowController.php |   30 ++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/application/controllers/ShowController.php b/application/controllers/ShowController.php
index 8d26788..87e6ce7 100644
--- a/application/controllers/ShowController.php
+++ b/application/controllers/ShowController.php
@@ -7,6 +7,7 @@ use Icinga\Module\Director\IcingaConfig\IcingaConfig;
 use Icinga\Module\Director\Web\Controller\ActionController;
 use Icinga\Module\Director\Util;
 use Icinga\Module\Director\Objects\IcingaObject;
+use Exception;
 
 class ShowController extends ActionController
 {
@@ -81,7 +82,17 @@ class ShowController extends ActionController
             $object->object_type = 'object';
         }
 
-        $object->renderToConfig($config);
+        try {
+            $object->renderToConfig($config);
+        } catch (Exception $e) {
+            $config->configFile(
+                'failed-to-render'
+            )->prepend(
+                "/** Failed to render this object **/\n"
+                . '/*  ' . $e->getMessage() . ' */'
+            );
+        }
+
         return $config;
     }
 
@@ -247,10 +258,17 @@ class ShowController extends ActionController
     protected function createObject($type, $props)
     {
         $props = json_decode($props);
-        return IcingaObject::createByType($type, array(
-            'object_name' => $props->object_name,
-            'object_type' => $props->object_type,
-        ), $this->db())->setProperties((array) $props);
-        return IcingaObject::createByType($type, (array) $props, $this->db());
+        $newProps = array(
+            'object_name' => $props->object_name
+        );
+        if (property_exists($props, 'object_type')) {
+            $newProps['object_type'] = $props->object_type;
+        }
+
+        return IcingaObject::createByType(
+            $type,
+            $newProps,
+            $this->db()
+        )->setProperties((array) $props);
     }
 }



More information about the icinga-checkins mailing list