-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62d7ca8
commit 20208a4
Showing
5 changed files
with
155 additions
and
3 deletions.
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,114 @@ | ||
<?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\WebModuleRequirement; | ||
|
||
class ModuleDependencyWizard | ||
{ | ||
protected $module; | ||
|
||
protected $checkedModules; | ||
|
||
public function __construct(Module $module, array $checkedModules) | ||
{ | ||
$this->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; | ||
} | ||
} |
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 enabled.'), | ||
$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