From 3423ddf60518b0895baf7c616cdeb231878f545d Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 9 Oct 2016 13:12:18 +0000 Subject: [PATCH] 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 8d267888..87e6ce78 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); } }