function extraCollectInfo($a_inventory, $computers_id) { global $DB; $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); // Get data from rules / collect registry, wmi, find files $data_collect = array(); $data_registries = getAllDatasFromTable('glpi_plugin_fusioninventory_collects_registries_contents', "`computers_id`='" . $computers_id . "'"); foreach ($data_registries as $data) { $res_rule = $pfCollectRuleCollection->processAllRules(array("regkey" => $data['key'], "regvalue" => $data['value'])); if (!isset($res_rule['_no_rule_matches'])) { $data_collect[] = $res_rule; } } $data_wmis = getAllDatasFromTable('glpi_plugin_fusioninventory_collects_wmis_contents', "`computers_id`='" . $computers_id . "'"); foreach ($data_wmis as $data) { $res_rule = $pfCollectRuleCollection->processAllRules(array("wmiproperty" => $data['property'], "wmivalue" => $data['value'])); if (!isset($res_rule['_no_rule_matches'])) { $data_collect[] = $res_rule; } } $data_files = getAllDatasFromTable('glpi_plugin_fusioninventory_collects_files_contents', "`computers_id`='" . $computers_id . "'"); foreach ($data_files as $data) { $a_split = explode("/", $data['pathfile']); $filename = array_pop($a_split); $path = implode("/", $a_split); $res_rule = $pfCollectRuleCollection->processAllRules(array("filename" => $filename, "filepath" => $path, "size" => $data['size'])); if (!isset($res_rule['_no_rule_matches'])) { $data_collect[] = $res_rule; } } // * Update $a_inventory with $data_collect; foreach ($data_collect as $data) { // Update computer model if (isset($data['computermodels_id'])) { $a_inventory['Computer']['computermodels_id'] = $data['computermodels_id']; } // Update computer type if (isset($data['computertypes_id'])) { $a_inventory['Computer']['computertypes_id'] = $data['computertypes_id']; } // Update computer OS if (isset($data['operatingsystems_id'])) { $a_inventory['Computer']['operatingsystems_id'] = $data['operatingsystems_id']; } // Update computer OS version if (isset($data['operatingsystemversions_id'])) { $a_inventory['Computer']['operatingsystemversions_id'] = $data['operatingsystemversions_id']; } // Update computer user if (isset($data['user'])) { $query = "SELECT `id`\n FROM `glpi_users`\n WHERE `name` = '" . $data['user'] . "'\n LIMIT 1"; $result = $DB->query($query); if ($DB->numrows($result) == 1) { $a_inventory['Computer']['users_id'] = $DB->result($result, 0, 0); } } // Update computer location if (isset($data['locations_id'])) { $a_inventory['Computer']['locations_id'] = $data['locations_id']; } // Update computer status if (isset($data['states_id'])) { $a_inventory['Computer']['states_id'] = $data['states_id']; } // Add software if (isset($data['software']) && isset($data['softwareversion'])) { $a_inventory['SOFTWARES'][] = array('NAME' => $data['software'], 'VERSION' => $data['softwareversion']); } // Update computer inventory number if (isset($data['otherserial'])) { $a_inventory['Computer']['otherserial'] = $data['otherserial']; } } return $a_inventory; }
/** * @test */ public function getOtherserialAssign() { global $DB; $DB->connect(); $_SESSION['glpiactive_entity'] = 0; $_SESSION["plugin_fusioninventory_entity"] = 0; $_SESSION["glpiname"] = 'Plugin_FusionInventory'; $pfCollectRuleCollection = new PluginFusioninventoryCollectRuleCollection(); $res_rule = $pfCollectRuleCollection->processAllRules(array("filename" => 'serial clic', "filepath" => '/tmp', "size" => 1000)); $this->assertEquals('ttuujj', $res_rule['otherserial']); }