Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Fix manufacturer problem when lock. closes #1900
Browse files Browse the repository at this point in the history
  • Loading branch information
David Durieux committed Aug 11, 2016
1 parent 97afb57 commit 467d071
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 6 deletions.
13 changes: 7 additions & 6 deletions inc/formatconvert.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ static function addValues($array, $a_key) {



function replaceids($array, $itemtype, $items_id) {
function replaceids($array, $itemtype, $items_id, $level=0) {
global $CFG_GLPI;

$a_lockable = PluginFusioninventoryLock::getLockFields(getTableForItemType($itemtype),
Expand All @@ -1827,7 +1827,11 @@ function replaceids($array, $itemtype, $items_id) {
} else {
//if (is_array($value)) {
if ((array)$value === $value) {
$array[$key] = $this->replaceids($value, $itemtype, $items_id);
$new_itemtype = $itemtype;
if ($level == 0) {
$new_itemtype = $key;
}
$array[$key] = $this->replaceids($value, $new_itemtype, $items_id, $level + 1);
} else {
if (!PluginFusioninventoryLock::isFieldLocked($a_lockable, $key)) {
if (!is_numeric($key)
Expand All @@ -1845,10 +1849,7 @@ function replaceids($array, $itemtype, $items_id) {
}
}
if (!is_numeric($key)) {
if ($key == "bios_manufacturers_id") {
$array[$key] = Dropdown::importExternal($this->foreignkey_itemtype['manufacturers_id'],
$value);
} else if ($key == "locations_id") {
if ($key == "locations_id") {
$array[$key] = Dropdown::importExternal('Location',
$value,
$_SESSION["plugin_fusioninventory_entity"]);
Expand Down
86 changes: 86 additions & 0 deletions phpunit/2_Integration/DevicesLocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,92 @@ public function computerLockItemtype() {
}


/**
* @test
*
* Test computer with manufacturer lock
*/
public function computerManufacturerLock() {
global $DB;

$DB->connect();

self::restore_database();

$_SESSION['glpiactive_entity'] = 0;
$_SESSION["plugin_fusioninventory_entity"] = 0;
$_SESSION["glpiname"] = 'Plugin_FusionInventory';

$pfInventoryComputerInventory = new PluginFusioninventoryInventoryComputerInventory();
$pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
$computer = new Computer();
$pfLock = new PluginFusioninventoryLock();

$a_computerinventory = array(
"Computer" => array(
"name" => "pc003",
"serial" => "gtrgvdbg",
"computermodels_id" => "model xxx",
"manufacturers_id" => "Dell"
),
"fusioninventorycomputer" => Array(
'last_fusioninventory_update' => date('Y-m-d H:i:s'),
'serialized_inventory' => 'something',
'bios_manufacturers_id' => 'Award'
),
'soundcard' => array(),
'graphiccard' => array(),
'controller' => array(),
'processor' => array(),
"computerdisk" => array(),
'memory' => array(),
'monitor' => array(),
'printer' => array(),
'peripheral' => array(),
'networkport' => array(),
'SOFTWARES' => array(),
'harddrive' => array(),
'virtualmachine' => array(),
'antivirus' => array(),
'storage' => array(),
'licenseinfo' => array(),
'networkcard' => array(),
'drive' => array(),
'batteries' => array(),
'remote_mgmt' => array(),
'itemtype' => 'Computer'
);

$input = array(
'name' => 'pc003',
'serial' => 'gtrgvdbg',
'entities_id' => 0
);
$computers_id = $computer->add($input);

$input = array(
'tablename' => 'glpi_computers',
'items_id' => $computers_id,
'tablefields' => exportArrayToDB(array('manufacturers_id'))
);
$pfLock->add($input);

$pfInventoryComputerInventory->fill_arrayinventory($a_computerinventory);
$pfInventoryComputerInventory->rulepassed($computers_id, 'Computer');

$this->assertEquals(countElementsInTable('glpi_computers'), 1, 'More than 1 computer created');
$computer->getFromDB(1);
$this->assertEquals($computer->fields['manufacturers_id'], 0, "Manufacturer not right");

$pfInventoryComputerComputer->getFromDB(1);
$this->assertEquals($pfInventoryComputerComputer->fields['bios_manufacturers_id'], 1, "bios manufacturer not right");

$GLPIlog = new GLPIlogs();
$GLPIlog->testSQLlogs();
$GLPIlog->testPHPlogs();
}


/**
* @test
*
Expand Down

0 comments on commit 467d071

Please sign in to comment.