Skip to content

Commit

Permalink
Unflatten empty customvars of type array & dict correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jun 22, 2023
1 parent 1756065 commit caf0122
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion library/Icingadb/Model/CustomvarFlat.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public function unFlattenVars(Traversable $flattenedVars): array

$registerValue($data[$step], $source[$step] ?? null, $path, $value);
} else {
$data[$step] = $value;
// Since empty custom vars of type dictionaries and arrays have null values in customvar_flat table,
// we won't be able to render them as such. Therefore, we have to use the value of the `customvar`
// table if it's not null, otherwise the current value.
$data[$step] = $source[$step] ?? $value;
}
};

Expand All @@ -130,6 +133,10 @@ public function unFlattenVars(Traversable $flattenedVars): array
$source = [$realName => $var->customvar->value];

$sourcePath = ltrim(substr($var->flatname, strlen($realName)), '.');
if ($sourcePath === '[]') {
$sourcePath = null;
}

$path = array_merge([$realName], $sourcePath ? explode('.', $sourcePath) : []);
} else {
$path = explode('.', $var->flatname);
Expand Down

0 comments on commit caf0122

Please sign in to comment.