Adjust editbackend-action to suit the new backend-form interface
refs #5525
This commit is contained in:
parent
488ea4633d
commit
b743cf8143
|
@ -3,12 +3,12 @@
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
use \Exception;
|
use \Exception;
|
||||||
|
use \Zend_Config;
|
||||||
use Icinga\Config\PreservingIniWriter;
|
use Icinga\Config\PreservingIniWriter;
|
||||||
use Icinga\Web\Controller\ModuleActionController;
|
use Icinga\Web\Controller\ModuleActionController;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
use Icinga\Module\Monitoring\Form\Config\BackendForm;
|
||||||
use Icinga\Module\Monitoring\Form\Config\ConfirmRemovalForm;
|
use Icinga\Module\Monitoring\Form\Config\ConfirmRemovalForm;
|
||||||
use Icinga\Module\Monitoring\Form\Config\Backend\EditBackendForm;
|
|
||||||
use Icinga\Module\Monitoring\Form\Config\Backend\CreateBackendForm;
|
|
||||||
use Icinga\Module\Monitoring\Form\Config\Instance\EditInstanceForm;
|
use Icinga\Module\Monitoring\Form\Config\Instance\EditInstanceForm;
|
||||||
use Icinga\Module\Monitoring\Form\Config\Instance\CreateInstanceForm;
|
use Icinga\Module\Monitoring\Form\Config\Instance\CreateInstanceForm;
|
||||||
use Icinga\Exception\NotReadableError;
|
use Icinga\Exception\NotReadableError;
|
||||||
|
@ -43,29 +43,40 @@ class Monitoring_ConfigController extends ModuleActionController
|
||||||
*/
|
*/
|
||||||
public function editbackendAction()
|
public function editbackendAction()
|
||||||
{
|
{
|
||||||
|
// Fetch the backend to be edited
|
||||||
$backend = $this->getParam('backend');
|
$backend = $this->getParam('backend');
|
||||||
if (!$this->isExistingBackend($backend)) {
|
$backendsConfig = $this->Config('backends')->toArray();
|
||||||
$this->view->error = 'Unknown backend ' . $backend;
|
if (false === array_key_exists($backend, $backendsConfig)) {
|
||||||
return;
|
// TODO: Should behave as in the app's config controller (Specific redirect to an error action)
|
||||||
|
Notification::error(sprintf($this->translate('Cannot edit "%s". Backend not found.'), $backend));
|
||||||
|
$this->redirectNow('monitoring/config');
|
||||||
}
|
}
|
||||||
$backendForm = new EditBackendForm();
|
|
||||||
$backendForm->setRequest($this->getRequest());
|
|
||||||
$backendForm->setBackendConfiguration($this->Config('backends')->get($backend));
|
|
||||||
|
|
||||||
if ($backendForm->isSubmittedAndValid()) {
|
$form = new BackendForm();
|
||||||
$newConfig = $backendForm->getConfig();
|
$request = $this->getRequest();
|
||||||
$config = $this->Config('backends');
|
if ($request->isPost()) {
|
||||||
$config->$backend = $newConfig;
|
if ($form->isValid($request->getPost())) {
|
||||||
if ($this->writeConfiguration($config, 'backends')) {
|
list($newName, $config) = $form->getBackendConfig();
|
||||||
Notification::success('Backend ' . $backend . ' Modified.');
|
|
||||||
$this->redirectNow('monitoring/config');
|
if ($newName !== $backend) {
|
||||||
} else {
|
// Backend name has changed
|
||||||
$this->render('show-configuration');
|
unset($backendsConfig[$backend]); // We can safely use unset as all values are part of the form
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
$backendsConfig[$newName] = $config;
|
||||||
|
if ($this->writeConfiguration($backendsConfig, 'backends')) {
|
||||||
|
Notification::success(sprintf($this->translate('Backend "%s" successfully modified.'), $backend));
|
||||||
|
$this->redirectNow('monitoring/config');
|
||||||
|
} else {
|
||||||
|
$this->render('show-configuration');
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$form->setBackendConfig($backend, $backendsConfig[$backend]);
|
||||||
}
|
}
|
||||||
$this->view->name = $backend;
|
|
||||||
$this->view->form = $backendForm;
|
$this->view->form = $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -218,6 +229,9 @@ class Monitoring_ConfigController extends ModuleActionController
|
||||||
*/
|
*/
|
||||||
protected function writeConfiguration($config, $file)
|
protected function writeConfiguration($config, $file)
|
||||||
{
|
{
|
||||||
|
if (is_array($config)) {
|
||||||
|
$config = new Zend_Config($config);
|
||||||
|
}
|
||||||
$target = $this->Config($file)->getConfigFile();
|
$target = $this->Config($file)->getConfigFile();
|
||||||
$writer = new PreservingIniWriter(array('filename' => $target, 'config' => $config));
|
$writer = new PreservingIniWriter(array('filename' => $target, 'config' => $config));
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,2 @@
|
||||||
<?php if ($this->name): ?>
|
<h4><?= $this->translate('Edit Existing Backend'); ?></h4>
|
||||||
<h4><i> <i class="icinga-icon-edit"></i> Edit Backend "<?= $this->escape($this->name) ?>"</h4>
|
<?= $form; ?>
|
||||||
<?php else: ?>
|
|
||||||
<h4> <i class="icinga-icon-create"></i> Create New Backend</h4>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ($this->error): ?>
|
|
||||||
<div class="alert alert-danger">
|
|
||||||
<?= $this->escape($this->error); ?>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?= $this->form; ?>
|
|
Loading…
Reference in New Issue