diff --git a/src/CentreonLegacy/Core/Widget/Information.php b/src/CentreonLegacy/Core/Widget/Information.php index f50d2518035..b8838d2902c 100644 --- a/src/CentreonLegacy/Core/Widget/Information.php +++ b/src/CentreonLegacy/Core/Widget/Information.php @@ -38,16 +38,29 @@ class Information { /** - * * @var \Pimple\Container */ protected $dependencyInjector; /** - * * @var \CentreonLegacy\Core\Utils\Utils */ protected $utils; + + /** + * @var array + */ + protected $cachedWidgetsList = []; + + /** + * @var bool + */ + protected $hasWidgetsForUpgrade = false; + + /** + * @var bool + */ + protected $hasWidgetsForInstallation = false; /** * @@ -251,15 +264,19 @@ public function getList() $widgets[$name]['upgradeable'] = false; $widgets[$name]['installed_version'] = _('N/A'); $widgets[$name]['available_version'] = $widgets[$name]['version']; + unset($widgets[$name]['version']); + if (isset($installedWidgets[$name])) { $widgets[$name]['id'] = $installedWidgets[$name]['widget_model_id']; $widgets[$name]['is_installed'] = true; $widgets[$name]['installed_version'] = $installedWidgets[$name]['version']; - $widgets[$name]['upgradeable'] = $this->isUpgradeable( + $widgetIsUpgradable = $this->isUpgradeable( $widgets[$name]['available_version'], $widgets[$name]['installed_version'] ); + $widgets[$name]['upgradeable'] = $widgetIsUpgradable; + $this->hasWidgetsForUpgrade = $widgetIsUpgradable ?: $this->hasWidgetsForUpgrade; } } @@ -270,6 +287,9 @@ public function getList() } } + $this->hasWidgetsForInstallation = count($availableWidgets) > count($installedWidgets); + $this->cachedWidgetsList = $widgets; + return $widgets; } @@ -316,4 +336,32 @@ public function getWidgetPath($widgetName = '') { return $this->utils->buildPath('/widgets/' . $widgetName) . '/'; } + + public function hasWidgetsForUpgrade() + { + return $this->hasWidgetsForUpgrade; + } + + public function getUpgradeableList() + { + $list = empty($this->cachedWidgetsList) ? $this->getList() : $this->cachedWidgetsList; + + return array_filter($list, function ($widget) { + return $widget['upgradeable']; + }); + } + + public function hasWidgetsForInstallation() + { + return $this->hasWidgetsForInstallation; + } + + public function getInstallableList() + { + $list = empty($this->cachedWidgetsList) ? $this->getList() : $this->cachedWidgetsList; + + return array_filter($list, function ($widget) { + return !$widget['is_installed']; + }); + } } diff --git a/www/include/options/oreon/widgets/action.php b/www/include/options/oreon/widgets/action.php index da7c479034f..eaf9158f189 100644 --- a/www/include/options/oreon/widgets/action.php +++ b/www/include/options/oreon/widgets/action.php @@ -69,6 +69,14 @@ $widgetInstaller = $factory->newInstaller($directory); $widgetInstaller->install(); break; + case 'install-all': + $widgetsToInstall = $widgetInfoObj->getInstallableList(); + + foreach ($widgetsToInstall as $widgetName => $widgetData) { + $widgetInstaller = $factory->newInstaller($widgetName); + $widgetInstaller->install(); + } + break; case 'uninstall': $widgetRemover = $factory->newRemover($directory); $widgetRemover->remove(); @@ -77,6 +85,14 @@ $widgetUpgrader = $factory->newUpgrader($directory); $widgetUpgrader->upgrade(); break; + case 'upgrade-all': + $widgetsToUpgrade = $widgetInfoObj->getUpgradeableList(); + + foreach ($widgetsToUpgrade as $widgetName => $widgetData) { + $widgetUpgrader = $factory->newUpgrader($widgetName); + $widgetUpgrader->upgrade(); + } + break; default: throw new Exception('Unknown action'); } diff --git a/www/include/options/oreon/widgets/list.ihtml b/www/include/options/oreon/widgets/list.ihtml index 9fce3366744..a12a9024b45 100644 --- a/www/include/options/oreon/widgets/list.ihtml +++ b/www/include/options/oreon/widgets/list.ihtml @@ -1,3 +1,11 @@ +{if $hasWidgetsForInstallation} + +{/if} + +{if $hasWidgetsForUpgrade} + +{/if} + diff --git a/www/include/options/oreon/widgets/list.php b/www/include/options/oreon/widgets/list.php index a3da9756e5d..2ea9050c9ba 100644 --- a/www/include/options/oreon/widgets/list.php +++ b/www/include/options/oreon/widgets/list.php @@ -48,20 +48,24 @@ $tpl = initSmartyTpl($path, $tpl); $labels = array(); -$labels['title'] = _("Title"); -$labels['description'] = _("Description"); -$labels['version'] = _("Version"); -$labels['author'] = _("Author"); -$labels['actions'] = _("Actions"); +$labels['title'] = _('Title'); +$labels['description'] = _('Description'); +$labels['version'] = _('Version'); +$labels['author'] = _('Author'); +$labels['actions'] = _('Actions'); +$tpl->assign('hasWidgetsForInstallation', $widgetInfoObj->hasWidgetsForInstallation()); +$tpl->assign('hasWidgetsForUpgrade', $widgetInfoObj->hasWidgetsForUpgrade()); $tpl->assign('widgets', $widgets); $tpl->assign('labels', $labels); -$tpl->display("list.ihtml"); +$tpl->display('list.ihtml'); ?>
{$labels.title}