Enable modules as part of the main installation routine

refs #8191
This commit is contained in:
Johannes Meyer 2015-01-21 15:03:34 +01:00
parent 817e4e937c
commit 96390d34bf
3 changed files with 36 additions and 30 deletions

View File

@ -4,15 +4,12 @@
namespace Icinga\Module\Monitoring;
use Icinga\Application\Icinga;
use Icinga\Web\Form;
use Icinga\Web\Wizard;
use Icinga\Web\Request;
use Icinga\Module\Setup\Setup;
use Icinga\Module\Setup\SetupWizard;
use Icinga\Module\Setup\Requirements;
use Icinga\Module\Setup\Utils\MakeDirStep;
use Icinga\Module\Setup\Utils\EnableModuleStep;
use Icinga\Module\Setup\Forms\SummaryPage;
use Icinga\Module\Monitoring\Forms\Setup\WelcomePage;
use Icinga\Module\Monitoring\Forms\Setup\BackendPage;
@ -109,8 +106,6 @@ class MonitoringWizard extends Wizard implements SetupWizard
$pageData = $this->getPageData();
$setup = new Setup();
$setup->addStep(new MakeDirStep(array(Icinga::app()->getConfigDir() . '/modules/monitoring'), 2770));
$setup->addStep(
new BackendStep(array(
'backendConfig' => $pageData['setup_monitoring_backend'],
@ -132,8 +127,6 @@ class MonitoringWizard extends Wizard implements SetupWizard
))
);
$setup->addStep(new EnableModuleStep('monitoring'));
return $setup;
}

View File

@ -12,13 +12,13 @@ class EnableModuleStep extends Step
{
protected $modulePaths;
protected $moduleName;
protected $moduleNames;
protected $error;
protected $errors;
public function __construct($moduleName)
public function __construct(array $moduleNames)
{
$this->moduleName = $moduleName;
$this->moduleNames = $moduleNames;
$this->modulePaths = array();
if (($appModulePath = realpath(Icinga::app()->getApplicationDir() . '/../modules')) !== false) {
@ -28,17 +28,20 @@ class EnableModuleStep extends Step
public function apply()
{
try {
$moduleManager = Icinga::app()->getModuleManager();
$moduleManager->detectInstalledModules($this->modulePaths);
$moduleManager->enableModule($this->moduleName);
} catch (Exception $e) {
$this->error = $e;
return false;
$moduleManager = Icinga::app()->getModuleManager();
$moduleManager->detectInstalledModules($this->modulePaths);
$success = true;
foreach ($this->moduleNames as $moduleName) {
try {
$moduleManager->enableModule($moduleName);
} catch (Exception $e) {
$this->errors[$moduleName] = $e;
$success = false;
}
}
$this->error = false;
return true;
return $success;
}
public function getSummary()
@ -48,12 +51,19 @@ class EnableModuleStep extends Step
public function getReport()
{
if ($this->error === false) {
return '<p>' . sprintf(mt('setup', 'Module "%s" has been successfully enabled.'), $this->moduleName) . '</p>';
} elseif ($this->error !== null) {
$message = mt('setup', 'Module "%s" could not be enabled. An error occured:');
return '<p class="error">' . sprintf($message, $this->moduleName) . '</p>'
. '<p>' . $this->error->getMessage() . '</p>';
$okMessage = mt('setup', 'Module "%s" has been successfully enabled.');
$failMessage = mt('setup', 'Module "%s" could not be enabled. An error occured:');
$report = '';
foreach ($this->moduleNames as $moduleName) {
if (isset($this->errors[$moduleName])) {
$report .= '<p class="error">' . sprintf($failMessage, $moduleName) . '</p>'
. '<p>' . $this->errors[$moduleName]->getMessage() . '</p>';
} else {
$report .= '<p>' . sprintf($okMessage, $moduleName) . '</p>';
}
}
return $report;
}
}

View File

@ -29,6 +29,7 @@ use Icinga\Module\Setup\Steps\DatabaseStep;
use Icinga\Module\Setup\Steps\GeneralConfigStep;
use Icinga\Module\Setup\Steps\ResourceStep;
use Icinga\Module\Setup\Steps\AuthenticationStep;
use Icinga\Module\Setup\Utils\EnableModuleStep;
use Icinga\Module\Setup\Utils\MakeDirStep;
use Icinga\Module\Setup\Utils\DbTool;
@ -284,7 +285,7 @@ class WebWizard extends Wizard implements SetupWizard
? $pageData['setup_database_creation']['password']
: null,
'schemaPath' => Config::module('setup')
->get('schema', 'path', Icinga::app()->getBaseDir('etc/schema'))
->get('schema', 'path', Icinga::app()->getBaseDir('etc' . DIRECTORY_SEPARATOR . 'schema'))
))
);
}
@ -337,9 +338,9 @@ class WebWizard extends Wizard implements SetupWizard
$setup->addStep(
new MakeDirStep(
array(
$configDir . '/modules',
$configDir . '/preferences',
$configDir . '/enabledModules'
$configDir . DIRECTORY_SEPARATOR . 'modules',
$configDir . DIRECTORY_SEPARATOR . 'preferences',
$configDir . DIRECTORY_SEPARATOR . 'enabledModules'
),
2770
)
@ -351,6 +352,8 @@ class WebWizard extends Wizard implements SetupWizard
}
}
$setup->addStep(new EnableModuleStep(array_keys($this->getPage('setup_modules')->getCheckedModules())));
return $setup;
}