2018-10-08 00:33:02 -04:00
|
|
|
<?php
|
|
|
|
|
|
2026-03-24 06:30:06 -04:00
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2018-10-08 00:33:02 -04:00
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
|
|
|
|
|
use Icinga\Application\Config;
|
|
|
|
|
use Icinga\Authentication\Auth;
|
|
|
|
|
use Icinga\Module\Director\Db;
|
|
|
|
|
use Icinga\Module\Director\DirectorObject\Automation\BasketSnapshot;
|
|
|
|
|
use Icinga\Module\Director\Web\Controller\Extension\DirectorDb;
|
|
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
|
|
|
|
|
|
|
|
|
class RestoreBasketForm extends QuickForm
|
|
|
|
|
{
|
|
|
|
|
use DirectorDb;
|
|
|
|
|
|
|
|
|
|
/** @var BasketSnapshot */
|
|
|
|
|
private $snapshot;
|
|
|
|
|
|
|
|
|
|
public function setSnapshot(BasketSnapshot $snapshot)
|
|
|
|
|
{
|
|
|
|
|
$this->snapshot = $snapshot;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 04:49:03 -04:00
|
|
|
/**
|
|
|
|
|
* @codingStandardsIgnoreStart
|
|
|
|
|
* @return Auth
|
|
|
|
|
*/
|
2018-10-08 00:33:02 -04:00
|
|
|
protected function Auth()
|
|
|
|
|
{
|
|
|
|
|
return Auth::getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-08 04:49:03 -04:00
|
|
|
/**
|
|
|
|
|
* @return Config
|
|
|
|
|
*/
|
2018-10-08 00:33:02 -04:00
|
|
|
protected function Config()
|
|
|
|
|
{
|
2018-10-08 04:49:03 -04:00
|
|
|
// @codingStandardsIgnoreEnd
|
2018-10-08 00:33:02 -04:00
|
|
|
return Config::module('director');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws \Zend_Form_Exception
|
|
|
|
|
*/
|
|
|
|
|
public function setup()
|
|
|
|
|
{
|
|
|
|
|
$allowedDbs = $this->listAllowedDbResourceNames();
|
2018-12-10 18:26:01 -05:00
|
|
|
$this->addElement('select', 'target_db', [
|
|
|
|
|
'label' => $this->translate('Target DB'),
|
|
|
|
|
'description' => $this->translate('Restore to this target Director DB'),
|
|
|
|
|
'multiOptions' => $allowedDbs,
|
|
|
|
|
'value' => $this->getRequest()->getParam('target_db', $this->getFirstDbResourceName()),
|
|
|
|
|
'class' => 'autosubmit',
|
|
|
|
|
]);
|
2018-10-08 00:33:02 -04:00
|
|
|
|
|
|
|
|
$this->setSubmitLabel($this->translate('Restore'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDb()
|
|
|
|
|
{
|
|
|
|
|
return Db::fromResourceName($this->getValue('target_db'));
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-11 17:13:51 -04:00
|
|
|
/**
|
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
|
*/
|
2018-10-08 00:33:02 -04:00
|
|
|
public function onSuccess()
|
|
|
|
|
{
|
|
|
|
|
$this->snapshot->restoreTo($this->getDb());
|
|
|
|
|
$this->setSuccessUrl($this->getSuccessUrl()->with('target_db', $this->getValue('target_db')));
|
|
|
|
|
$this->setSuccessMessage(sprintf('Restored to %s', $this->getValue('target_db')));
|
|
|
|
|
|
|
|
|
|
parent::onSuccess();
|
|
|
|
|
}
|
|
|
|
|
}
|