Skip to content
Merged
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
10 changes: 8 additions & 2 deletions phpunit/functional/Glpi/Inventory/Assets/MonitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

include_once __DIR__ . '/../../../../abstracts/AbstractInventoryAsset.php';

/* Test for inc/inventory/asset/monitor.class.php */

class MonitorTest extends AbstractInventoryAsset
{
public static function assetProvider(): array
Expand Down Expand Up @@ -178,6 +176,14 @@ public function testHandle()
$ico->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Monitor']),
'Monitor has not been linked to computer :('
);

$monitor = new \Monitor();
$this->assertTrue(
$monitor->getFromDB($ico->fields['items_id']),
'Monitor does not exist.'
);

$this->assertSame($computer->fields['autoupdatesystems_id'], $monitor->fields['autoupdatesystems_id'], 'Monitor has not the same autoupdatesystems_id as computer :(');
}

public function testInventoryMove()
Expand Down
10 changes: 8 additions & 2 deletions phpunit/functional/Glpi/Inventory/Assets/PeripheralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

include_once __DIR__ . '/../../../../abstracts/AbstractInventoryAsset.php';

/* Test for inc/inventory/asset/controller.class.php */

class PeripheralTest extends AbstractInventoryAsset
{
public static function assetProvider(): array
Expand Down Expand Up @@ -118,6 +116,14 @@ public function testHandle()
$idp->getFromDbByCrit(['computers_id' => $computer->fields['id'], 'itemtype' => 'Peripheral']),
'Peripheral has not been linked to computer :('
);

$peripheral = new \Peripheral();
$this->assertTrue(
$peripheral->getFromDB($idp->fields['items_id']),
'Peripheral does not exist.'
);

$this->assertSame($computer->fields['autoupdatesystems_id'], $peripheral->fields['autoupdatesystems_id'], 'Peripheral has not the same autoupdatesystems_id as computer :(');
}

public function testInventoryUpdate()
Expand Down
6 changes: 5 additions & 1 deletion phpunit/functional/Glpi/Inventory/InventoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ private function checkComputer1($computers_id)
$this->assertIsArray($mmodel);
$models_id = $mmodel['id'];

$autoupdatesystems = $DB->request(['FROM' => \AutoupdateSystem::getTable(), 'WHERE' => ['name' => 'GLPI Native Inventory']])->current();
$this->assertIsArray($autoupdatesystems);
$autoupdatesystems_id = $autoupdatesystems['id'];

$expected = [
'id' => $monitor_link['id'],
'entities_id' => 0,
Expand Down Expand Up @@ -191,7 +195,7 @@ private function checkComputer1($computers_id)
'states_id' => 0,
'ticket_tco' => '0.0000',
'is_dynamic' => 1,
'autoupdatesystems_id' => 0,
'autoupdatesystems_id' => $autoupdatesystems_id,
'uuid' => null,
'is_recursive' => 0,
'linkid' => $monitor_link['linkid'],
Expand Down
15 changes: 15 additions & 0 deletions src/Inventory/Asset/InventoryAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ public function handleLinks()
$manufacturer_name = $value->manufacturers_id;
}

// Set autoupdate system for all assets contained in this field and linked to the current item.
// Extract the asset class name (e.g., "Monitor" from "Glpi\Inventory\Asset\Monitor")
$asset_itemtype_ns = explode('\\', get_class($this));
$asset_itemtype = end($asset_itemtype_ns);

if ($temp_item = getItemForItemtype($asset_itemtype)) {
if ($temp_item->isField('autoupdatesystems_id') && isset($this->item->fields['autoupdatesystems_id'])) {
if ($this->item->fields['autoupdatesystems_id'] == 0) {
$value->autoupdatesystems_id = 0;
} else {
$value->autoupdatesystems_id = Dropdown::getDropdownName('glpi_autoupdatesystems', $this->item->fields['autoupdatesystems_id']);
}
}
}

foreach ($value as $key => &$val) {
if ($val instanceof \stdClass || is_array($val)) {
continue;
Expand Down