icingaweb2-module-director/application/controllers/ShowController.php

56 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2015-10-20 22:34:04 +02:00
namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\Objects\IcingaObject;
2015-09-14 16:26:51 +02:00
use Icinga\Module\Director\ConfigDiff;
2015-06-23 14:37:23 +02:00
use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ActionController;
2015-10-20 22:34:04 +02:00
class ShowController extends ActionController
{
public function activitylogAction()
{
if ($id = $this->params->get('id')) {
2015-06-18 11:01:45 +02:00
$this->view->entry = $this->db()->fetchActivityLogEntryById($id);
} elseif ($checksum = $this->params->get('checksum')) {
2015-06-23 14:37:23 +02:00
$this->view->entry = $this->db()->fetchActivityLogEntry(Util::hex2binary($checksum));
}
2015-06-18 11:01:45 +02:00
$entry = $this->view->entry;
if ($entry->old_properties) {
$old = $this->createObject($entry->object_type, $entry->old_properties);
if ($entry->new_properties) {
$new = $this->createObject($entry->object_type, $entry->old_properties);
$new->setProperties((array) json_decode($entry->new_properties));
} else {
$new = null;
}
} else {
$old = null;
$new = $this->createObject($entry->object_type, $entry->new_properties);
}
2015-09-14 16:26:51 +02:00
if ($old && $new) {
$d = ConfigDiff::create($old, $new);
$this->view->diff = strtr(
$d->renderHtml(),
array('\\n' => "\\n\n")
);
}
$this->view->entry = $entry;
$this->view->newObject = $new;
$this->view->oldObject = $old;
2015-06-18 11:01:45 +02:00
$this->view->title = $this->translate('Activity');
}
protected function createObject($type, $props)
{
$props = json_decode($props);
return IcingaObject::createByType($type, (array) $props, $this->db());
}
}