From 0e6d03f3da71a6148d3d2449e4f7d374f109ef95 Mon Sep 17 00:00:00 2001 From: Bastian Lederer Date: Thu, 9 Apr 2026 07:54:22 +0200 Subject: [PATCH] Adjust customVarSources and minor improvements --- application/controllers/HostsController.php | 11 +------ .../controllers/ServicesController.php | 11 +------ .../Icingadb/Data/QueryColumnsProvider.php | 30 +++++++++---------- library/Icingadb/Web/Controller.php | 2 +- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php index 70734981..75ca6494 100644 --- a/application/controllers/HostsController.php +++ b/application/controllers/HostsController.php @@ -213,17 +213,8 @@ class HostsController extends Controller public function suggestColumnsAction() { $this->suggestColumns(Host::class, [ - 'checkcommand' => t('Checkcommand %s', '..'), - 'eventcommand' => t('Eventcommand %s', '..'), 'host' => t('Host %s', '..'), - 'hostgroup' => t('Hostgroup %s', '..'), - 'notification' => t('Notification %s', '..'), - 'notificationcommand' => t('Notificationcommand %s', '..'), - 'service' => t('Service %s', '..'), - 'servicegroup' => t('Servicegroup %s', '..'), - 'timeperiod' => t('Timeperiod %s', '..'), - 'user' => t('Contact %s', '..'), - 'usergroup' => t('Contactgroup %s', '..') + 'service' => t('Service %s', '..') ]); } diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 04f117df..78457ae7 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -230,17 +230,8 @@ class ServicesController extends Controller public function suggestColumnsAction() { $this->suggestColumns(Service::class, [ - 'checkcommand' => t('Checkcommand %s', '..'), - 'eventcommand' => t('Eventcommand %s', '..'), 'host' => t('Host %s', '..'), - 'hostgroup' => t('Hostgroup %s', '..'), - 'notification' => t('Notification %s', '..'), - 'notificationcommand' => t('Notificationcommand %s', '..'), - 'service' => t('Service %s', '..'), - 'servicegroup' => t('Servicegroup %s', '..'), - 'timeperiod' => t('Timeperiod %s', '..'), - 'user' => t('Contact %s', '..'), - 'usergroup' => t('Contactgroup %s', '..') + 'service' => t('Service %s', '..') ]); } diff --git a/library/Icingadb/Data/QueryColumnsProvider.php b/library/Icingadb/Data/QueryColumnsProvider.php index 2ec2b0b3..ad3e94c9 100644 --- a/library/Icingadb/Data/QueryColumnsProvider.php +++ b/library/Icingadb/Data/QueryColumnsProvider.php @@ -105,6 +105,20 @@ class QueryColumnsProvider implements IteratorAggregate return $this; } + /** + * Set columns to exclude from the suggestions + * + * @param array $columns + * + * @return $this + */ + public function setExcludedColumns(array $columns): static + { + $this->excludedColumns = $columns; + + return $this; + } + public function getIterator(): Generator { $exactVarSearches = []; @@ -175,7 +189,7 @@ class QueryColumnsProvider implements IteratorAggregate ); foreach ($columns as $columnName => $columnMeta) { if ( - ! in_array($columnName, $this->excludedColumns) + ! in_array($columnName, $this->excludedColumns, true) && $this->matchSuggestion($columnName, $columnMeta, $this->searchTerm) ) { yield [ @@ -429,20 +443,6 @@ class QueryColumnsProvider implements IteratorAggregate return $this; } - /** - * Set columns to exclude from the suggestions - * - * @param array $columns - * - * @return $this - */ - public function setExcludedColumns(array $columns): static - { - $this->excludedColumns = $columns; - - return $this; - } - /** * Check whether the given column path and label match the search term * diff --git a/library/Icingadb/Web/Controller.php b/library/Icingadb/Web/Controller.php index afd9fcc6..5e5eafaa 100644 --- a/library/Icingadb/Web/Controller.php +++ b/library/Icingadb/Web/Controller.php @@ -514,7 +514,7 @@ class Controller extends CompatController $query = $model::on($this->getDb()); $provider = (new QueryColumnsProvider($query))->setCustomVarSources($customVarSources); $suggestions = new SearchSuggestions($provider); - $suggestions->forRequest(ServerRequest::fromGlobals()); + $suggestions->forRequest($this->getServerRequest()); $provider->forSuggestions($suggestions); $this->getDocument()->addHtml($suggestions); }