Handle enabled, but deleted modules properly

refs #2811
This commit is contained in:
Alexander A. Klimov 2017-11-07 12:51:31 +01:00 committed by Eric Lippmann
parent 3fc410b8c1
commit cbfbb3a162
4 changed files with 32 additions and 27 deletions

View File

@ -78,7 +78,9 @@ class ModuleCommand extends Command
"%-14s %-9s %-9s %s\n",
$module,
$mod->getVersion(),
($type === 'enabled' || $this->modules->hasEnabled($module)) ? 'enabled' : 'disabled',
($type === 'enabled' || $this->modules->hasEnabled($module))
? $this->modules->hasInstalled($module) ? 'enabled' : 'dangling'
: 'disabled',
$dir
);
}

View File

@ -102,6 +102,7 @@ class ConfigController extends Controller
$this->view->modules = Icinga::app()->getModuleManager()->select()
->from('modules')
->order('enabled', 'desc')
->order('installed', 'asc')
->order('name');
$this->setupLimitControl();
$this->setupPaginationControl($this->view->modules);
@ -113,7 +114,7 @@ class ConfigController extends Controller
$app = Icinga::app();
$manager = $app->getModuleManager();
$name = $this->getParam('name');
if ($manager->hasInstalled($name)) {
if ($manager->hasInstalled($name) || $manager->hasEnabled($name)) {
$this->view->moduleData = $manager->select()->from('modules')->where('name', $name)->fetchRow();
if ($manager->hasLoaded($name)) {
$module = $manager->getModule($name);

View File

@ -15,7 +15,9 @@
<?php foreach ($modules as $module): ?>
<tr>
<td>
<?php if ($module->enabled && $module->loaded) {
<?php if (! $module->installed) {
$this->icon('flash', sprintf($this->translate('Module %s is dangling'), $module->name));
} elseif ($module->enabled && $module->loaded) {
echo $this->icon('thumbs-up', sprintf($this->translate('Module %s is enabled'), $module->name));
} elseif (! $module->enabled) {
echo $this->icon('block', sprintf($this->translate('Module %s is disabled'), $module->name));

View File

@ -158,17 +158,19 @@ class Manager
}
$dir = realpath($link);
if (! file_exists($dir) || !is_dir($dir)) {
if ($dir !== false && is_dir($dir)) {
$this->enabledDirs[$file] = $dir;
} else {
$this->enabledDirs[$file] = null;
Logger::warning(
'Found invalid module in enabledModule directory "%s": "%s" points to non existing path "%s"',
$this->enableDir,
$link,
$dir
);
continue;
}
$this->enabledDirs[$file] = $dir;
ksort($this->enabledDirs);
}
closedir($dh);
@ -329,12 +331,6 @@ class Manager
}
$link = $this->enableDir . DIRECTORY_SEPARATOR . $name;
if (! file_exists($link)) {
throw new ConfigurationError(
'Cannot disable module "%s". Module is not installed.',
$name
);
}
if (! is_link($link)) {
throw new ConfigurationError(
'Cannot disable module %s at %s. '
@ -346,7 +342,7 @@ class Manager
);
}
if (file_exists($link) && is_link($link)) {
if (is_link($link)) {
if (! @unlink($link)) {
$error = error_get_last();
throw new SystemPermissionException(
@ -471,6 +467,7 @@ class Manager
* Each entry has the following fields
* * name, name of the module as a string
* * path, path where the module is located as a string
* * installed, whether the module is installed or not as a boolean
* * enabled, whether the module is enabled or not as a boolean
* * loaded, whether the module is loaded or not as a boolean
*
@ -480,25 +477,28 @@ class Manager
{
$info = array();
$enabled = $this->listEnabledModules();
foreach ($enabled as $name) {
$info[$name] = (object) array(
'name' => $name,
'path' => $this->enabledDirs[$name],
'enabled' => true,
'loaded' => $this->hasLoaded($name)
);
}
$installed = $this->listInstalledModules();
foreach ($installed as $name) {
$info[$name] = (object) array(
'name' => $name,
'path' => $this->installedBaseDirs[$name],
'installed' => true,
'enabled' => $this->hasEnabled($name),
'loaded' => $this->hasLoaded($name)
);
}
$enabled = $this->listEnabledModules();
foreach ($enabled as $name) {
$info[$name] = (object) array(
'name' => $name,
'path' => $this->enabledDirs[$name],
'installed' => $this->enabledDirs[$name] !== null,
'enabled' => true,
'loaded' => $this->hasLoaded($name)
);
}
return $info;
}