Skip to content

Commit

Permalink
Make sure remote managements are removed if node is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz committed Nov 27, 2023
1 parent 06b9453 commit 98a47fc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Inventory/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ function ($property_name) {
) {
//if inventory is not partial, we consider following properties are empty if not present; so they'll be removed
$empty_props = [
'virtualmachines'
'virtualmachines',
'remote_mgmt'
];
}

Expand Down
56 changes: 54 additions & 2 deletions tests/functional/Glpi/Inventory/Assets/RemoteManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ public function testInventoryUpdate()
//computer inventory knows only "teamviewer" and "anydesk" remote managements
$this->doInventory($xml_source, true);

//we still have 3 remote managements
//we still have 3 remote managements
$mgmts = $mgmt->find();
$this->integer(count($mgmts))->isIdenticalTo(3);

//we still have 3 remote managements items linked to the computer
//we still have 3 remote managements items linked to the computer
$mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id]);
$this->integer(count($mgmts))->isIdenticalTo(3);

Expand Down Expand Up @@ -324,4 +324,56 @@ public function testInventoryUpdate()
$mgmts = $mgmt->find(['itemtype' => 'Computer', 'items_id' => $computers_id, 'is_dynamic' => 0]);
$this->integer(count($mgmts))->isIdenticalTo(1);
}

public function testNoMoreRemoteManagement()
{
$mgmt = new \Item_RemoteManagement();

$xml_source = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<REQUEST>
<CONTENT>
<REMOTE_MGMT>
<ID>abcdyz</ID>
<TYPE>anydesk</TYPE>
</REMOTE_MGMT>
<HARDWARE>
<NAME>pc002</NAME>
</HARDWARE>
<BIOS>
<SSN>ggheb7ne7</SSN>
</BIOS>
<VERSIONCLIENT>FusionInventory-Agent_v2.3.19</VERSIONCLIENT>
</CONTENT>
<DEVICEID>test-pc002</DEVICEID>
<QUERY>INVENTORY</QUERY>
</REQUEST>";


$this->doInventory($xml_source, true);

//we have 1 remote managements (anydesk / abcdyz) linked to computer
$mgmts = $mgmt->find();
$this->integer(count($mgmts))->isIdenticalTo(1);

$xml_source = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<REQUEST>
<CONTENT>
<HARDWARE>
<NAME>pc002</NAME>
</HARDWARE>
<BIOS>
<SSN>ggheb7ne7</SSN>
</BIOS>
<VERSIONCLIENT>FusionInventory-Agent_v2.3.19</VERSIONCLIENT>
</CONTENT>
<DEVICEID>test-pc002</DEVICEID>
<QUERY>INVENTORY</QUERY>
</REQUEST>";

$this->doInventory($xml_source, true);

//we have no remote managements linked to computer
$mgmts = $mgmt->find();
$this->integer(count($mgmts))->isIdenticalTo(0);
}
}

0 comments on commit 98a47fc

Please sign in to comment.