From 136ebab79ec72e640fc79726ccdf305cbe5c07f0 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Tue, 6 Sep 2022 16:48:59 +0200 Subject: [PATCH] Add module lib dependencies on reqirement page * Enhance class WebLibraryRequirement --- modules/setup/application/forms/ModulePage.php | 2 +- modules/setup/library/Setup/ModuleDependency.php | 9 +++++++++ .../Setup/Requirement/WebLibraryRequirement.php | 12 +++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/setup/application/forms/ModulePage.php b/modules/setup/application/forms/ModulePage.php index 01f2cd9df0..55620fa12e 100644 --- a/modules/setup/application/forms/ModulePage.php +++ b/modules/setup/application/forms/ModulePage.php @@ -101,7 +101,7 @@ public function getModuleWizards() foreach ($checked as $name => $module) { if ($module->providesSetupWizard()) { $wizards[$name] = $module->getSetupWizard(); - } elseif (! empty($module->getRequiredModules())) { + } elseif (! empty($module->getRequiredModules()) || ! empty($module->getRequiredLibraries())) { $wizards[$name] = new ModuleDependency($module, array_keys($checked)); } } diff --git a/modules/setup/library/Setup/ModuleDependency.php b/modules/setup/library/Setup/ModuleDependency.php index 0810a1cc00..09d5fea5bd 100644 --- a/modules/setup/library/Setup/ModuleDependency.php +++ b/modules/setup/library/Setup/ModuleDependency.php @@ -5,6 +5,7 @@ use Icinga\Application\Modules\Module; use Icinga\Module\Setup\Requirement\ModuleMissingRequirement; use Icinga\Module\Setup\Requirement\SetRequirement; +use Icinga\Module\Setup\Requirement\WebLibraryRequirement; use Icinga\Module\Setup\Requirement\WebModuleRequirement; class ModuleDependency @@ -94,6 +95,14 @@ public function getRequirements() $set->add($requirement); } + foreach ($this->module->getRequiredLibraries() as $name => $requiredVersion) { + $set->add(new WebLibraryRequirement([ + 'condition' => [$name, $requiredVersion], + 'alias' => $name, + 'description' => sprintf(t('The %s library (%s) is required'), $name, $requiredVersion) + ])); + } + return $set; } } diff --git a/modules/setup/library/Setup/Requirement/WebLibraryRequirement.php b/modules/setup/library/Setup/Requirement/WebLibraryRequirement.php index bab587aac0..5160deaed9 100644 --- a/modules/setup/library/Setup/Requirement/WebLibraryRequirement.php +++ b/modules/setup/library/Setup/Requirement/WebLibraryRequirement.php @@ -10,7 +10,12 @@ class WebLibraryRequirement extends Requirement { protected function evaluate() { - list($name, $op, $version) = $this->getCondition(); + if (count($this->getCondition()) === 2) { + list($name, $version) = $this->getCondition(); + $op = ''; + } else { + list($name, $op, $version) = $this->getCondition(); + } $libs = Icinga::app()->getLibraries(); if (! $libs->has($name)) { @@ -19,6 +24,11 @@ protected function evaluate() } $this->setStateText(sprintf(mt('setup', '%s version: %s'), $this->getAlias(), $libs->get($name)->getVersion())); + + if (! is_string($version)) { // null, bool + return $libs->has($name, $version); + } + return $libs->has($name, $op . $version); } }