ModulePage: Select icingadb by default if installed

This commit is contained in:
Johannes Meyer 2020-04-20 11:16:38 +02:00
parent a087089025
commit a6bacd0dc3
1 changed files with 18 additions and 1 deletions

View File

@ -4,6 +4,7 @@
namespace Icinga\Module\Setup\Forms; namespace Icinga\Module\Setup\Forms;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Web\Form; use Icinga\Web\Form;
class ModulePage extends Form class ModulePage extends Form
@ -12,6 +13,8 @@ class ModulePage extends Form
protected $modulePaths; protected $modulePaths;
protected $foundIcingaDB = false;
/** /**
* Initialize this page * Initialize this page
*/ */
@ -29,19 +32,29 @@ class ModulePage extends Form
public function createElements(array $formData) public function createElements(array $formData)
{ {
foreach ($this->getModules() as $module) { foreach ($this->getModules() as $module) {
$checked = false;
if ($module->getName() === 'monitoring') {
$checked = ! $this->foundIcingaDB;
} elseif ($this->foundIcingaDB && $module->getName() === 'icingadb') {
$checked = true;
}
$this->addElement( $this->addElement(
'checkbox', 'checkbox',
$module->getName(), $module->getName(),
array( array(
'description' => $module->getDescription(), 'description' => $module->getDescription(),
'label' => ucfirst($module->getName()), 'label' => ucfirst($module->getName()),
'value' => $module->getName() === 'monitoring' ? 1 : 0, 'value' => (int) $checked,
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper')
) )
); );
} }
} }
/**
* @return Module[]
*/
protected function getModules() protected function getModules()
{ {
if ($this->modules !== null) { if ($this->modules !== null) {
@ -56,6 +69,10 @@ class ModulePage extends Form
if ($moduleName !== 'setup') { if ($moduleName !== 'setup') {
$this->modules[$moduleName] = $moduleManager->loadModule($moduleName)->getModule($moduleName); $this->modules[$moduleName] = $moduleManager->loadModule($moduleName)->getModule($moduleName);
} }
if ($moduleName === 'icingadb') {
$this->foundIcingaDB = true;
}
} }
return $this->modules; return $this->modules;