public function testLog() { global $DB; $DB->connect(); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $computer = new Computer(); $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib(); $date = date('Y-m-d H:i:s'); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION['glpiactiveentities_string'] = 0; $_SESSION['glpishowallentities'] = 1; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $this->a_inventory = array('fusioninventorycomputer' => array('winowner' => 'test', 'wincompany' => 'siprossii', 'operatingsystem_installationdate' => '2012-10-16 08:12:56', 'last_fusioninventory_update' => $date), '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(), 'itemtype' => 'Computer'); $this->a_inventory['Computer'] = array('name' => 'pc', 'users_id' => 0, 'operatingsystems_id' => 'freebsd', 'operatingsystemversions_id' => '9.1-RELEASE', 'uuid' => '68405E00-E5BE-11DF-801C-B05981201220', 'domains_id' => 'mydomain.local', 'os_licenseid' => '', 'os_license_number' => '', 'operatingsystemservicepacks_id' => 'GENERIC ()root@farrell.cse.buffalo.edu', 'manufacturers_id' => '', 'computermodels_id' => '', 'serial' => 'XB63J7D', 'computertypes_id' => 'Notebook', 'is_dynamic' => 1, 'contact' => 'ddurieux'); $this->a_inventory['processor'] = array(array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400), array('nbcores' => 2, 'manufacturers_id' => 'Intel Corporation', 'designation' => 'Core i3', 'frequence' => 2400, 'nbthreads' => 2, 'serial' => '', 'frequency' => 2400, 'frequency_default' => 2400)); $this->a_inventory['memory'] = array(array('size' => 2048, 'serial' => '98F6FF18', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 1), array('size' => 2048, 'serial' => '95F1833E', 'frequence' => '1067 MHz', 'devicememorytypes_id' => 'DDR3', 'designation' => 'DDR3 - SODIMM (None)', 'busID' => 2)); $this->a_inventory['monitor'] = array(array('name' => '', 'serial' => '', 'manufacturers_id' => '')); $this->a_inventory['networkport'] = array('em0-00:23:18:cf:0d:93' => array('name' => 'em0', 'netmask' => '255.255.255.0', 'subnet' => '192.168.30.0', 'mac' => '00:23:18:cf:0d:93', 'instantiation_type' => 'NetworkPortEthernet', 'virtualdev' => 0, 'ssid' => '', 'gateway' => '', 'dhcpserver' => '', 'logical_number' => 0, 'ipaddress' => array('192.168.30.198')), 'lo0-' => array('name' => 'lo0', 'virtualdev' => 1, 'mac' => '', 'instantiation_type' => 'NetworkPortLocal', 'subnet' => '', 'ssid' => '', 'gateway' => '', 'netmask' => '', 'dhcpserver' => '', 'logical_number' => 1, 'ipaddress' => array('::1', 'fe80::1', '127.0.0.1'))); $this->a_inventory['software'] = array('gentiumbasic$$$$110$$$$1$$$$0' => array('name' => 'GentiumBasic', 'version' => 110, 'manufacturers_id' => 1, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1), 'imagemagick$$$$6.8.0.7_1$$$$2$$$$0' => array('name' => 'ImageMagick', 'version' => '6.8.0.7_1', 'manufacturers_id' => 2, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1), 'orbit2$$$$2.14.19$$$$3$$$$0' => array('name' => 'ORBit2', 'version' => '2.14.19', 'manufacturers_id' => 3, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0, 'is_dynamic' => 1)); $this->a_inventory = $pfFormatconvert->replaceids($this->a_inventory); $serialized = gzcompress(serialize($this->a_inventory)); $this->a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $computer->add(array('serial' => 'XB63J7D', 'entities_id' => 0)); // truncate glpi_logs $DB->query('TRUNCATE TABLE `glpi_logs`;'); $this->assertEquals(0, countElementsInTable('glpi_logs'), "Log must be empty (truncate)"); $_SESSION['glpiactive_entity'] = 0; $pfiComputerLib->updateComputer($this->a_inventory, 1, TRUE); $a_logs = getAllDatasFromTable('glpi_logs'); foreach ($a_logs as $id => $data) { unset($data['date_mod']); $a_logs[$id] = $data; } $a_reference = array(1 => array('id' => 1, 'itemtype' => 'Software', 'items_id' => 1, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 2 => array('id' => 2, 'itemtype' => 'Software', 'items_id' => 2, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 3 => array('id' => 3, 'itemtype' => 'Software', 'items_id' => 3, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 4 => array('id' => 4, 'itemtype' => 'SoftwareVersion', 'items_id' => 1, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 5 => array('id' => 5, 'itemtype' => 'SoftwareVersion', 'items_id' => 2, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => ''), 6 => array('id' => 6, 'itemtype' => 'SoftwareVersion', 'items_id' => 3, 'itemtype_link' => '', 'linked_action' => 20, 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => 0, 'old_value' => '', 'new_value' => '')); $this->assertEquals($a_reference, $a_logs, "Log must be 6 " . print_r($a_logs, true)); $DB->query('TRUNCATE `glpi_logs`'); // Update a second time and must not have any new lines in glpi_logs $pfiComputerLib->updateComputer($this->a_inventory, 1, FALSE); $a_logs = getAllDatasFromTable('glpi_logs'); $a_reference = array(); $this->assertEquals($a_reference, $a_logs, "Log may be empty at second update " . print_r($a_logs, true)); // * Modify: contact // * remove a processor // * Remove a software $this->a_inventory['Computer']['contact'] = 'root'; unset($this->a_inventory['processor'][3]); unset($this->a_inventory['software']['orbit2$$$$2.14.19$$$$3$$$$0']); $DB->query('TRUNCATE `glpi_logs`'); $pfiComputerLib->updateComputer($this->a_inventory, 1, FALSE); $a_logs = getAllDatasFromTable('glpi_logs'); foreach ($a_logs as $id => $data) { unset($data['date_mod']); $a_logs[$id] = $data; } $a_reference = array(1 => array('id' => '1', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => '', 'linked_action' => '0', 'user_name' => '', 'id_search_option' => '7', 'old_value' => 'ddurieux', 'new_value' => 'root'), 2 => array('id' => '2', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => 'DeviceProcessor', 'linked_action' => '3', 'user_name' => '', 'id_search_option' => '0', 'old_value' => 'Core i3 (1)', 'new_value' => ''), 3 => array('id' => '3', 'itemtype' => 'Computer', 'items_id' => '1', 'itemtype_link' => 'SoftwareVersion', 'linked_action' => '5', 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => '0', 'old_value' => 'ORBit2 - 2.14.19 (3)', 'new_value' => ''), 4 => array('id' => '4', 'itemtype' => 'SoftwareVersion', 'items_id' => '3', 'itemtype_link' => 'Computer', 'linked_action' => '5', 'user_name' => 'Plugin_FusionInventory', 'id_search_option' => '0', 'old_value' => 'pc (1)', 'new_value' => '')); $this->assertEquals($a_reference, $a_logs, "May have 5 logs (update contact, remove processor\n and remove a software)"); }
/** * @test */ public function Replaceids() { global $DB; $DB->connect(); $a_inventory['software'] = array(); $a_inventory['Computer'] = array('name' => 'pc', 'users_id' => 0, 'operatingsystems_id' => 'freebsd', 'operatingsystemversions_id' => '9.1-RELEASE'); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_inventory = $pfFormatconvert->replaceids($a_inventory); $a_reference['software'] = array(); $a_reference['Computer'] = array('name' => 'pc', 'users_id' => 0, 'operatingsystems_id' => 1, 'operatingsystemversions_id' => 1); $this->assertEquals($a_reference, $a_inventory); $GLPIlog = new GLPIlogs(); $GLPIlog->testSQLlogs(); $GLPIlog->testPHPlogs(); }
/** * @test */ public function SoftwareUniqueForTwoComputers() { global $DB; $DB->connect(); $date = date('Y-m-d H:i:s'); $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION['glpiactiveentities_string'] = 0; $_SESSION['glpishowallentities'] = 1; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $a_inventory = array('fusioninventorycomputer' => array('winowner' => 'test', 'wincompany' => 'siprossii', 'operatingsystem_installationdate' => '2012-10-16 08:12:56', 'last_fusioninventory_update' => $date), '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(), 'itemtype' => 'Computer'); $a_inventory['Computer'] = array('name' => 'pcJ1', 'comment' => 'amd64/-1-11-30 22:04:44', 'users_id' => 0, 'operatingsystems_id' => 'freebsd', 'operatingsystemversions_id' => '9.1-RELEASE', 'uuid' => '68405E00-E5BE-11DF-801C-B05981201220', 'domains_id' => 'mydomain.local', 'os_licenseid' => '', 'os_license_number' => '', 'operatingsystemservicepacks_id' => 'GENERIC ()root@farrell.cse.buffalo.edu', 'manufacturers_id' => '', 'computermodels_id' => '', 'serial' => 'XB63J7J1', 'computertypes_id' => 'Notebook', 'is_dynamic' => 1, 'contact' => 'ddurieux'); $a_inventory['software'] = array('acrobat_reader_9.2$$$$1.0.0.0$$$$192$$$$0' => array('name' => 'acrobat_Reader_9.2', 'version' => '1.0.0.0', 'manufacturers_id' => 192, 'entities_id' => 0, 'is_template_computer' => 0, 'is_deleted_computer' => 0)); $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib(); $computer = new Computer(); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $software = new Software(); $a_inventory = $pfFormatconvert->replaceids($a_inventory); $serialized = gzcompress(serialize($a_inventory)); $a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $this->items_id = $computer->add(array('serial' => 'XB63J7J1', 'entities_id' => 0)); $_SESSION['glpiactive_entity'] = 0; $pfiComputerLib->updateComputer($a_inventory, $this->items_id, FALSE); $a_software = $software->find("`name`='acrobat_Reader_9.2'"); $this->assertEquals(1, count($a_software), "First computer added"); $a_inventory['Computer']['name'] = "pcJ2"; $a_inventory['Computer']['serial'] = "XB63J7J2"; $pfiComputerLib->updateComputer($a_inventory, $this->items_id, FALSE); $a_software = $software->find("`name`='acrobat_Reader_9.2'"); $this->assertEquals(1, count($a_software), "Second computer added"); }
/** * Update VirtualMachine in computer * * @test */ public function ComputerVirtualmachineUpdateMemory() { global $DB; $DB->connect(); $a_inventory = $this->computer_inventory; $a_inventory['virtualmachine'][0]['ram'] = '2048'; $pfiComputerLib = new PluginFusioninventoryInventoryComputerLib(); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_inventory = $pfFormatconvert->replaceids($a_inventory); $serialized = gzcompress(serialize($a_inventory)); $a_inventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $pfiComputerLib->updateComputer($a_inventory, 1, FALSE); $nbvm = countElementsInTable("glpi_computervirtualmachines"); $this->assertEquals(1, $nbvm, 'May have only 1 VM'); $a_data = getAllDatasFromTable("glpi_computervirtualmachines"); $a_reference = array('1' => array('id' => '1', 'entities_id' => '0', 'computers_id' => '1', 'name' => 'Windows 7', 'virtualmachinestates_id' => '1', 'virtualmachinesystems_id' => '1', 'virtualmachinetypes_id' => '1', 'uuid' => '2961ecf6-7e94-488d-ae0d-e427123078b3', 'vcpu' => '1', 'ram' => '2048', 'is_deleted' => '0', 'is_dynamic' => '1', 'comment' => null)); $this->assertEquals($a_reference, $a_data); }
/** * If rule have found computer or rule give to create computer * * @param $items_id integer id of the computer found (or 0 if must be created) * @param $itemtype value Computer type here * * @return nothing * **/ function rulepassed($items_id, $itemtype) { global $DB, $PLUGIN_FUSIONINVENTORY_XML, $PF_ESXINVENTORY, $CFG_GLPI; PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n"); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_computerinventory = $pfFormatconvert->replaceids($this->arrayinventory); $entities_id = $_SESSION["plugin_fusioninventory_entity"]; if ($itemtype == 'Computer') { $pfInventoryComputerLib = new PluginFusioninventoryInventoryComputerLib(); $pfAgent = new PluginFusioninventoryAgent(); $computer = new Computer(); if ($items_id == '0') { if ($entities_id == -1) { $entities_id = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; } $_SESSION['glpiactiveentities'] = array($entities_id); $_SESSION['glpiactiveentities_string'] = $entities_id; $_SESSION['glpiactive_entity'] = $entities_id; } else { $computer->getFromDB($items_id); $a_computerinventory['Computer']['states_id'] = $computer->fields['states_id']; $input = array(); PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input); if (isset($input['states_id'])) { $a_computerinventory['Computer']['states_id'] = $input['states_id']; } if ($entities_id == -1) { $entities_id = $computer->fields['entities_id']; $_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id']; } $_SESSION['glpiactiveentities'] = array($entities_id); $_SESSION['glpiactiveentities_string'] = $entities_id; $_SESSION['glpiactive_entity'] = $entities_id; if ($computer->fields['entities_id'] != $entities_id) { $pfEntity = new PluginFusioninventoryEntity(); $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer(); $moveentity = FALSE; if ($pfEntity->getValue('transfers_id_auto', $computer->fields['entities_id']) > 0) { if (!$pfInventoryComputerComputer->getLock($items_id)) { $moveentity = TRUE; } } if ($moveentity) { $pfEntity = new PluginFusioninventoryEntity(); $transfer = new Transfer(); $transfer->getFromDB($pfEntity->getValue('transfers_id_auto', $entities_id)); $item_to_transfer = array("Computer" => array($items_id => $items_id)); $transfer->moveItems($item_to_transfer, $entities_id, $transfer->fields); } else { $_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id']; $_SESSION['glpiactiveentities'] = array($computer->fields['entities_id']); $_SESSION['glpiactiveentities_string'] = $computer->fields['entities_id']; $_SESSION['glpiactive_entity'] = $computer->fields['entities_id']; $entities_id = $computer->fields['entities_id']; } } } $a_computerinventory = $pfFormatconvert->extraCollectInfo($a_computerinventory, $items_id); $a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id); $no_history = FALSE; // * New $setdynamic = 1; if ($items_id == '0') { $input = array(); $input['entities_id'] = $entities_id; PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input); if (isset($input['states_id'])) { $a_computerinventory['Computer']['states_id'] = $input['states_id']; } else { $a_computerinventory['Computer']['states_id'] = 0; } $items_id = $computer->add($input); $no_history = TRUE; $setdynamic = 0; } if (isset($_SESSION['plugin_fusioninventory_locations_id'])) { $a_computerinventory['Computer']['locations_id'] = $_SESSION['plugin_fusioninventory_locations_id']; unset($_SESSION['plugin_fusioninventory_locations_id']); } $serialized = gzcompress(serialize($a_computerinventory)); $a_computerinventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); if (!$PF_ESXINVENTORY) { $pfAgent->setAgentWithComputerid($items_id, $this->device_id, $entities_id); } $pfConfig = new PluginFusioninventoryConfig(); $query = "INSERT INTO `glpi_plugin_fusioninventory_dblockinventories`\n SET `value`='" . $items_id . "'"; $CFG_GLPI["use_log_in_files"] = FALSE; if (!$DB->query($query)) { $communication = new PluginFusioninventoryCommunication(); $communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n <REPLY>\n <ERROR>ERROR: SAME COMPUTER IS CURRENTLY UPDATED</ERROR>\n </REPLY>"); $communication->sendMessage($_SESSION['plugin_fusioninventory_compressmode']); exit; } $CFG_GLPI["use_log_in_files"] = TRUE; // * For benchs //$start = microtime(TRUE); PluginFusioninventoryInventoryComputerStat::increment(); $pfInventoryComputerLib->updateComputer($a_computerinventory, $items_id, $no_history, $setdynamic); $query = "DELETE FROM `glpi_plugin_fusioninventory_dblockinventories`\n WHERE `value`='" . $items_id . "'"; $DB->query($query); $plugin = new Plugin(); if ($plugin->isActivated('monitoring')) { Plugin::doOneHook("monitoring", "ReplayRulesForItem", array('Computer', $items_id)); } // * For benchs //Toolbox::logInFile("exetime", (microtime(TRUE) - $start)." (".$items_id.")\n". // memory_get_usage()."\n". // memory_get_usage(TRUE)."\n". // memory_get_peak_usage()."\n". // memory_get_peak_usage()."\n"); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'inventory'; $pfRulematchedlog->add($inputrulelog, array(), FALSE); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } // Write XML file if (!empty($PLUGIN_FUSIONINVENTORY_XML)) { PluginFusioninventoryToolbox::writeXML($items_id, $PLUGIN_FUSIONINVENTORY_XML->asXML(), 'computer'); } } else { if ($itemtype == 'PluginFusioninventoryUnmanaged') { $a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id); $class = new $itemtype(); if ($items_id == "0") { if ($entities_id == -1) { $entities_id = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; } $input = array(); $input['date_mod'] = date("Y-m-d H:i:s"); $items_id = $class->add($input); if (isset($_SESSION['plugin_fusioninventory_rules_id'])) { $pfRulematchedlog = new PluginFusioninventoryRulematchedlog(); $inputrulelog = array(); $inputrulelog['date'] = date('Y-m-d H:i:s'); $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id']; if (isset($_SESSION['plugin_fusioninventory_agents_id'])) { $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id']; } $inputrulelog['items_id'] = $items_id; $inputrulelog['itemtype'] = $itemtype; $inputrulelog['method'] = 'inventory'; $pfRulematchedlog->add($inputrulelog); $pfRulematchedlog->cleanOlddata($items_id, $itemtype); unset($_SESSION['plugin_fusioninventory_rules_id']); } } $class->getFromDB($items_id); $_SESSION["plugin_fusioninventory_entity"] = $class->fields['entities_id']; $input = array(); $input['id'] = $class->fields['id']; // Write XML file if (!empty($PLUGIN_FUSIONINVENTORY_XML)) { PluginFusioninventoryToolbox::writeXML($items_id, $PLUGIN_FUSIONINVENTORY_XML->asXML(), 'PluginFusioninventoryUnmanaged'); } if (isset($a_computerinventory['Computer']['name'])) { $input['name'] = $a_computerinventory['Computer']['name']; } $input['item_type'] = "Computer"; if (isset($a_computerinventory['Computer']['domains_id'])) { $input['domain'] = $a_computerinventory['Computer']['domains_id']; } if (isset($a_computerinventory['Computer']['serial'])) { $input['serial'] = $a_computerinventory['Computer']['serial']; } $class->update($input); } } }
/** * Import one device * * @param type $itemtype * @param type $items_id * * @return errors string to be alimented if import ko / '' if ok */ function importDevice($itemtype, $items_id, $a_inventory) { global $PLUGIN_FUSIONINVENTORY_XML; PluginFusioninventoryCommunication::addLog('Function PluginFusioninventoryCommunicationNetworkInventory->importDevice().'); $pfFormatconvert = new PluginFusioninventoryFormatconvert(); $a_inventory = $pfFormatconvert->replaceids($a_inventory); // Write XML file if (count($a_inventory) > 0) { $xml = $PLUGIN_FUSIONINVENTORY_XML->CONTENT->DEVICE[$_SESSION['plugin_fusioninventory_xmlnum']]->asXML(); PluginFusioninventoryToolbox::writeXML($items_id, $xml, $itemtype); // $folder = substr($items_id, 0, -1); // if (empty($folder)) { // $folder = '0'; // } // if (!file_exists(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder)) { // mkdir(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder, 0777, TRUE); // } // $fileopen = fopen(GLPI_PLUGIN_DOC_DIR."/fusioninventory/".$itemtype."/".$folder."/". // $items_id, 'w'); // fwrite($fileopen, print_r($a_inventory, TRUE)); // fclose($fileopen); } $errors = ''; $this->deviceId = $items_id; $serialized = gzcompress(serialize($a_inventory)); if (isset($a_inventory['name']) && $a_inventory['name'] == '') { unset($a_inventory['name']); } if (isset($a_inventory['serial']) && $a_inventory['serial'] == '') { unset($a_inventory['serial']); } switch ($itemtype) { case 'Printer': $pfiPrinterLib = new PluginFusioninventoryInventoryPrinterLib(); $a_inventory['PluginFusioninventoryPrinter']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $pfiPrinterLib->updatePrinter($a_inventory, $items_id); break; case 'NetworkEquipment': $pfiNetworkEquipmentLib = new PluginFusioninventoryInventoryNetworkEquipmentLib(); $a_inventory['PluginFusioninventoryNetworkEquipment']['serialized_inventory'] = Toolbox::addslashes_deep($serialized); $pfiNetworkEquipmentLib->updateNetworkEquipment($a_inventory, $items_id); break; default: $errors .= __('Unattended element in', 'fusioninventory') . ' TYPE : ' . $a_inventory['itemtype'] . "\n"; } }