Drop class SetAsBackendConfigForm

This commit is contained in:
Johannes Meyer 2022-02-24 16:13:33 +01:00
parent 0851f6f045
commit 598d26f0f9
3 changed files with 0 additions and 124 deletions

View file

@ -5,7 +5,6 @@
namespace Icinga\Module\Icingadb\Controllers;
use Icinga\Application\Config;
use Icinga\Module\Icingadb\Forms\SetAsBackendConfigForm;
use Icinga\Module\Icingadb\Forms\DatabaseConfigForm;
use Icinga\Module\Icingadb\Forms\RedisConfigForm;
use Icinga\Module\Icingadb\Web\Controller;
@ -47,15 +46,6 @@ class ConfigController extends Controller
$this->addFormToContent($form);
}
public function backendAction()
{
$form = new SetAsBackendConfigForm();
$form->handleRequest();
$this->mergeTabs($this->Module()->getConfigTabs()->activate('backend'));
$this->addFormToContent($form);
}
protected function addFormToContent(Form $form)
{
$this->addContent(new HtmlString($form->render()));

View file

@ -1,105 +0,0 @@
<?php
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb\Forms;
use Exception;
use Icinga\Application\Config;
use Icinga\Authentication\Auth;
use Icinga\Data\ConfigObject;
use Icinga\Module\Icingadb\Hook\IcingadbSupportHook;
use Icinga\User\Preferences;
use Icinga\User\Preferences\PreferencesStore;
use Icinga\Web\Form;
use Icinga\Web\Notification;
use Icinga\Web\Session;
class SetAsBackendConfigForm extends Form
{
public function createElements(array $formData)
{
$this->addElement('checkbox', 'backend', [
'label' => t('Use icinga DB as backend for all modules'),
'description' => t('Use icinga db as backend resource for all modules'),
'value' => IcingadbSupportHook::isIcingaDbSetAsPreferredBackend(),
]);
$this->addElement(
'submit',
'btn_submit',
array(
'ignore' => true,
'label' => t('Save to the Preferences'),
'decorators' => array('ViewHelper'),
'class' => 'btn-primary'
)
);
$this->addElement(
'submit',
'btn_submit_session',
array(
'ignore' => true,
'label' => t('Save for the current Session'),
'decorators' => array('ViewHelper')
)
);
$this->setAttrib('data-progress-element', 'preferences-progress');
$this->addElement(
'note',
'preferences-progress',
array(
'decorators' => array(
'ViewHelper',
array('Spinner', array('id' => 'preferences-progress'))
)
)
);
$this->addDisplayGroup(
array('btn_submit', 'btn_submit_session', 'preferences-progress'),
'submit_buttons',
array(
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls'))
)
)
);
}
public function onSuccess()
{
$this->save($this->getElement('backend')->isChecked());
}
public function save($setAsBackend)
{
$user = Auth::getInstance()->getUser();
try {
$preferencesStore = PreferencesStore::create(new ConfigObject([
'store' => Config::app()->get('global', 'config_backend', 'db'),
'resource' => Config::app()->get('global', 'config_resource')
]), $user);
$preferences = new Preferences($preferencesStore->load());
$webPreferences = $user->getPreferences()->get('icingaweb');
$webPreferences[IcingadbSupportHook::PREFERENCE_NAME] = $setAsBackend;
$preferences->icingaweb = $webPreferences;
} catch (Exception $e) {
Notification::error('Failed to save the preference');
return;
}
Session::getSession()->user->setPreferences($preferences);
if ($this->getElement('btn_submit') !== null && $this->getElement('btn_submit')->isChecked()) {
$preferencesStore->save($preferences);
Notification::success($this->translate('Preference successfully saved'));
} else {
Notification::success($this->translate('Preference successfully saved for the current session'));
}
}
}

View file

@ -540,15 +540,6 @@ namespace Icinga\Module\Icingadb {
'title' => t('Configure the database backend'),
'url' => 'config/database'
]);
if ($this::exists('monitoring')) {
$this->provideConfigTab('backend', [
'label' => t('Backend'),
'title' => t('Configure IcingaDB as the Backend'),
'url' => 'config/backend'
]);
}
$this->provideConfigTab('redis', [
'label' => t('Redis'),
'title' => t('Configure the Redis connections'),