Skip to content

Commit

Permalink
Add module lib dependencies on reqirement page
Browse files Browse the repository at this point in the history
* Enhance class WebLibraryRequirement
  • Loading branch information
sukhwinder33445 committed Sep 6, 2022
1 parent 5ef89e5 commit 136ebab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/setup/application/forms/ModulePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
9 changes: 9 additions & 0 deletions modules/setup/library/Setup/ModuleDependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
}
}

0 comments on commit 136ebab

Please sign in to comment.