From bf2b90fd6c38b1c94103a2ca71e2dadc3ca0bff0 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 13 Jul 2017 15:37:30 +0200 Subject: [PATCH] Settings: fix global zone defaults and settings --- application/forms/SettingsForm.php | 21 ++++++++++++++------- library/Director/Settings.php | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/application/forms/SettingsForm.php b/application/forms/SettingsForm.php index c6b8152e..274bc865 100644 --- a/application/forms/SettingsForm.php +++ b/application/forms/SettingsForm.php @@ -23,13 +23,7 @@ class SettingsForm extends DirectorForm . ' environment.' ) ); - - $globalZones = array( - null => sprintf( - $this->translate('%s (default)'), - $settings->getDefaultValue('default_global_zone') - ) - ); + $globalZones = $this->eventuallyConfiguredEnum('default_global_zone', $this->enumGlobalZones()); $this->addElement('select', 'default_global_zone', array( 'label' => $this->translate('Default global zone'), @@ -158,6 +152,19 @@ class SettingsForm extends DirectorForm return $this; } + protected function enumGlobalZones() + { + $db = $this->settings->getDb(); + $zones = $db->fetchCol( + $db->select()->from('icinga_zone', 'object_name') + ->where('disabled = ?', 'n') + ->where('is_global = ?', 'y') + ->order('object_name') + ); + + return array_combine($zones, $zones); + } + public function onSuccess() { try { diff --git a/library/Director/Settings.php b/library/Director/Settings.php index c061735b..3a86bc0a 100644 --- a/library/Director/Settings.php +++ b/library/Director/Settings.php @@ -23,7 +23,7 @@ class Settings 'activation_script_v1' => null, 'self-service/agent_name' => 'fqdn', 'self-service/transform_hostname' => '0', - 'self-service/global_zones' => ['director_global'], + 'self-service/global_zones' => ['director-global'], // 'experimental_features' => null, // 'allow' // 'master_zone' => null, ]; @@ -39,6 +39,22 @@ class Settings $this->db = $connection->getDbAdapter(); } + /** + * @return Db + */ + public function getConnection() + { + return $this->connection; + } + + /** + * @return \Zend_Db_Adapter_Abstract + */ + public function getDb() + { + return $this->db; + } + public function get($key, $default = null) { if (null === ($value = $this->getStoredValue($key, $default))) {