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", "%-14s %-9s %-9s %s\n",
$module, $module,
$mod->getVersion(), $mod->getVersion(),
($type === 'enabled' || $this->modules->hasEnabled($module)) ? 'enabled' : 'disabled', ($type === 'enabled' || $this->modules->hasEnabled($module))
? $this->modules->hasInstalled($module) ? 'enabled' : 'dangling'
: 'disabled',
$dir $dir
); );
} }

View File

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

View File

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

View File

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