Skip to content

Commit

Permalink
Fix column suggestions for empty custom vars of type array
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jun 22, 2023
1 parent 2a2905e commit 58d8183
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions library/Icingadb/Web/Control/SearchBar/ObjectSuggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,24 @@ protected function fetchColumnSuggestions($searchTerm)

// Custom variables only after the columns are exhausted and there's actually a chance the user sees them
$titleAdded = false;
$parsedArrayVars = [];
foreach ($this->getDb()->select($this->queryCustomvarConfig($searchTerm)) as $customVar) {
$search = $name = $customVar->flatname;
if (preg_match('/\w+\[(\d+)]$/', $search, $matches)) {
// array vars need to be specifically handled
if ($matches[1] !== '0') {
if (preg_match('/\w+(?:\[(\d*)])+$/', $search, $matches)) {
$index = $matches[2] ?? $matches[1];
if ($index !== "" && $index !== '0') {
continue;
}

$name = substr($search, 0, -3);
$name = substr($search, 0, $index === "" ? -2 : -3);
if (isset($parsedArrayVars[$name])) {
continue;
}

$parsedArrayVars[$name] = true;
$search = $name . '[*]';
} elseif (substr($name, -1) === '.') {
$name = substr($name, 0, -1) . ' (empty)';
}

foreach ($this->customVarSources as $relation => $label) {
Expand Down

0 comments on commit 58d8183

Please sign in to comment.