Skip to content

Commit

Permalink
Add support for "core" modules and make the setup module such a module
Browse files Browse the repository at this point in the history
refs #7163
  • Loading branch information
Johannes Meyer committed Nov 10, 2014
1 parent 6b2f434 commit 8af13f5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
15 changes: 15 additions & 0 deletions library/Icinga/Application/ApplicationBootstrap.php
Expand Up @@ -324,6 +324,21 @@ protected function setupModuleManager()
return $this;
}

/**
* Load all core modules
*
* @return self
*/
protected function loadCoreModules()
{
try {
$this->moduleManager->loadCoreModules();
} catch (NotReadableError $e) {
Logger::error(new IcingaException('Cannot load core modules. An exception was thrown:', $e));
}
return $this;
}

/**
* Load all enabled modules
*
Expand Down
1 change: 1 addition & 0 deletions library/Icinga/Application/EmbeddedWeb.php
Expand Up @@ -31,6 +31,7 @@ protected function bootstrap()
->setupErrorHandling()
->setupTimezone()
->setupModuleManager()
->loadCoreModules()
->loadEnabledModules();
}
}
32 changes: 30 additions & 2 deletions library/Icinga/Application/Modules/Manager.php
Expand Up @@ -67,6 +67,18 @@ class Manager
*/
private $modulePaths = array();

/**
* The core modules
*
* Core modules do not need to be enabled to load and cannot be disabled
* by the user. This must not be writable programmatically!
*
* @var array
*/
private $coreModules = array(
'setup'
);

/**
* Create a new instance of the module manager
*
Expand Down Expand Up @@ -157,7 +169,21 @@ private function detectEnabledModules()
}

/**
* Try to set all enabled modules in loaded sate
* Try to set all core modules in loaded state
*
* @return self
* @see Manager::loadModule()
*/
public function loadCoreModules()
{
foreach ($this->coreModules as $name) {
$this->loadModule($name);
}
return $this;
}

/**
* Try to set all enabled modules in loaded state
*
* @return self
* @see Manager::loadModule()
Expand Down Expand Up @@ -211,6 +237,8 @@ public function enableModule($name)
'Cannot enable module "%s". Module is not installed.',
$name
);
} elseif (in_array($name, $this->coreModules)) {
return $this;
}

clearstatcache(true);
Expand Down Expand Up @@ -427,7 +455,7 @@ public function getModuleInfo()
}

$installed = $this->listInstalledModules();
foreach ($installed as $name) {
foreach (array_diff($installed, $this->coreModules) as $name) {
$info[$name] = (object) array(
'name' => $name,
'path' => $this->installedBaseDirs[$name],
Expand Down
1 change: 1 addition & 0 deletions library/Icinga/Application/Web.php
Expand Up @@ -92,6 +92,7 @@ protected function bootstrap()
->setupZendMvc()
->setupFormNamespace()
->setupModuleManager()
->loadCoreModules()
->loadEnabledModules()
->setupRoute()
->setupPagination();
Expand Down
Expand Up @@ -101,7 +101,7 @@ class GettextTranslationHelper
*/
public function __construct(ApplicationBootstrap $bootstrap, $locale)
{
$this->moduleMgr = $bootstrap->getModuleManager()->loadEnabledModules();
$this->moduleMgr = $bootstrap->getModuleManager()->loadCoreModules()->loadEnabledModules();
$this->appDir = $bootstrap->getApplicationDir();
$this->locale = $locale;
}
Expand Down

0 comments on commit 8af13f5

Please sign in to comment.