From 5b87d6238bfc129d63ebf06c3bfdf4f1e934d8ee Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 26 May 2014 14:11:43 +0000 Subject: [PATCH] Modules\Module: improve provided metadata refs #4095 --- application/clicommands/ModuleCommand.php | 2 +- library/Icinga/Application/Modules/Module.php | 61 ++++++++++++++----- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/application/clicommands/ModuleCommand.php b/application/clicommands/ModuleCommand.php index 6a6f981ed..1fb0932fd 100644 --- a/application/clicommands/ModuleCommand.php +++ b/application/clicommands/ModuleCommand.php @@ -67,7 +67,7 @@ class ModuleCommand extends Command if ($this->isVerbose) { $dir = ' ' . $this->modules->getModuleDir($module); } else { - $dir = $mod->getShortDescription(); + $dir = $mod->getTitle(); } printf( "%-14s %-9s %-9s %s\n", diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index c765ca380..027bfc48b 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -292,13 +292,23 @@ class Module } /** - * Get short description + * Get module description * * @return string */ - public function getShortDescription() + public function getDescription() { - return $this->metadata()->shortDescription; + return $this->metadata()->description; + } + + /** + * Get module title (short description) + * + * @return string + */ + public function getTitle() + { + return $this->metadata()->title; } /** @@ -308,7 +318,6 @@ class Module */ public function getDependencies() { - return $this->metadata()->depends; } @@ -321,11 +330,11 @@ class Module { if ($this->metadata === null) { $metadata = (object) array( - 'name' => $this->getName(), - 'version' => '0.0.0', - 'shortDescription' => '', - 'description' => '', - 'depends' => array(), + 'name' => $this->getName(), + 'version' => '0.0.0', + 'title' => null, + 'description' => '', + 'depends' => array(), ); if (file_exists($this->metadataFile)) { @@ -336,15 +345,21 @@ class Module while (false !== ($line = fgets($fh))) { $line = rtrim($line); - if ($key === 'description' && $line[0] === ' ') { - $metadata->{$key} .= "\n" . ltrim($line); - continue; + if ($key === 'description') { + if (empty($line)) { + $metadata->description .= "\n"; + continue; + } elseif ($line[0] === ' ') { + $metadata->description .= $line; + continue; + } } list($key, $val) = preg_split('/:\s+/', $line, 2); $key = lcfirst($key); switch ($key) { + case 'depends': if (strpos($val, ' ') === false) { $metadata->depends[$val] = true; @@ -361,9 +376,15 @@ class Module } } break; + case 'description': - $metadata->shortDescription = $val; - // YES, no break here + if ($metadata->title === null) { + $metadata->title = $val; + } else { + $metadata->description = $val; + } + break; + default: $metadata->{$key} = $val; @@ -371,6 +392,18 @@ class Module } } + if ($metadata->title === null) { + $metadata->title = $this->getName(); + } + + if ($metadata->description === '') { + // TODO: Check whether the translation module is able to + // extract this + $metadata->description = t( + 'This module has no description' + ); + } + $this->metadata = $metadata; } return $this->metadata;