Skip to content

Commit

Permalink
fix: Make additional-content option works as before when merging json…
Browse files Browse the repository at this point in the history
… lists

Closes #589
  • Loading branch information
g-bougard committed Jan 24, 2024
1 parent 82e3ca7 commit 3720f7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ core:
inventory:
* Fix network default route discovery on linux
* Fix virtualmachine inventory on computer providing vmware-cmd command
* fix #589: Make additional-content option works as before when merging a json list

netdiscovery/netinventory:
* Keep device mac address found via snmp during netdiscovery as this is the one
Expand Down
8 changes: 6 additions & 2 deletions lib/GLPI/Agent/Protocol/Inventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,14 @@ sub converted {
my $merge = $self->{_merge_content};
if ($merge) {
foreach my $key (keys(%{$merge})) {
if (! $content->{$key} || ref($merge->{$key}) ne 'HASH') {
if (! $content->{$key} || (ref($merge->{$key}) ne 'HASH' && ref($merge->{$key}) ne 'ARRAY')) {
$content->{$key} = $merge->{$key};
} else {
if (ref($content->{$key}) eq 'HASH') {
if (ref($content->{$key}) eq 'ARRAY' && ref($merge->{$key}) eq 'ARRAY') {
foreach my $item (@{$merge->{$key}}) {
push @{$content->{$key}}, $item;
}
} elsif (ref($content->{$key}) eq 'HASH') {
foreach my $leaf (keys(%{$merge->{$key}})) {
$content->{$key}->{$leaf} = $merge->{$key}->{$leaf};
}
Expand Down

0 comments on commit 3720f7f

Please sign in to comment.