icingaweb2-module-director/application/forms/RestoreObjectForm.php

50 lines
1.3 KiB
PHP
Raw Normal View History

2016-03-16 16:02:17 +01:00
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Web\Form\DirectorForm;
2016-03-16 16:02:17 +01: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()
{
$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)) {
$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 {
$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;
}
}