Merge branch 'bugfix/renaming-the-resource-used-for-the-config-backend-9804'

fixes #9804
This commit is contained in:
Johannes Meyer 2016-11-11 11:03:33 +01:00
commit f3b1d28f7d
2 changed files with 43 additions and 3 deletions

View File

@ -395,10 +395,10 @@ class ConfigController extends Controller
$authConfig = Config::app('authentication');
foreach ($authConfig as $backendName => $config) {
if ($config->get('resource') === $resource) {
$form->addDescription(sprintf(
$form->warning(sprintf(
$this->translate(
'The resource "%s" is currently utilized for authentication by user backend "%s". ' .
'Removing the resource can result in noone being able to log in any longer.'
'The resource "%s" is currently utilized for authentication by user backend "%s".'
. ' Removing the resource can result in noone being able to log in any longer.'
),
$resource,
$backendName
@ -406,6 +406,17 @@ class ConfigController extends Controller
}
}
// Check if selected resource is currently used as user preferences backend
if (Config::app()->get('global', 'config_resource') === $resource) {
$form->warning(sprintf(
$this->translate(
'The resource "%s" is currently utilized to store user preferences. Removing the'
. ' resource causes all current user preferences not being available any longer.'
),
$resource
));
}
$this->view->form = $form;
$this->render('resource/remove');
}

View File

@ -3,6 +3,7 @@
namespace Icinga\Forms\Config;
use Icinga\Application\Config;
use InvalidArgumentException;
use Icinga\Application\Platform;
use Icinga\Exception\ConfigurationError;
@ -21,6 +22,13 @@ use Icinga\Web\Notification;
class ResourceConfigForm extends ConfigForm
{
/**
* If the global config must be updated because a resource has been changed, this is the updated global config
*
* @var Config|null
*/
protected $updatedAppConfig = null;
/**
* Initialize this form
*/
@ -104,6 +112,16 @@ class ResourceConfigForm extends ConfigForm
$this->config->removeSection($name);
unset($values['name']);
$this->config->setSection($newName, $resourceConfig->merge($values));
if ($newName !== $name) {
$appConfig = Config::app();
$section = $appConfig->getSection('global');
if ($section->config_resource === $name) {
$section->config_resource = $newName;
$this->updatedAppConfig = $appConfig->setSection('global', $section);
}
}
return $resourceConfig;
}
@ -376,4 +394,15 @@ class ResourceConfigForm extends ConfigForm
return $this;
}
/**
* {@inheritDoc}
*/
protected function writeConfig(Config $config)
{
parent::writeConfig($config);
if ($this->updatedAppConfig !== null) {
$this->updatedAppConfig->saveIni();
}
}
}