From d6fbcb6e4efa92f7e2563538d44e464fa22d3f10 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 11 Nov 2021 16:14:51 +0100 Subject: [PATCH] Move functions `Icingadb` class into the new hook --- application/controllers/MigrateController.php | 4 +- application/forms/SetAsBackendConfigForm.php | 6 +-- library/Icingadb/Icingadb.php | 39 ------------------- 3 files changed, 5 insertions(+), 44 deletions(-) delete mode 100644 library/Icingadb/Icingadb.php diff --git a/application/controllers/MigrateController.php b/application/controllers/MigrateController.php index 3e8ca679..6ddc9446 100644 --- a/application/controllers/MigrateController.php +++ b/application/controllers/MigrateController.php @@ -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; } diff --git a/application/forms/SetAsBackendConfigForm.php b/application/forms/SetAsBackendConfigForm.php index 0071c9f5..79c75ae0 100644 --- a/application/forms/SetAsBackendConfigForm.php +++ b/application/forms/SetAsBackendConfigForm.php @@ -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'); diff --git a/library/Icingadb/Icingadb.php b/library/Icingadb/Icingadb.php deleted file mode 100644 index fb8e06dc..00000000 --- a/library/Icingadb/Icingadb.php +++ /dev/null @@ -1,39 +0,0 @@ -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(); - } -}