Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectSuggestions: Make CustomVar suggestion sources adjustable #1100

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions application/controllers/RedundancygroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$groupId = $this->params->shiftRequired('id');
}

$this->groupId = $groupId;

Check failure on line 48 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$groupId (string) does not accept mixed.

Check failure on line 48 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$groupId (string) does not accept mixed.
}

/**
Expand All @@ -59,7 +59,7 @@

$this->applyRestrictions($query);

$this->group = $query->first();

Check failure on line 62 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$group (Icinga\Module\Icingadb\Model\RedundancyGroup) does not accept ipl\Orm\Model|null.

Check failure on line 62 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$group (Icinga\Module\Icingadb\Model\RedundancyGroup) does not accept ipl\Orm\Model|null.

if ($this->group === null) {
$this->httpNotFound($this->translate('Redundancy Group not found'));
Expand All @@ -73,9 +73,9 @@

$this->applyRestrictions($summary);

$this->groupSummary = $summary->first();

Check failure on line 76 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$groupSummary (Icinga\Module\Icingadb\Model\RedundancyGroupSummary) does not accept ipl\Orm\Model|null.

Check failure on line 76 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Property Icinga\Module\Icingadb\Controllers\RedundancygroupController::$groupSummary (Icinga\Module\Icingadb\Model\RedundancyGroupSummary) does not accept ipl\Orm\Model|null.

$this->addControl(new RedundancyGroupHeader($this->group, $this->groupSummary));

Check failure on line 78 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Parameter #2 $summary of class Icinga\Module\Icingadb\Widget\Detail\RedundancyGroupHeader constructor expects Icinga\Module\Icingadb\Model\RedundancyGroupSummary, ipl\Orm\Model|null given.

Check failure on line 78 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Parameter #2 $summary of class Icinga\Module\Icingadb\Widget\Detail\RedundancyGroupHeader constructor expects Icinga\Module\Icingadb\Model\RedundancyGroupSummary, ipl\Orm\Model|null given.
}

public function indexAction(): void
Expand Down Expand Up @@ -186,7 +186,7 @@

$searchBar->getSuggestionUrl()->setParam('isChildrenTab');
$searchBar->getEditorUrl()
->setParams((clone $searchBar->getEditorUrl()->getParams())->set('isChildrenTab', true));

Check failure on line 189 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Parameter #2 $value of method Icinga\Web\UrlParams::set() expects string, true given.

Check failure on line 189 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Parameter #2 $value of method Icinga\Web\UrlParams::set() expects string, true given.

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
Expand Down Expand Up @@ -230,6 +230,7 @@
$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);
Expand All @@ -254,7 +255,7 @@
);

if ($isChildrenTab) {
$editor->getSuggestionUrl()->setParam('isChildrenTab');

Check failure on line 258 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Cannot call method setParam() on ipl\Web\Url|null.

Check failure on line 258 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Cannot call method setParam() on ipl\Web\Url|null.
}

$this->getDocument()->add($editor);
Expand Down Expand Up @@ -321,7 +322,7 @@
return $query;
}

protected function fetchCommandTargets()

Check failure on line 325 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Method Icinga\Module\Icingadb\Controllers\RedundancygroupController::fetchCommandTargets() has no return type specified.

Check failure on line 325 in application/controllers/RedundancygroupController.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Method Icinga\Module\Icingadb\Controllers\RedundancygroupController::fetchCommandTargets() has no return type specified.
{
$filter = Filter::all(Filter::equal('child.redundancy_group.id', $this->groupId));

Expand Down
4 changes: 3 additions & 1 deletion library/Icingadb/Model/Hostgroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public function getDefaultSort()
public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new ReRoute([
'servicegroup' => 'service.servicegroup'
'servicegroup' => 'service.servicegroup',
'parent' => 'host.from.to',
'child' => 'host.to.from'
]));

$behaviors->add(new Binary([
Expand Down
4 changes: 3 additions & 1 deletion library/Icingadb/Model/Servicegroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new ReRoute([
'host' => 'service.host',
'hostgroup' => 'service.hostgroup'
'hostgroup' => 'service.hostgroup',
'parent' => 'service.from.to',
'child' => 'service.to.from'
]));

$behaviors->add(new Binary([
Expand Down
14 changes: 14 additions & 0 deletions library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,18 @@ protected static function collectRelations(Resolver $resolver, Model $subject, a
}
}
}

/**
* Reduce {@see $customVarSources} to only given relations to fetch variables from
*
* @param string[] $relations
*
* @return $this
*/
public function onlyWithCustomVarSources(array $relations): self
{
$this->customVarSources = array_intersect_key($this->customVarSources, array_flip($relations));

return $this;
}
}
Loading