Skip to content

Commit

Permalink
ActivityLog: Link back to the correct frontend for service and servic…
Browse files Browse the repository at this point in the history
…eset

fixes #1377
  • Loading branch information
lazyfrosch committed Mar 28, 2019
1 parent 0d3649c commit 4050fff
Showing 1 changed file with 84 additions and 2 deletions.
86 changes: 84 additions & 2 deletions library/Director/Web/Widget/ActivityLogInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
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;
Expand Down Expand Up @@ -39,6 +41,10 @@ class ActivityLogInfo extends HtmlDocument

protected $entry;

protected $oldProperties;

protected $newProperties;

protected $oldObject;

/** @var Tabs */
Expand Down Expand Up @@ -200,6 +206,7 @@ public function getCurrentObject()

/**
* @return bool
* @deprecated No longer used?
*/
public function objectStillExists()
{
Expand All @@ -210,6 +217,75 @@ public function objectStillExists()
);
}

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;
Expand Down Expand Up @@ -363,10 +439,16 @@ protected function getLinkToObject()
{
$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']
);
}
Expand Down

0 comments on commit 4050fff

Please sign in to comment.