diff --git a/inc/inventory.class.php b/inc/inventory.class.php index e800fb78..ff9e0ead 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -9,50 +9,49 @@ static function updateInventory($params = []) { && isset($params['inventory_data']) && !empty($params['inventory_data'])) { $availaibleItemType = ["Computer","Printer","NetworkEquipment"]; - foreach($params['inventory_data'] as $itemtype => $inventories){ + foreach ($params['inventory_data'] as $itemtype => $inventories) { - if(in_array($itemtype,$availaibleItemType)){ + if (in_array($itemtype,$availaibleItemType)) { //retrive items id switch itemtype switch ($itemtype) { case Computer::getType(): $items_id = $params['computers_id']; break; - case NetworkEquipment::getType(): + case NetworkEquipment::getType(): $items_id = $params['networkequipments_id']; break; - case Printer::getType(): + case Printer::getType(): $items_id = $params['printers_id']; break; } //load inventory from DB because //FI not update XML file if computer is not update - if($itemtype == Computer::getType()){ + if ($itemtype == Computer::getType()) { $db_info = new PluginFusioninventoryInventoryComputerComputer(); if ($db_info->getFromDBByCrit(['computers_id' => $items_id])) { $arrayinventory = unserialize(gzuncompress($db_info->fields['serialized_inventory'])); - if(isset($arrayinventory['custom'])){ - if(isset($arrayinventory['custom']['container']['ID'])){ + if (isset($arrayinventory['custom'])) { + if (isset($arrayinventory['custom']['container']['ID'])) { $customData['container'][0] = $arrayinventory['custom']['container']; - }else{ + } else { $customData = $arrayinventory['custom']; } self::updateFields($customData, $itemtype, $items_id); } } - //Load XML file because FI - //always update XML file and don't store inventory into DB - }else{ + //Load XML file because FI always update XML file and don't store inventory into DB + } else { $file = self::loadXMLFile($itemtype, $items_id); - if($file !== false){ + if ($file !== false) { $arrayinventory = PluginFusioninventoryFormatconvert::XMLtoArray($file); - if(isset($arrayinventory['CUSTOM'])){ - if(isset($arrayinventory['CUSTOM']['CONTAINER']['ID'])){ + if (isset($arrayinventory['CUSTOM'])) { + if (isset($arrayinventory['CUSTOM']['CONTAINER']['ID'])) { $customData['container'][0] = $arrayinventory['CUSTOM']['CONTAINER']; - }else{ + } else { $customData['container'] = $arrayinventory['CUSTOM']['CONTAINER']; } self::updateFields($customData, $itemtype, $items_id); @@ -64,7 +63,6 @@ static function updateInventory($params = []) { } } - static function updateFields($customData, $itemtype, $items_id){ foreach ($customData['container'] as $key => $dataContainers) { $container = new PluginFieldsContainer(); diff --git a/setup.php b/setup.php index 12a91cec..715ccc05 100644 --- a/setup.php +++ b/setup.php @@ -98,13 +98,11 @@ function plugin_init_fields() { } } - if ($plugin->isActivated('fusioninventory')) { $PLUGIN_HOOKS['fusioninventory_inventory']['fields'] = ['PluginFieldsInventory', 'updateInventory']; } - // complete rule engine $PLUGIN_HOOKS['use_rules']['fields'] = ['PluginFusioninventoryTaskpostactionRule']; $PLUGIN_HOOKS['rule_matched']['fields'] = 'plugin_fields_rule_matched';