Merge pull request #3588 from Icinga/fix/problems-the-world-has-and-ever-will
Fix problems the world has and ever will
This commit is contained in:
commit
1268c16a7f
|
@ -12,6 +12,7 @@ use Icinga\Application\Modules\Module;
|
||||||
use Icinga\Data\ResourceFactory;
|
use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
|
use Icinga\Forms\ActionForm;
|
||||||
use Icinga\Forms\Config\GeneralConfigForm;
|
use Icinga\Forms\Config\GeneralConfigForm;
|
||||||
use Icinga\Forms\Config\ResourceConfigForm;
|
use Icinga\Forms\Config\ResourceConfigForm;
|
||||||
use Icinga\Forms\Config\UserBackendConfigForm;
|
use Icinga\Forms\Config\UserBackendConfigForm;
|
||||||
|
@ -122,7 +123,20 @@ class ConfigController extends Controller
|
||||||
$module = new Module($app, $name, $manager->getModuleDir($name));
|
$module = new Module($app, $name, $manager->getModuleDir($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$toggleForm = new ActionForm();
|
||||||
|
$toggleForm->setDefaults(['identifier' => $name]);
|
||||||
|
if (! $this->view->moduleData->enabled) {
|
||||||
|
$toggleForm->setAction(Url::fromPath('config/moduleenable'));
|
||||||
|
$toggleForm->setDescription(sprintf($this->translate('Enable the %s module'), $name));
|
||||||
|
} elseif ($this->view->moduleData->loaded) {
|
||||||
|
$toggleForm->setAction(Url::fromPath('config/moduledisable'));
|
||||||
|
$toggleForm->setDescription(sprintf($this->translate('Disable the %s module'), $name));
|
||||||
|
} else {
|
||||||
|
$toggleForm = null;
|
||||||
|
}
|
||||||
|
|
||||||
$this->view->module = $module;
|
$this->view->module = $module;
|
||||||
|
$this->view->toggleForm = $toggleForm;
|
||||||
$this->view->tabs = $module->getConfigTabs()->activate('info');
|
$this->view->tabs = $module->getConfigTabs()->activate('info');
|
||||||
$this->view->moduleGitCommitId = Version::getGitHead($module->getBaseDir());
|
$this->view->moduleGitCommitId = Version::getGitHead($module->getBaseDir());
|
||||||
} else {
|
} else {
|
||||||
|
@ -137,15 +151,20 @@ class ConfigController extends Controller
|
||||||
public function moduleenableAction()
|
public function moduleenableAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission('config/modules');
|
$this->assertPermission('config/modules');
|
||||||
$module = $this->getParam('name');
|
|
||||||
$manager = Icinga::app()->getModuleManager();
|
$form = new ActionForm();
|
||||||
try {
|
$form->setOnSuccess(function (ActionForm $form) {
|
||||||
$manager->enableModule($module);
|
$module = $form->getValue('identifier');
|
||||||
|
Icinga::app()->getModuleManager()->enableModule($module);
|
||||||
Notification::success(sprintf($this->translate('Module "%s" enabled'), $module));
|
Notification::success(sprintf($this->translate('Module "%s" enabled'), $module));
|
||||||
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form->handleRequest();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->view->exceptionMessage = $e->getMessage();
|
$this->view->exceptionMessage = $e->getMessage();
|
||||||
$this->view->moduleName = $module;
|
$this->view->moduleName = $form->getValue('name');
|
||||||
$this->view->action = 'enable';
|
$this->view->action = 'enable';
|
||||||
$this->render('module-configuration-error');
|
$this->render('module-configuration-error');
|
||||||
}
|
}
|
||||||
|
@ -157,15 +176,20 @@ class ConfigController extends Controller
|
||||||
public function moduledisableAction()
|
public function moduledisableAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission('config/modules');
|
$this->assertPermission('config/modules');
|
||||||
$module = $this->getParam('name');
|
|
||||||
$manager = Icinga::app()->getModuleManager();
|
$form = new ActionForm();
|
||||||
try {
|
$form->setOnSuccess(function (ActionForm $form) {
|
||||||
$manager->disableModule($module);
|
$module = $form->getValue('identifier');
|
||||||
|
Icinga::app()->getModuleManager()->disableModule($module);
|
||||||
Notification::success(sprintf($this->translate('Module "%s" disabled'), $module));
|
Notification::success(sprintf($this->translate('Module "%s" disabled'), $module));
|
||||||
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form->handleRequest();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->view->exceptionMessage = $e->getMessage();
|
$this->view->exceptionMessage = $e->getMessage();
|
||||||
$this->view->moduleName = $module;
|
$this->view->moduleName = $form->getValue('name');
|
||||||
$this->view->action = 'disable';
|
$this->view->action = 'disable';
|
||||||
$this->render('module-configuration-error');
|
$this->render('module-configuration-error');
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2018 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Forms;
|
||||||
|
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
|
||||||
|
class ActionForm extends Form
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The icon shown on the button
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $icon = 'arrows-cw';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the icon to show on the button
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setIcon($name)
|
||||||
|
{
|
||||||
|
$this->icon = (string) $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setAttrib('class', 'inline');
|
||||||
|
$this->setUidDisabled(true);
|
||||||
|
$this->setDecorators(['FormElements', 'Form']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
$this->addElement(
|
||||||
|
'hidden',
|
||||||
|
'identifier',
|
||||||
|
[
|
||||||
|
'required' => true,
|
||||||
|
'decorators' => ['ViewHelper']
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$this->addElement(
|
||||||
|
'button',
|
||||||
|
'btn_submit',
|
||||||
|
[
|
||||||
|
'escape' => false,
|
||||||
|
'type' => 'submit',
|
||||||
|
'class' => 'link-button spinner',
|
||||||
|
'value' => 'btn_submit',
|
||||||
|
'decorators' => ['ViewHelper'],
|
||||||
|
'label' => $this->getView()->icon($this->icon),
|
||||||
|
'title' => $this->getDescription()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,22 +18,11 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= $this->translate('State') ?></th>
|
<th><?= $this->translate('State') ?></th>
|
||||||
<td><?= $state ?><?php if ($state === 'enabled'): ?>
|
<td>
|
||||||
<?= $this->qlink(
|
<?= $state ?>
|
||||||
$this->translate('disable'),
|
<?php if (isset($this->toggleForm)): ?>
|
||||||
'config/moduledisable',
|
<?= $this->toggleForm ?>
|
||||||
array('name' => $module->getName()),
|
<?php endif ?>
|
||||||
array('title' => sprintf($this->translate('Disable the %s module'), $module->getName()), 'class' => 'action-link')
|
|
||||||
); ?>
|
|
||||||
<?php endif ?>
|
|
||||||
<?php if ($state === 'disabled'): ?>
|
|
||||||
<?= $this->qlink(
|
|
||||||
$this->translate('enable'),
|
|
||||||
'config/moduleenable',
|
|
||||||
array('name' => $module->getName()),
|
|
||||||
array('title' => sprintf($this->translate('Enable the %s module'), $module->getName()), 'class' => 'action-link')
|
|
||||||
); ?>
|
|
||||||
<?php endif ?>
|
|
||||||
</td>
|
</td>
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= $this->escape($this->translate('Version')) ?></th>
|
<th><?= $this->escape($this->translate('Version')) ?></th>
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
echo $this->qlink(
|
echo $this->qlink(
|
||||||
$module->name,
|
$module->name,
|
||||||
'config/module/',
|
'config/module',
|
||||||
array('name' => $module->name),
|
array('name' => $module->name),
|
||||||
array(
|
array(
|
||||||
'class' => 'rowaction',
|
'class' => 'rowaction',
|
||||||
|
|
|
@ -262,7 +262,7 @@ class IniParser
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$configArray = parse_ini_string($content, true);
|
$configArray = parse_ini_string($content, true, INI_SCANNER_RAW);
|
||||||
} catch (ErrorException $e) {
|
} catch (ErrorException $e) {
|
||||||
throw new ConfigurationError('Couldn\'t parse the INI file `%s\'', $path, $e);
|
throw new ConfigurationError('Couldn\'t parse the INI file `%s\'', $path, $e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ $this->addHelperFunction('img', function ($url, $params = null, array $propertie
|
||||||
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<img src="%s"%s />',
|
'<img src="%s"%s />',
|
||||||
$view->url($url, $params),
|
$view->escape($view->url($url, $params)),
|
||||||
$view->propertiesToString($properties)
|
$view->propertiesToString($properties)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue