mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-22 13:24:24 +02:00
ModuleManager: Throw module dir exceptions later
This is important for bootstrap to detect configuration errors. refs #4604
This commit is contained in:
parent
b6eb19ce6a
commit
b99b9a7ca8
@ -343,7 +343,14 @@ abstract class ApplicationBootstrap
|
|||||||
{
|
{
|
||||||
$this->moduleManager = new ModuleManager($this, $this->configDir . '/enabledModules');
|
$this->moduleManager = new ModuleManager($this, $this->configDir . '/enabledModules');
|
||||||
|
|
||||||
$this->moduleManager->loadEnabledModules();
|
try {
|
||||||
|
$this->moduleManager->loadEnabledModules();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Logger::fatal(
|
||||||
|
'Could not load modules. An exception was thrown during bootstrap: %s',
|
||||||
|
$e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -108,28 +108,8 @@ class Manager
|
|||||||
if ($enabledDir === null) {
|
if ($enabledDir === null) {
|
||||||
$enabledDir = $this->app->getConfigDir() . '/enabledModules';
|
$enabledDir = $this->app->getConfigDir() . '/enabledModules';
|
||||||
}
|
}
|
||||||
$this->prepareEssentials($enabledDir);
|
|
||||||
$this->detectEnabledModules();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->enableDir = $enabledDir;
|
||||||
* Set the module dir and checks for existence
|
|
||||||
*
|
|
||||||
* @param string $moduleDir The module directory to set for the module manager
|
|
||||||
* @throws ProgrammingError
|
|
||||||
*/
|
|
||||||
private function prepareEssentials($moduleDir)
|
|
||||||
{
|
|
||||||
$this->enableDir = $moduleDir;
|
|
||||||
|
|
||||||
if (!file_exists($this->enableDir) || !is_dir($this->enableDir)) {
|
|
||||||
throw new ProgrammingError(
|
|
||||||
sprintf(
|
|
||||||
'Missing module directory: %s',
|
|
||||||
$this->enableDir
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,10 +124,26 @@ class Manager
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for enabled modules and update the internal $enabledDirs property with the enabled modules
|
* Check for enabled modules
|
||||||
|
*
|
||||||
|
* Update the internal $enabledDirs property with the enabled modules.
|
||||||
|
*
|
||||||
|
* @throws ConfigurationError If module dir is not a directory or not readable
|
||||||
*/
|
*/
|
||||||
private function detectEnabledModules()
|
private function detectEnabledModules()
|
||||||
{
|
{
|
||||||
|
if (!is_dir($this->enableDir)) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
'Could not read enabled modules: Module directory is not a directory: ' . $this->enableDir
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_readable($this->enableDir)) {
|
||||||
|
throw new ConfigurationError(
|
||||||
|
'Could not read enabled modules: Module directory is not readable: ' . $this->enableDir
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$fh = opendir($this->enableDir);
|
$fh = opendir($this->enableDir);
|
||||||
|
|
||||||
$this->enabledDirs = array();
|
$this->enabledDirs = array();
|
||||||
@ -452,6 +448,10 @@ class Manager
|
|||||||
*/
|
*/
|
||||||
public function listEnabledModules()
|
public function listEnabledModules()
|
||||||
{
|
{
|
||||||
|
if (count($this->enabledDirs) === 0) {
|
||||||
|
$this->detectEnabledModules();
|
||||||
|
}
|
||||||
|
|
||||||
return array_keys($this->enabledDirs);
|
return array_keys($this->enabledDirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user