diff --git a/application/controllers/RedundancygroupController.php b/application/controllers/RedundancygroupController.php index 9e0c65fb0..3c43ac856 100644 --- a/application/controllers/RedundancygroupController.php +++ b/application/controllers/RedundancygroupController.php @@ -228,6 +228,7 @@ public function completeAction(): void $suggestions = (new ObjectSuggestions()) ->setModel(DependencyNode::class) ->setBaseFilter(Filter::equal("$column.redundancy_group.id", $this->groupId)) + ->onlyWithCustomVarSources(['host', 'service', 'hostgroup', 'servicegroup']) ->forRequest($this->getServerRequest()); $this->getDocument()->add($suggestions); diff --git a/library/Icingadb/Model/Hostgroup.php b/library/Icingadb/Model/Hostgroup.php index 1ff6f0fba..0c28ee494 100644 --- a/library/Icingadb/Model/Hostgroup.php +++ b/library/Icingadb/Model/Hostgroup.php @@ -71,7 +71,8 @@ public function getDefaultSort() public function createBehaviors(Behaviors $behaviors) { $behaviors->add(new ReRoute([ - 'servicegroup' => 'service.servicegroup' + 'servicegroup' => 'service.servicegroup', + 'child' => 'host.to.from' ])); $behaviors->add(new Binary([ diff --git a/library/Icingadb/Model/Servicegroup.php b/library/Icingadb/Model/Servicegroup.php index 2e4b847b5..2db297a62 100644 --- a/library/Icingadb/Model/Servicegroup.php +++ b/library/Icingadb/Model/Servicegroup.php @@ -72,7 +72,8 @@ public function createBehaviors(Behaviors $behaviors) { $behaviors->add(new ReRoute([ 'host' => 'service.host', - 'hostgroup' => 'service.hostgroup' + 'hostgroup' => 'service.hostgroup', + 'child' => 'service.to.from' ])); $behaviors->add(new Binary([ diff --git a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php index 7630e0162..468846132 100644 --- a/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php +++ b/library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php @@ -43,6 +43,9 @@ class ObjectSuggestions extends Suggestions /** @var array */ protected $customVarSources; + /** @var string[] Reduce {@see $customVarSources} to only given relations to fetch customVar for */ + protected $onlyWithCustomVarSources = []; + public function __construct() { $this->customVarSources = [ @@ -241,7 +244,7 @@ protected function fetchColumnSuggestions($searchTerm) $search = $name . '[*]'; } - foreach ($this->customVarSources as $relation => $label) { + foreach ($this->getCustomVarSources() as $relation => $label) { if (isset($customVar->$relation)) { if (! $titleAdded) { $titleAdded = true; @@ -284,8 +287,9 @@ protected function queryCustomvarConfig(string $searchTerm): Select $scalarQueries = []; $aggregates = ['flatname']; + $customVarSources = $this->getCustomVarSources(); foreach ($resolver->getRelations($customVars->getModel()) as $name => $relation) { - if (isset($this->customVarSources[$name]) && $relation instanceof BelongsToMany) { + if (isset($customVarSources[$name]) && $relation instanceof BelongsToMany) { $query = $customVars->createSubQuery( $relation->getTarget(), $resolver->qualifyPath($name, $tableName) @@ -419,4 +423,37 @@ protected static function collectRelations(Resolver $resolver, Model $subject, a } } } + + /** + * Get the custom variable sources to fetch customVar for + * + * If {@see $onlyWithCustomVarSources} is set, only return the sources that are in the list + * + * @return array + */ + protected function getCustomVarSources(): array + { + if (! empty($this->onlyWithCustomVarSources)) { + $this->customVarSources = array_intersect_key( + $this->customVarSources, + array_flip($this->onlyWithCustomVarSources) + ); + } + + return $this->customVarSources; + } + + /** + * Reduce {@see $customVarSources} to only given relations to fetch customVar for + * + * @param string[] $relations + * + * @return $this + */ + public function onlyWithCustomVarSources(array $relations): self + { + $this->onlyWithCustomVarSources = $relations; + + return $this; + } }