diff --git a/library/Director/Objects/DirectorActivityLog.php b/library/Director/Objects/DirectorActivityLog.php index cb041b61..2cecc2ee 100644 --- a/library/Director/Objects/DirectorActivityLog.php +++ b/library/Director/Objects/DirectorActivityLog.php @@ -7,6 +7,7 @@ use Icinga\Module\Director\Db; use Icinga\Authentication\Auth; use Icinga\Application\Icinga; use Icinga\Application\Logger; +use stdClass; class DirectorActivityLog extends DbObject { @@ -176,7 +177,19 @@ class DirectorActivityLog extends DbObject { $name = $object->getObjectName(); $type = $object->getTableName(); - $oldProps = json_encode($object->getPlainUnmodifiedObject()); + /** @var stdClass $plainUnmodifiedObject */ + $plainUnmodifiedObject = $object->getPlainUnmodifiedObject(); + + if ($object instanceof IcingaServiceSet) { + $services = []; + foreach ($object->getCachedServices() as $service) { + $services[$service->getObjectName()] = $service->toPlainObject(); + } + + $plainUnmodifiedObject->services = $services; + } + + $oldProps = json_encode($plainUnmodifiedObject); $data = [ 'object_name' => $name, diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index d15bae97..252c52a0 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -44,9 +44,33 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface 'host' => 'IcingaHost', ); + /** @var IcingaService[] Cached services */ + protected $cachedServices = []; + /** @var IcingaService[]|null */ private $services; + /** + * Set the services to be cached + * + * @param $services IcingaService[] + * @return void + */ + public function setCachedServices($services) + { + $this->cachedServices = $services; + } + + /** + * Get the cached services + * + * @return IcingaService[] + */ + public function getCachedServices() + { + return $this->cachedServices; + } + public function isDisabled() { return false; @@ -110,7 +134,12 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface protected function storeRelatedServices() { if ($this->services === null) { - return; + $cachedServices = $this->getCachedServices(); + if ($cachedServices) { + $this->services = $cachedServices; + } else { + return; + } } $seen = []; @@ -179,6 +208,7 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface public function beforeDelete() { + $this->setCachedServices($this->getServices()); // check if this is a template, or directly assigned to a host if ($this->get('host_id') === null) { // find all host sets and delete them diff --git a/library/Director/Web/Widget/ActivityLogInfo.php b/library/Director/Web/Widget/ActivityLogInfo.php index 8034c5a4..2b64fd42 100644 --- a/library/Director/Web/Widget/ActivityLogInfo.php +++ b/library/Director/Web/Widget/ActivityLogInfo.php @@ -3,7 +3,10 @@ namespace Icinga\Module\Director\Web\Widget; use gipfl\Json\JsonString; +use Icinga\Module\Director\Data\FieldReferenceLoader; +use Icinga\Module\Director\DirectorObject\Automation\BasketSnapshotFieldResolver; use Icinga\Module\Director\Objects\DirectorActivityLog; +use Icinga\Module\Director\Web\Form\IcingaObjectFieldLoader; use ipl\Html\HtmlDocument; use ipl\Html\HtmlElement; use Icinga\Date\DateFormatter; @@ -433,11 +436,30 @@ class ActivityLogInfo extends HtmlDocument { if ($object instanceof IcingaService) { return $this->previewService($object); + } elseif ($object instanceof IcingaServiceSet) { + return $this->previewServiceSet($object); } else { return $object->toSingleIcingaConfig(); } } + /** + * Render service set to be previewed + * + * @param IcingaServiceSet $object + * + * @return IcingaConfig + */ + protected function previewServiceSet(IcingaServiceSet $object) + { + $config = $object->toSingleIcingaConfig(); + foreach ($object->getCachedServices() as $service) { + $service->renderToConfig($config); + } + + return $config; + } + protected function previewService(IcingaService $service) { if (($set = $service->get('service_set')) !== null) { @@ -624,10 +646,27 @@ class ActivityLogInfo extends HtmlDocument $newProps['object_type'] = $props->object_type; } - return IcingaObject::createByType( + $object = IcingaObject::createByType( $type, $newProps, $this->db - )->setProperties((array) $props); + ); + + if ($type === 'icinga_service_set' && isset($props->services)) { + $services = []; + foreach ($props->services as $service) { + $services[$service->object_name] = IcingaObject::createByType( + 'icinga_service', + (array) $service, + $this->db + ); + } + + /** @var IcingaServiceSet $object */ + $object->setCachedServices($services); + unset($props->services); + } + + return $object->setProperties((array) $props); } }