Move ModuleController from incubator
The Notification dependency is removed and uses exceptions now, otherwise it's mostly the same like in the incubator refs #4092
This commit is contained in:
parent
beaac3a68d
commit
8b84de934a
|
@ -35,11 +35,7 @@ class ModulesController extends ActionController
|
||||||
public function enableAction()
|
public function enableAction()
|
||||||
{
|
{
|
||||||
$this->manager->enableModule($this->_getParam('name'));
|
$this->manager->enableModule($this->_getParam('name'));
|
||||||
$this->manager->loadModule($this->_getParam('name'));
|
$this->redirectNow('modules/overview?_render=body');
|
||||||
$this->getResponse()->setHeader('X-Icinga-Enable-Module', $this->_getParam('name'));
|
|
||||||
$this->replaceLayout = true;
|
|
||||||
$this->indexAction();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function disableAction()
|
public function disableAction()
|
||||||
|
|
|
@ -2,39 +2,33 @@
|
||||||
|
|
||||||
namespace Icinga\Application\Modules;
|
namespace Icinga\Application\Modules;
|
||||||
|
|
||||||
|
use Icinga\Application\ApplicationBootstrap;
|
||||||
|
use Icinga\Data\ArrayDatasource;
|
||||||
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\SystemPermissionException;
|
use Icinga\Exception\SystemPermissionException;
|
||||||
use Icinga\Exception\ProgrammingError;
|
|
||||||
|
|
||||||
// TODO: show whether enabling/disabling modules is allowed by checking enableDir
|
// TODO: show whether enabling/disabling modules is allowed by checking enableDir
|
||||||
// perms
|
// perms
|
||||||
|
|
||||||
class Manager
|
class Manager
|
||||||
{
|
{
|
||||||
protected $installedBaseDirs = null;
|
protected $installedBaseDirs;
|
||||||
protected $enabledDirs = array();
|
protected $enabledDirs = array();
|
||||||
protected $loadedModules = array();
|
protected $loadedModules = array();
|
||||||
protected $index;
|
protected $index;
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
protected $enableDir;
|
protected $enableDir;
|
||||||
protected $modulePaths = array();
|
|
||||||
/**
|
public function __construct(ApplicationBootstrap $app, $dir = null)
|
||||||
* @param $app : The applicaiton bootstrap. This one needs a properly defined interface
|
|
||||||
* In order to test it correctly, the application now only requires a stdClass
|
|
||||||
* @param $dir :
|
|
||||||
**/
|
|
||||||
public function __construct($app, $enabledDir = null, array $availableDirs = array())
|
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
if (empty($availableDirs)) {
|
if ($dir === null) {
|
||||||
$availableDirs = array(ICINGA_APPDIR."/../modules");
|
$dir = $this->app->getConfig()->getConfigDir()
|
||||||
}
|
|
||||||
$this->modulePaths = $availableDirs;
|
|
||||||
if ($enabledDir === null) {
|
|
||||||
$enabledDir = $this->app->getConfig()->getConfigDir()
|
|
||||||
. '/enabledModules';
|
. '/enabledModules';
|
||||||
}
|
}
|
||||||
$this->prepareEssentials($enabledDir);
|
$this->prepareEssentials($dir);
|
||||||
$this->detectEnabledModules();
|
$this->detectEnabledModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,17 +46,10 @@ class Manager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function select()
|
|
||||||
{
|
|
||||||
$source = new \Icinga\Data\ArrayDataSource($this->getModuleInfo());
|
|
||||||
return $source->select();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function detectEnabledModules()
|
protected function detectEnabledModules()
|
||||||
{
|
{
|
||||||
$fh = opendir($this->enableDir);
|
$fh = opendir($this->enableDir);
|
||||||
|
|
||||||
$this->enabledDirs = array();
|
|
||||||
while (false !== ($file = readdir($fh))) {
|
while (false !== ($file = readdir($fh))) {
|
||||||
|
|
||||||
if ($file[0] === '.') {
|
if ($file[0] === '.') {
|
||||||
|
@ -91,18 +78,12 @@ class Manager
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadModule($name, $moduleBase = null)
|
public function loadModule($name)
|
||||||
{
|
{
|
||||||
if ($this->hasLoaded($name)) {
|
if ($this->hasLoaded($name)) {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
$module = new Module($this->app, $name, $this->getModuleDir($name));
|
||||||
$module = null;
|
|
||||||
if ($moduleBase === null) {
|
|
||||||
$module = new Module($this->app, $name, $this->getModuleDir($name));
|
|
||||||
} else {
|
|
||||||
$module = new $moduleBase($this->app, $name, $this->getModuleDir($name));
|
|
||||||
}
|
|
||||||
$module->register();
|
$module->register();
|
||||||
$this->loadedModules[$name] = $module;
|
$this->loadedModules[$name] = $module;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -119,7 +100,6 @@ class Manager
|
||||||
);
|
);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
clearstatcache(true);
|
|
||||||
$target = $this->installedBaseDirs[$name];
|
$target = $this->installedBaseDirs[$name];
|
||||||
$link = $this->enableDir . '/' . $name;
|
$link = $this->enableDir . '/' . $name;
|
||||||
if (! is_writable($this->enableDir)) {
|
if (! is_writable($this->enableDir)) {
|
||||||
|
@ -138,7 +118,6 @@ class Manager
|
||||||
throw new SystemPermissionException($error["message"], "symlink", $link);
|
throw new SystemPermissionException($error["message"], "symlink", $link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->enabledDirs[$name] = $link;
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +151,6 @@ class Manager
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
unset($this->enabledDirs[$name]);
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,6 +228,12 @@ class Manager
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function select()
|
||||||
|
{
|
||||||
|
$ds = new ArrayDatasource($this->getModuleInfo());
|
||||||
|
return $ds->select();
|
||||||
|
}
|
||||||
|
|
||||||
public function listEnabledModules()
|
public function listEnabledModules()
|
||||||
{
|
{
|
||||||
return array_keys($this->enabledDirs);
|
return array_keys($this->enabledDirs);
|
||||||
|
@ -270,19 +254,19 @@ class Manager
|
||||||
|
|
||||||
public function detectInstalledModules()
|
public function detectInstalledModules()
|
||||||
{
|
{
|
||||||
foreach ($this->modulePaths as $basedir) {
|
// TODO: Allow multiple paths for installed modules (e.g. web vs pkg)
|
||||||
$fh = opendir($basedir);
|
$basedir = realpath(ICINGA_APPDIR . '/../modules');
|
||||||
if ($fh === false) {
|
$fh = @opendir($basedir);
|
||||||
return $this;
|
if ($fh === false) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($name = readdir($fh)) {
|
||||||
|
if ($name[0] === '.') {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
if (is_dir($basedir . '/' . $name)) {
|
||||||
while ($name = readdir($fh)) {
|
$this->installedBaseDirs[$name] = $basedir . '/' . $name;
|
||||||
if ($name[0] === '.') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (is_dir($basedir . '/' . $name)) {
|
|
||||||
$this->installedBaseDirs[$name] = $basedir . '/' . $name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
};
|
};
|
||||||
var getDOMForDestination = function(destination) {
|
var getDOMForDestination = function(destination) {
|
||||||
var target = destination;
|
var target = destination;
|
||||||
if(typeof destination === "string") {
|
if (typeof destination === "string") {
|
||||||
target = containerMgr.getContainer(destination)[0];
|
target = containerMgr.getContainer(destination)[0];
|
||||||
} else if(typeof destination.context !== "undefined") {
|
} else if(typeof destination.context !== "undefined") {
|
||||||
target = destination[0];
|
target = destination[0];
|
||||||
|
@ -89,7 +89,7 @@
|
||||||
if(destination) {
|
if(destination) {
|
||||||
pending.push({
|
pending.push({
|
||||||
request: req,
|
request: req,
|
||||||
DOM: getDOMForDestination(destination)
|
DOM: getDOMForDestination(destination)
|
||||||
});
|
});
|
||||||
req.destination = destination;
|
req.destination = destination;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue