diff --git a/application/controllers/ShowController.php b/application/controllers/ShowController.php index a7a6500f..b915d648 100644 --- a/application/controllers/ShowController.php +++ b/application/controllers/ShowController.php @@ -11,6 +11,8 @@ class ShowController extends ActionController { protected $defaultTab; + protected $oldObject; + protected function activityTabs($entry) { $tabs = $this->getTabs(); @@ -87,7 +89,14 @@ class ShowController extends ActionController protected function oldObject($entry) { - return $this->createObject($entry->object_type, $entry->old_properties); + if ($this->oldObject === null) { + $this->oldObject = $this->createObject( + $entry->object_type, + $entry->old_properties + ); + } + + return $this->oldObject; } protected function newObject($entry) @@ -167,6 +176,15 @@ class ShowController extends ActionController ); $entry = $v->entry; + + if ($entry->old_properties) { + $this->view->form = $this + ->loadForm('restoreObject') + ->setDb($this->db()) + ->setObject($this->oldObject($entry)) + ->handleRequest(); + } + $this->activityTabs($entry); $this->showInfo($entry); $func = 'show' . ucfirst($this->params->get('show', $this->defaultTab)); diff --git a/application/forms/RestoreObjectForm.php b/application/forms/RestoreObjectForm.php new file mode 100644 index 00000000..d6a72f74 --- /dev/null +++ b/application/forms/RestoreObjectForm.php @@ -0,0 +1,56 @@ +submitLabel = $this->translate('Restore former object'); + } + + protected function addSubmitButtonIfSet() + { + $res = parent::addSubmitButtonIfSet(); + $this->getDisplayGroup('buttons')->setDecorators(array('FormElements')); + return $res; + } + + public function onSuccess() + { + $object = $this->object; + $name = $object->object_name; + $db = $this->db; + $msg = $this->translate('Object has been restored'); + + // TODO: service -> multi-key + if ($object::exists($name, $db)) { + $object::load($name, $db)->replaceWith($object)->store(); + } else { + $object->store($db); + } + + $this->redirectOnSuccess($msg); + } + + public function setDb($db) + { + $this->db = $db; + return $this; + } + + public function setObject(IcingaObject $object) + { + $this->object = $object; + return $this; + } +} diff --git a/application/views/scripts/show/activitylog.phtml b/application/views/scripts/show/activitylog.phtml index 7a332dc4..cdf2ca8b 100644 --- a/application/views/scripts/show/activitylog.phtml +++ b/application/views/scripts/show/activitylog.phtml @@ -62,6 +62,12 @@ $url = $this->url()->without('checksum')->without('show');