/
EnableModuleStep.php
54 lines (44 loc) · 1.43 KB
/
EnableModuleStep.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Setup;
use Exception;
use Icinga\Application\Icinga;
class EnableModuleStep extends Step
{
protected $availableDirs;
protected $moduleName;
protected $error;
public function __construct($availableDirs, $moduleName)
{
$this->availableDirs = $availableDirs;
$this->moduleName = $moduleName;
}
public function apply()
{
try {
$moduleManager = Icinga::app()->getModuleManager();
$moduleManager->detectInstalledModules($this->availableDirs);
$moduleManager->enableModule($this->moduleName);
} catch (Exception $e) {
$this->error = $e;
return false;
}
$this->error = false;
return true;
}
public function getSummary()
{
// Enabling a module is like a implicit action, which does not need to be shown to the user...
}
public function getReport()
{
if ($this->error === false) {
return '<p>' . sprintf(t('Module "%s" has been successfully enabled.'), $this->moduleName) . '</p>';
} elseif ($this->error !== null) {
$message = t('Module "%s" could not be enabled. An error occured:');
return '<p class="error">' . sprintf($message, $this->moduleName) . '</p>'
. '<p>' . $this->error->getMessage() . '</p>';
}
}
}