diff --git a/modules/setup/application/forms/ModulePage.php b/modules/setup/application/forms/ModulePage.php index d62b5a93ea7..b068930fa5b 100644 --- a/modules/setup/application/forms/ModulePage.php +++ b/modules/setup/application/forms/ModulePage.php @@ -5,6 +5,7 @@ use Icinga\Application\Icinga; use Icinga\Application\Modules\Module; +use Icinga\Module\Setup\ModuleDependencyWizard; use Icinga\Web\Form; class ModulePage extends Form @@ -100,6 +101,8 @@ public function getModuleWizards() foreach ($checked as $name => $module) { if ($module->providesSetupWizard()) { $wizards[$name] = $module->getSetupWizard(); + } elseif (! empty($module->getRequiredModules())) { + $wizards[$name] = new ModuleDependencyWizard($module, array_keys($checked)); } } diff --git a/modules/setup/library/Setup/ModuleDependencyWizard.php b/modules/setup/library/Setup/ModuleDependencyWizard.php new file mode 100644 index 00000000000..a7fdb6c6b63 --- /dev/null +++ b/modules/setup/library/Setup/ModuleDependencyWizard.php @@ -0,0 +1,114 @@ +module = $module; + $this->checkedModules = $checkedModules; + } + + public function getRequirements() + { + $icingadbAndMonitoring = []; + $set = new RequirementSet(); + + foreach ($this->module->getRequiredModules() as $name => $requiredVersion) { + if ($name === 'monitoring' || $name === 'icingadb') { + $icingadbAndMonitoring[$name] = $requiredVersion; + + continue; + } + + if (! in_array($name, $this->checkedModules)) { + $set->add( + (new ModuleMissingRequirement( + [ + 'title' => $name, + 'alias' => $name, + 'description' => sprintf( + t('Module %s (%s) is required.'), + $name, + $requiredVersion + ) + ] + )) + ); + } else { + $set->add( + (new WebModuleRequirement( + [ + 'title' => $name, + 'alias' => $name, + 'condition' => [$name, $requiredVersion], + 'description' => sprintf( + t('Module %s (%s) is required.'), + $name, + $requiredVersion + ) + ] + )) + ); + } + } + + if (! empty($icingadbAndMonitoring)) { + $icingadbOrmonitoring = new RequirementSet(false, RequirementSet::MODE_OR); + foreach ($icingadbAndMonitoring as $name => $requiredVersion) { + if (! in_array($name, $this->checkedModules)) { + $icingadbOrmonitoring->add( + (new ModuleMissingRequirement( + [ + 'title' => $name, + 'alias' => $name, + 'optional' => true, + 'description' => sprintf( + t('Module %s (%s) is required.'), + $name, + $requiredVersion + ) + ] + )) + ); + } else { + $icingadbOrmonitoring->add(new WebModuleRequirement([ + 'title' => $name, + 'alias' => $name, + 'optional' => true, + 'condition' => [$name, $requiredVersion], + 'description' => sprintf( + t('Module %s (%s) is required.'), + $name, + $requiredVersion + ) + ])); + } + } + + $set->merge($icingadbOrmonitoring); + + $requirement = (new SetRequirement([ + 'title' =>'Base Module', + 'alias' => 'Monitoring OR Icingadb', + 'optional' => false, + 'condition' => $icingadbOrmonitoring, + 'description' => t('Module Monitoring OR Icingadb is required.') + ])); + + $set->add($requirement); + } + + return $set; + } +} \ No newline at end of file diff --git a/modules/setup/library/Setup/Requirement/ModuleMissingRequirement.php b/modules/setup/library/Setup/Requirement/ModuleMissingRequirement.php new file mode 100644 index 00000000000..a2f4ae02d8f --- /dev/null +++ b/modules/setup/library/Setup/Requirement/ModuleMissingRequirement.php @@ -0,0 +1,23 @@ +setStateText(sprintf( + mt('setup', 'Module %s is not enabled.'), + $this->getAlias() + )); + + return false; + } + + public function equals(Requirement $requirement) + { + return false; + } +} diff --git a/modules/setup/library/Setup/Requirement/WebModuleRequirement.php b/modules/setup/library/Setup/Requirement/WebModuleRequirement.php index ad600e1dfd6..a2b639d5021 100644 --- a/modules/setup/library/Setup/Requirement/WebModuleRequirement.php +++ b/modules/setup/library/Setup/Requirement/WebModuleRequirement.php @@ -10,7 +10,17 @@ class WebModuleRequirement extends Requirement { protected function evaluate() { - list($name, $op, $version) = $this->getCondition(); + if (count($this->getCondition()) === 2) { + list($name, $version) = $this->getCondition(); + $op = '='; + if (is_string($version) + && preg_match('/^([<>=]{1,2})\s*v?((?:[\d.]+)(?:.+)?)$/', $version, $match)) { + $op = $match[1]; + $version = $match[2]; + } + } else { + list($name, $op, $version) = $this->getCondition(); + } $mm = Icinga::app()->getModuleManager(); if (! $mm->hasInstalled($name)) { @@ -26,6 +36,6 @@ protected function evaluate() } $this->setStateText(sprintf(mt('setup', '%s version: %s'), $this->getAlias(), $moduleVersion)); - return version_compare($moduleVersion, $version, $op); + return ($version === true || $version === null) ? true : version_compare($moduleVersion, $version, $op); } } diff --git a/modules/setup/library/Setup/WebWizard.php b/modules/setup/library/Setup/WebWizard.php index bb2cbb90b1a..0eb2b3a446f 100644 --- a/modules/setup/library/Setup/WebWizard.php +++ b/modules/setup/library/Setup/WebWizard.php @@ -119,7 +119,9 @@ protected function init() if (($modulePageData = $this->getPageData('setup_modules')) !== null) { $modulePage = $this->getPage('setup_modules')->populate($modulePageData); foreach ($modulePage->getModuleWizards() as $moduleWizard) { - $this->addPage($moduleWizard); + if (! $moduleWizard instanceof ModuleDependencyWizard) { + $this->addPage($moduleWizard); + } } } }