-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup wizard: Show module dependencies on requirements page #4864
Open
sukhwinder33445
wants to merge
5
commits into
main
Choose a base branch
from
show-module-dependencies-on-requirments-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b91a4af
Introduce class `ModuleMissingRequirement`
sukhwinder33445 ca3bfdd
WebModuleRequirement: Enhance class
sukhwinder33445 e390a61
Introduce class `ModuleDependency`
sukhwinder33445 5ef89e5
Add module dependencies to requirements page
sukhwinder33445 136ebab
Add module lib dependencies on reqirement page
sukhwinder33445 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Setup; | ||
|
||
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 | ||
{ | ||
/** @var Module The given Module */ | ||
protected $module; | ||
|
||
/** @var array The chosen modules */ | ||
protected $checkedModules; | ||
|
||
/** | ||
* @param Module $module The given module | ||
* | ||
* @param array $checkedModules The checked modules from module page | ||
*/ | ||
public function __construct(Module $module, array $checkedModules) | ||
sukhwinder33445 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->module = $module; | ||
$this->checkedModules = $checkedModules; | ||
} | ||
|
||
/** | ||
* Get the module dependency requirements | ||
* | ||
* @return RequirementSet | ||
*/ | ||
public function getRequirements() | ||
{ | ||
$icingadbAndMonitoring = []; | ||
$set = new RequirementSet(); | ||
|
||
foreach ($this->module->getRequiredModules() as $name => $requiredVersion) { | ||
if ($name === 'monitoring' || $name === 'icingadb') { | ||
$icingadbAndMonitoring[$name] = $requiredVersion; | ||
|
||
continue; | ||
} | ||
|
||
$options = [ | ||
'alias' => $name, | ||
'description' => sprintf( | ||
t('Module %s (%s) is required.'), | ||
$name, | ||
$requiredVersion | ||
) | ||
]; | ||
|
||
if (! in_array($name, $this->checkedModules)) { | ||
$set->add(new ModuleMissingRequirement($options)); | ||
} else { | ||
$options['condition'] = [$name, $requiredVersion]; | ||
$set->add(new WebModuleRequirement($options)); | ||
} | ||
} | ||
|
||
if (! empty($icingadbAndMonitoring)) { | ||
$icingadbOrMonitoring = new RequirementSet(false, RequirementSet::MODE_OR); | ||
foreach ($icingadbAndMonitoring as $name => $requiredVersion) { | ||
$options = [ | ||
'alias' => $name, | ||
'optional' => true, | ||
'description' => sprintf( | ||
t('Module %s (%s) is required.'), | ||
$name, | ||
$requiredVersion | ||
) | ||
]; | ||
|
||
if (! in_array($name, $this->checkedModules)) { | ||
$icingadbOrMonitoring->add(new ModuleMissingRequirement($options)); | ||
} else { | ||
$options['condition'] = [$name, $requiredVersion]; | ||
$icingadbOrMonitoring->add(new WebModuleRequirement($options)); | ||
} | ||
} | ||
|
||
$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); | ||
} | ||
|
||
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; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
modules/setup/library/Setup/Requirement/ModuleMissingRequirement.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Setup\Requirement; | ||
|
||
use Icinga\Module\Setup\Requirement; | ||
|
||
class ModuleMissingRequirement extends Requirement | ||
{ | ||
protected function evaluate() | ||
{ | ||
$this->setStateText(sprintf( | ||
mt('setup', 'Module %s is not chosen.'), | ||
$this->getAlias() | ||
)); | ||
|
||
return false; | ||
} | ||
|
||
public function equals(Requirement $requirement) | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work? It's not a page nor a wizard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setup-requirements.phtml
(line 12) gets the wizard and callsgetRequirements()
.The class
ModuleDependency
contains only this method, i.e. if noSetupWizard
is provided for the current module (e.g. Cube), this class returns module and lib dependencies.