Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #7163
- Loading branch information
Johannes Meyer
committed
Oct 29, 2014
1 parent
3c438d9
commit 83cfcef
Showing
1 changed file
with
54 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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>'; | ||
} | ||
} | ||
} |