Move functions Icingadb class into the new hook

This commit is contained in:
Johannes Meyer 2021-11-11 16:14:51 +01:00
parent bfe58ba4ec
commit d6fbcb6e4e
3 changed files with 5 additions and 44 deletions

View file

@ -7,7 +7,7 @@ namespace Icinga\Module\Icingadb\Controllers;
use Exception;
use Icinga\Exception\IcingaException;
use Icinga\Module\Icingadb\Compat\UrlMigrator;
use Icinga\Module\Icingadb\Icingadb;
use Icinga\Module\Icingadb\Hook\IcingadbSupportHook;
use Icinga\Module\Icingadb\Web\Controller;
use ipl\Web\Url;
@ -66,7 +66,7 @@ class MigrateController extends Controller
$this->assertHttpMethod('get');
$this->getResponse()
->setBody(Icingadb::isSetAsBackend())
->setBody(IcingadbSupportHook::isIcingaDbSetAsPreferredBackend())
->sendResponse();
exit;
}

View file

@ -8,7 +8,7 @@ use Exception;
use Icinga\Application\Config;
use Icinga\Authentication\Auth;
use Icinga\Data\ConfigObject;
use Icinga\Module\Icingadb\Icingadb;
use Icinga\Module\Icingadb\Hook\IcingadbSupportHook;
use Icinga\User\Preferences;
use Icinga\User\Preferences\PreferencesStore;
use Icinga\Web\Form;
@ -22,7 +22,7 @@ class SetAsBackendConfigForm extends Form
$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' => Icingadb::isSetAsBackend(),
'value' => IcingadbSupportHook::isIcingaDbSetAsPreferredBackend(),
]);
$this->addElement(
@ -86,7 +86,7 @@ class SetAsBackendConfigForm extends Form
$preferences = new Preferences($preferencesStore->load());
$webPreferences = $user->getPreferences()->get('icingaweb');
$webPreferences[Icingadb::PREFERENCE_NAME] = $setAsBackend;
$webPreferences[IcingadbSupportHook::PREFERENCE_NAME] = $setAsBackend;
$preferences->icingaweb = $webPreferences;
} catch (Exception $e) {
Notification::error('Failed to save the preference');

View file

@ -1,39 +0,0 @@
<?php
/* Icinga DB Web | (c) 2021 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Icingadb;
use Icinga\Application\Icinga;
use Icinga\Authentication\Auth;
class Icingadb
{
/** @var string key name of preference */
const PREFERENCE_NAME = 'icingadb_as_backend';
/**
* Whether icingadb is set as the backend source in preferences
*
* @return bool Return true if icingadb is set as backend, false otherwise
*/
public static function isSetAsBackend(): bool
{
$webPreferences = Auth::getInstance()->getUser()->getPreferences()->get('icingaweb');
if (! empty($webPreferences) && array_key_exists(static::PREFERENCE_NAME, $webPreferences)) {
return (bool) $webPreferences[static::PREFERENCE_NAME];
}
return false;
}
/**
* Whether to use icingadb as the backend
*
* @return bool Returns true if monitoring module is disabled or icingadb is selected as backend, false otherwise.
*/
public static function useAsBackend()
{
return ! Icinga::app()->getModuleManager()->hasEnabled('monitoring') || self::isSetAsBackend();
}
}