From 7b9e9f3a2f66516d90750cdd84c25ce955b7892c Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Thu, 28 Mar 2019 17:11:43 +0100 Subject: [PATCH] ActivityLog: Link back to the correct frontend for service and serviceset fixes #1377 --- .../Director/Web/Widget/ActivityLogInfo.php | 86 ++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/library/Director/Web/Widget/ActivityLogInfo.php b/library/Director/Web/Widget/ActivityLogInfo.php index 7471af2d..a147029d 100644 --- a/library/Director/Web/Widget/ActivityLogInfo.php +++ b/library/Director/Web/Widget/ActivityLogInfo.php @@ -11,6 +11,8 @@ use Icinga\Module\Director\Db; use Icinga\Module\Director\Forms\RestoreObjectForm; use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\Objects\IcingaObject; +use Icinga\Module\Director\Objects\IcingaService; +use Icinga\Module\Director\Objects\IcingaServiceSet; use dipl\Html\Html; use dipl\Html\Icon; use dipl\Html\Link; @@ -39,6 +41,10 @@ class ActivityLogInfo extends HtmlDocument protected $entry; + protected $oldProperties; + + protected $newProperties; + protected $oldObject; /** @var Tabs */ @@ -200,6 +206,7 @@ class ActivityLogInfo extends HtmlDocument /** * @return bool + * @deprecated No longer used? */ public function objectStillExists() { @@ -210,6 +217,75 @@ class ActivityLogInfo extends HtmlDocument ); } + protected function oldProperties() + { + if ($this->oldProperties === null) { + if (property_exists($this->entry, 'old_properties')) { + $this->oldProperties = json_decode($this->entry->old_properties); + } + if ($this->oldProperties === null) { + $this->oldProperties = new \stdClass; + } + } + + return $this->oldProperties; + } + + protected function newProperties() + { + if ($this->newProperties === null) { + if (property_exists($this->entry, 'new_properties')) { + $this->newProperties = json_decode($this->entry->new_properties); + } else { + $this->newProperties = new \stdClass; + } + } + + return $this->newProperties; + } + + protected function getEntryProperty($key) + { + $entry = $this->entry; + + if (property_exists($entry, $key)) { + return $entry->{$key}; + } elseif (property_exists($this->newProperties(), $key)) { + return $this->newProperties->{$key}; + } elseif (property_exists($this->oldProperties(), $key)) { + return $this->oldProperties->{$key}; + } else { + return null; + } + } + + protected function objectLinkParams() + { + $entry = $this->entry; + + $params = ['name' => $entry->object_name]; + + if ($entry->object_type === 'icinga_service') { + if (($set = $this->getEntryProperty('service_set')) !== null) { + $params['set'] = $set; + return $params; + } elseif (($host = $this->getEntryProperty('host')) !== null) { + $params['host'] = $host; + return $params; + } else { + return $params; + } + } elseif ($entry->object_type === 'icinga_service_set') { + return $params; + } else { + return $params; + } + } + + /** + * @return array + * @deprecated No longer used? + */ protected function objectKey() { $entry = $this->entry; @@ -363,10 +439,16 @@ class ActivityLogInfo extends HtmlDocument { $entry = $this->entry; $name = $entry->object_name; + $controller = preg_replace('/^icinga_/', '', $entry->object_type); + + if ($controller === 'service_set') { + $controller = 'serviceset'; + } + return Link::create( $name, - 'director/' . preg_replace('/^icinga_/', '', $entry->object_type), - ['name' => $name], + 'director/' . $controller, + $this->objectLinkParams(), ['data-base-target' => '_next'] ); }