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

Open
wants to merge 3 commits into
base: dependencies
Choose a base branch
from
Open
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 @@ -47,7 +47,7 @@
$groupId = $this->params->shiftRequired('id');
}

$this->groupId = $groupId;

Check failure on line 50 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 50 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 @@ -61,7 +61,7 @@

$this->applyRestrictions($query);

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

Check failure on line 64 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 64 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 @@ -75,9 +75,9 @@

$this->applyRestrictions($summary);

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

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

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

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

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 80 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 80 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 @@ -228,6 +228,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 @@ -252,7 +253,7 @@
);

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

Check failure on line 256 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 256 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 @@ -319,7 +320,7 @@
return $query;
}

protected function fetchCommandTargets()

Check failure on line 323 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 323 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
3 changes: 2 additions & 1 deletion library/Icingadb/Model/Hostgroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
3 changes: 2 additions & 1 deletion library/Icingadb/Model/Servicegroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
41 changes: 39 additions & 2 deletions library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
Loading