2016-03-16 16:02:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
|
|
use Icinga\Module\Director\Objects\IcingaObject;
|
2017-07-25 14:04:08 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\DirectorForm;
|
2016-03-16 16:02:17 +01:00
|
|
|
|
2017-07-25 14:04:08 +02:00
|
|
|
class RestoreObjectForm extends DirectorForm
|
2016-03-16 16:02:17 +01:00
|
|
|
{
|
2016-11-01 18:28:36 +01:00
|
|
|
/** @var IcingaObject */
|
2016-03-16 16:02:17 +01:00
|
|
|
protected $object;
|
|
|
|
|
|
|
|
public function setup()
|
|
|
|
{
|
2017-07-25 14:04:08 +02:00
|
|
|
$this->addSubmitButton($this->translate('Restore former object'));
|
2016-03-16 16:02:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function onSuccess()
|
|
|
|
{
|
|
|
|
$object = $this->object;
|
2016-11-01 18:28:36 +01:00
|
|
|
$name = $object->getObjectName();
|
2016-03-16 16:02:17 +01:00
|
|
|
$db = $this->db;
|
|
|
|
|
|
|
|
// TODO: service -> multi-key
|
|
|
|
if ($object::exists($name, $db)) {
|
2017-07-25 14:04:08 +02:00
|
|
|
$existing = $object::load($name, $db)->replaceWith($object);
|
|
|
|
|
|
|
|
if ($existing->hasBeenModified()) {
|
|
|
|
$msg = $this->translate('Object has been restored');
|
|
|
|
$existing->store();
|
|
|
|
} else {
|
|
|
|
$msg = $this->translate(
|
|
|
|
'Nothing to do, restore would not modify the current object'
|
|
|
|
);
|
|
|
|
}
|
2016-03-16 16:02:17 +01:00
|
|
|
} else {
|
2017-07-25 14:04:08 +02:00
|
|
|
$msg = $this->translate('Object has been re-created');
|
2016-03-16 16:02:17 +01:00
|
|
|
$object->store($db);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->redirectOnSuccess($msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setObject(IcingaObject $object)
|
|
|
|
{
|
|
|
|
$this->object = $object;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|