2014-10-28 15:13:06 +01:00
|
|
|
<?php
|
2015-02-03 16:27:59 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | http://www.gnu.org/licenses/gpl-2.0.txt */
|
2014-10-28 15:13:06 +01:00
|
|
|
|
2014-11-10 16:31:40 +01:00
|
|
|
namespace Icinga\Module\Setup\Utils;
|
2014-10-28 15:13:06 +01:00
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use Icinga\Application\Icinga;
|
2014-11-10 16:31:40 +01:00
|
|
|
use Icinga\Module\Setup\Step;
|
2014-10-28 15:13:06 +01:00
|
|
|
|
|
|
|
class EnableModuleStep extends Step
|
|
|
|
{
|
2014-10-29 15:43:08 +01:00
|
|
|
protected $modulePaths;
|
2014-10-28 15:13:06 +01:00
|
|
|
|
2015-01-21 15:03:34 +01:00
|
|
|
protected $moduleNames;
|
2014-10-28 15:13:06 +01:00
|
|
|
|
2015-01-21 15:03:34 +01:00
|
|
|
protected $errors;
|
2014-10-28 15:13:06 +01:00
|
|
|
|
2015-01-21 15:03:34 +01:00
|
|
|
public function __construct(array $moduleNames)
|
2014-10-28 15:13:06 +01:00
|
|
|
{
|
2015-01-21 15:03:34 +01:00
|
|
|
$this->moduleNames = $moduleNames;
|
2014-10-29 15:43:08 +01:00
|
|
|
|
|
|
|
$this->modulePaths = array();
|
|
|
|
if (($appModulePath = realpath(Icinga::app()->getApplicationDir() . '/../modules')) !== false) {
|
|
|
|
$this->modulePaths[] = $appModulePath;
|
|
|
|
}
|
2014-10-28 15:13:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function apply()
|
|
|
|
{
|
2015-01-21 15:03:34 +01:00
|
|
|
$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;
|
|
|
|
}
|
2014-10-28 15:13:06 +01:00
|
|
|
}
|
|
|
|
|
2015-01-21 15:03:34 +01:00
|
|
|
return $success;
|
2014-10-28 15:13:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSummary()
|
|
|
|
{
|
|
|
|
// Enabling a module is like a implicit action, which does not need to be shown to the user...
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReport()
|
|
|
|
{
|
2015-01-21 15:03:34 +01:00
|
|
|
$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>';
|
|
|
|
}
|
2014-10-28 15:13:06 +01:00
|
|
|
}
|
2015-01-21 15:03:34 +01:00
|
|
|
|
|
|
|
return $report;
|
2014-10-28 15:13:06 +01:00
|
|
|
}
|
|
|
|
}
|