/** * Display a list of computers to add or to link * * @param plugin_ocsinventoryng_ocsservers_id the ID of the ocs server * @param advanced display detail about the computer import or not (target entity, matched rules, etc.) * @param check indicates if checkboxes are checked or not * @param start display a list of computers starting at rowX * @param entity a list of entities in which computers can be added or linked * @param tolinked false for an import, true for a link * * @return nothing **/ static function showComputersToAdd($serverId, $advanced, $check, $start, $entity = 0, $tolinked = false) { global $DB, $CFG_GLPI; if (!Session::haveRight("plugin_ocsinventoryng", UPDATE)) { return false; } $title = __('Import new computers', 'ocsinventoryng'); if ($tolinked) { $title = __('Link new OCSNG computers to existing GLPI computers', 'ocsinventoryng'); } $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.import.php'; if ($tolinked) { $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.link.php'; } // Get all links between glpi and OCS $query_glpi = "SELECT ocsid\n FROM `glpi_plugin_ocsinventoryng_ocslinks`\n WHERE `plugin_ocsinventoryng_ocsservers_id` = '{$serverId}'"; $result_glpi = $DB->query($query_glpi); $already_linked = array(); if ($DB->numrows($result_glpi) > 0) { while ($data = $DB->fetch_array($result_glpi)) { $already_linked[] = $data["ocsid"]; } } $cfg_ocs = self::getConfig($serverId); $computerOptions = array('OFFSET' => $start, 'MAX_RECORDS' => $_SESSION['glpilist_limit'], 'ORDER' => 'LASTDATE', 'FILTER' => array('EXCLUDE_IDS' => $already_linked), 'DISPLAY' => array('CHECKSUM' => PluginOcsinventoryngOcsClient::CHECKSUM_BIOS), 'ORDER' => 'NAME'); if ($cfg_ocs["tag_limit"] and $tag_limit = explode("\$", trim($cfg_ocs["tag_limit"]))) { $computerOptions['FILTER']['TAGS'] = $tag_limit; } if ($cfg_ocs["tag_exclude"] and $tag_exclude = explode("\$", trim($cfg_ocs["tag_exclude"]))) { $computerOptions['FILTER']['EXCLUDE_TAGS'] = $tag_exclude; } $ocsClient = self::getDBocs($serverId); $ocsResult = $ocsClient->getComputers($computerOptions); if (isset($ocsResult['COMPUTERS'])) { $computers = $ocsResult['COMPUTERS']; if (count($computers)) { // Get all hardware from OCS DB $hardware = array(); foreach ($computers as $data) { $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data)); $id = $data['META']['ID']; $hardware[$id]["date"] = $data['META']["LASTDATE"]; $hardware[$id]["name"] = $data['META']["NAME"]; $hardware[$id]["TAG"] = $data['META']["TAG"]; $hardware[$id]["id"] = $data['META']["ID"]; if (isset($data['BIOS']) && count($data['BIOS'])) { $hardware[$id]["serial"] = $data['BIOS']["SSN"]; $hardware[$id]["model"] = $data['BIOS']["SMODEL"]; $hardware[$id]["manufacturer"] = $data['BIOS']["SMANUFACTURER"]; } else { $hardware[$id]["serial"] = ''; $hardware[$id]["model"] = ''; $hardware[$id]["manufacturer"] = ''; } } if ($tolinked && count($hardware)) { echo "<div class='center b'>" . __('Caution! The imported data (see your configuration) will overwrite the existing one', 'ocsinventoryng') . "</div>"; } echo "<div class='center'>"; if ($numrows = $ocsResult['TOTAL_COUNT']) { $parameters = "check={$check}"; Html::printPager($start, $numrows, $target, $parameters); //Show preview form only in import even in multi-entity mode because computer import //can be refused by a rule if (!$tolinked) { echo "<div class='firstbloc'>"; echo "<form method='post' name='ocsng_import_mode' id='ocsng_import_mode'\n action='{$target}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Manual import mode', 'ocsinventoryng') . "</th></tr>\n"; echo "<tr class='tab_bg_1'><td class='center'>"; if ($advanced) { Html::showSimpleForm($target, 'change_import_mode', __('Disable preview', 'ocsinventoryng'), array('id' => 'false')); } else { Html::showSimpleForm($target, 'change_import_mode', __('Enable preview', 'ocsinventoryng'), array('id' => 'true')); } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td class='center b'>" . __('Check first that duplicates have been correctly managed in OCSNG', 'ocsinventoryng') . "</td>"; echo "</tr></table>"; Html::closeForm(); echo "</div>"; } echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>"; if (!$tolinked) { self::checkBox($target); } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">"; echo "</td></tr>\n"; echo "<tr><th>" . __('Name') . "</th>\n"; echo "<th>" . __('Manufacturer') . "</th>\n"; echo "<th>" . __('Model') . "</th>\n"; echo "<th>" . __('Serial number') . "</th>\n"; echo "<th>" . __('Date') . "</th>\n"; echo "<th>" . __('OCSNG TAG', 'ocsinventoryng') . "</th>\n"; if ($advanced && !$tolinked) { echo "<th>" . __('Match the rule ?', 'ocsinventoryng') . "</th>\n"; echo "<th>" . __('Destination entity') . "</th>\n"; echo "<th>" . __('Target location', 'ocsinventoryng') . "</th>\n"; } echo "<th width='20%'> </th></tr>\n"; $rule = new RuleImportEntityCollection(); foreach ($hardware as $ID => $tab) { $comp = new Computer(); $comp->fields["id"] = $tab["id"]; $data = array(); if ($advanced && !$tolinked) { $data = $rule->processAllRules(array('ocsservers_id' => $serverId, '_source' => 'ocsinventoryng'), array(), array('ocsid' => $tab["id"])); } echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n"; echo "<td>" . $tab["manufacturer"] . "</td><td>" . $tab["model"] . "</td>"; echo "<td>" . $tab["serial"] . "</td>\n"; echo "<td>" . Html::convDateTime($tab["date"]) . "</td>\n"; echo "<td>" . $tab["TAG"] . "</td>\n"; if ($advanced && !$tolinked) { if (!isset($data['entities_id']) || $data['entities_id'] == -1) { echo "<td class='center'><img src=\"" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png\"></td>\n"; $data['entities_id'] = -1; } else { echo "<td class='center'>"; $tmprule = new RuleImportEntity(); if ($tmprule->can($data['_ruleid'], READ)) { echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>"; } else { echo $tmprule->getName(); } echo "</td>\n"; } echo "<td width='30%'>"; $ent = "toimport_entities[" . $tab["id"] . "]"; Entity::dropdown(array('name' => $ent, 'value' => $data['entities_id'], 'comments' => 0)); echo "</td>\n"; echo "<td width='30%'>"; if (!isset($data['locations_id'])) { $data['locations_id'] = 0; } $loc = "toimport_locations[" . $tab["id"] . "]"; Location::dropdown(array('name' => $loc, 'value' => $data['locations_id'], 'comments' => 0)); echo "</td>\n"; } echo "<td>"; if (!$tolinked) { echo "<input type='checkbox' name='toimport[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . ">"; } else { $tab['entities_id'] = $entity; $rulelink = new RuleImportComputerCollection(); $rulelink_results = array(); $params = array('entities_id' => $entity, 'plugin_ocsinventoryng_ocsservers_id' => $serverId); $rulelink_results = $rulelink->processAllRules(Toolbox::stripslashes_deep($tab), array(), $params); //Look for the computer using automatic link criterias as defined in OCSNG configuration $options = array('name' => "tolink[" . $tab["id"] . "]"); $show_dropdown = true; //If the computer is not explicitly refused by a rule if (!isset($rulelink_results['action']) || $rulelink_results['action'] != self::LINK_RESULT_NO_IMPORT) { if (!empty($rulelink_results['found_computers'])) { $options['value'] = $rulelink_results['found_computers'][0]; $options['entity'] = $entity; } $options['width'] = "100%"; Computer::dropdown($options); } else { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>"; } } echo "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">\n"; echo "<input type=hidden name='plugin_ocsinventoryng_ocsservers_id' " . "value='{$serverId}'>"; echo "</td></tr>"; echo "</table>\n"; Html::closeForm(); if (!$tolinked) { self::checkBox($target); } Html::printPager($start, $numrows, $target, $parameters); } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $title . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table>"; } echo "</div>"; } else { echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $title . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table></div>"; } } else { echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $title . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table></div>"; } }
/** * @param $item CommonGLPI object * @param $tabnum (default 1) * @param $withtemplate (default 0) **/ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item->getType() == 'Entity') { $collection = new RuleRightCollection(); if ($collection->canList()) { $ldaprule = new RuleRight(); $ldaprule->showAndAddRuleForm($item); } $collection = new RuleImportEntityCollection(); if ($collection->canList()) { $importrule = new RuleImportEntity(); $importrule->showAndAddRuleForm($item); } $collection = new RuleMailCollectorCollection(); if ($collection->canList()) { $mailcollector = new RuleMailCollector(); $mailcollector->showAndAddRuleForm($item); } } else { if ($item->getType() == 'SLA') { $rule = new RuleTicket(); $rule->showAndAddRuleForm($item); } else { if ($item instanceof Rule) { $item->getRuleWithCriteriasAndActions($item->getID(), 1, 1); switch ($tabnum) { case 1: $item->showCriteriasList($item->getID()); break; case 2: $item->showActionsList($item->getID()); break; } } } } return true; }
/** * Display a list of computers to add or to link * * @param plugin_ocsinventoryng_ocsservers_id the ID of the ocs server * @param advanced display detail about the computer import or not (target entity, matched rules, etc.) * @param check indicates if checkboxes are checked or not * @param start display a list of computers starting at rowX * @param entity a list of entities in which computers can be added or linked * @param tolinked false for an import, true for a link * * @return nothing **/ static function showComputersToAdd($plugin_ocsinventoryng_ocsservers_id, $advanced, $check, $start, $entity = 0, $tolinked = false) { global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI; if (!plugin_ocsinventoryng_haveRight("ocsng", "w")) { return false; } $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.import.php'; if ($tolinked) { $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.link.php'; } $cfg_ocs = self::getConfig($plugin_ocsinventoryng_ocsservers_id); $WHERE = self::getTagLimit($cfg_ocs); $query_ocs = "SELECT `hardware`.*,\n `accountinfo`.`TAG` AS TAG,\n `bios`.`SSN` AS SERIAL,\n `bios`.`SMODEL`,\n `bios`.`SMANUFACTURER`\n FROM `hardware`\n INNER JOIN `accountinfo` ON (`hardware`.`id` = `accountinfo`.`HARDWARE_ID`)\n INNER JOIN `bios` ON (`hardware`.`id` = `bios`.`HARDWARE_ID`)" . (!empty($WHERE) ? "WHERE {$WHERE}" : "") . "\n ORDER BY `hardware`.`NAME`"; $result_ocs = $PluginOcsinventoryngDBocs->query($query_ocs); // Existing OCS - GLPI link $query_glpi = "SELECT*\n FROM `glpi_plugin_ocsinventoryng_ocslinks`\n WHERE `plugin_ocsinventoryng_ocsservers_id`\n = '{$plugin_ocsinventoryng_ocsservers_id}'"; $result_glpi = $DB->query($query_glpi); if ($PluginOcsinventoryngDBocs->numrows($result_ocs) > 0) { // Get all hardware from OCS DB $hardware = array(); while ($data = $PluginOcsinventoryngDBocs->fetch_array($result_ocs)) { $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data)); $hardware[$data["ID"]]["date"] = $data["LASTDATE"]; $hardware[$data["ID"]]["name"] = $data["NAME"]; $hardware[$data["ID"]]["TAG"] = $data["TAG"]; $hardware[$data["ID"]]["id"] = $data["ID"]; $hardware[$data["ID"]]["serial"] = $data["SERIAL"]; $hardware[$data["ID"]]["model"] = $data["SMODEL"]; $hardware[$data["ID"]]["manufacturer"] = $data["SMANUFACTURER"]; $query_network = "SELECT*\n FROM `networks`\n WHERE `HARDWARE_ID` = '" . $data["ID"] . "'"; //Get network informations for this computer //Ignore informations that contains "??" foreach ($PluginOcsinventoryngDBocs->request($query_network) as $network) { if (isset($network['IPADDRESS']) && $network['IPADDRESS'] != '??') { $hardware[$data["ID"]]['IPADDRESS'][] = $network['IPADDRESS']; } if (isset($network['IPSUBNET']) && $network['IPSUBNET'] != '??') { $hardware[$data["ID"]]['IPSUBNET'][] = $network['IPSUBNET']; } if (isset($network['MACADDRESS']) && $network['MACADDR'] != '??') { $hardware[$data["ID"]]['MACADDRESS'][] = $network['MACADDR']; } } } // Get all links between glpi and OCS $already_linked = array(); if ($DB->numrows($result_glpi) > 0) { while ($data = $PluginOcsinventoryngDBocs->fetch_array($result_glpi)) { $already_linked[$data["ocsid"]] = $data["last_update"]; } } // Clean $hardware from already linked element if (count($already_linked) > 0) { foreach ($already_linked as $ID => $date) { if (isset($hardware[$ID]) && isset($already_linked[$ID])) { unset($hardware[$ID]); } } } if ($tolinked && count($hardware)) { echo "<div class='center b'>" . __('Caution! The imported data (see your configuration) will overwrite the existing one', 'ocsinventoryng') . "</div>"; } echo "<div class='center'>"; if (($numrows = count($hardware)) > 0) { $parameters = "check={$check}"; Html::printPager($start, $numrows, $target, $parameters); // delete end array_splice($hardware, $start + $_SESSION['glpilist_limit']); // delete begin if ($start > 0) { array_splice($hardware, 0, $start); } //Show preview form only in import even in multi-entity mode because computer import //can be refused by a rule if (!$tolinked) { echo "<div class='firstbloc'>"; echo "<form method='post' name='ocsng_import_mode' id='ocsng_import_mode'\n action='{$target}'>\n"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Manual import mode', 'ocsinventoryng') . "</th></tr>\n"; echo "<tr class='tab_bg_1'><td class='center'>"; if ($advanced) { Html::showSimpleForm($target, 'change_import_mode', __('Disable preview', 'ocsinventoryng'), array('id' => 'false')); } else { Html::showSimpleForm($target, 'change_import_mode', __('Enable preview', 'ocsinventoryng'), array('id' => 'true')); } echo "</td></tr>"; echo "<tr class='tab_bg_1'><td class='center b'>" . __('Check first that duplicates have been correctly managed in OCSNG', 'ocsinventoryng') . "</td>"; echo "</tr></table>"; Html::closeForm(); echo "</div>"; } echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>"; if (!$tolinked) { self::checkBox($target); } echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">"; echo "</td></tr>\n"; echo "<tr><th>" . __('Name') . "</th>\n"; echo "<th>" . __('Manufacturer') . "</th>\n"; echo "<th>" . __('Model') . "</th>\n"; echo "<th>" . __('Serial number') . "</th>\n"; echo "<th>" . __('Date') . "</th>\n"; echo "<th>" . __('OCSNG TAG', 'ocsinventoryng') . "</th>\n"; if ($advanced && !$tolinked) { echo "<th>" . __('Match the rule ?', 'ocsinventoryng') . "</th>\n"; echo "<th>" . __('Destination entity') . "</th>\n"; echo "<th>" . __('Target location', 'ocsinventoryng') . "</th>\n"; } echo "<th> </th></tr>\n"; $rule = new RuleImportEntityCollection(); foreach ($hardware as $ID => $tab) { $comp = new Computer(); $comp->fields["id"] = $tab["id"]; $data = array(); if ($advanced && !$tolinked) { $data = $rule->processAllRules(array('ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id, '_source' => 'ocsinventoryng'), array(), array('ocsid' => $tab["id"])); } echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n"; echo "<td>" . $tab["manufacturer"] . "</td><td>" . $tab["model"] . "</td>"; echo "<td>" . $tab["serial"] . "</td>\n"; echo "<td>" . Html::convDateTime($tab["date"]) . "</td>\n"; echo "<td>" . $tab["TAG"] . "</td>\n"; if ($advanced && !$tolinked) { if (!isset($data['entities_id']) || $data['entities_id'] == -1) { echo "<td class='center'><img src=\"" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png\"></td>\n"; $data['entities_id'] = -1; } else { echo "<td class='center'>"; $tmprule = new RuleImportEntity(); if ($tmprule->can($data['_ruleid'], 'r')) { echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>"; } else { echo $tmprule->getName(); } echo "</td>\n"; } echo "<td>"; Entity::dropdown(array('name' => "toimport_entities[" . $tab["id"] . "]=" . $data['entities_id'], 'value' => $data['entities_id'], 'comments' => 0)); echo "</td>\n"; echo "<td>"; if (!isset($data['locations_id'])) { $data['locations_id'] = 0; } Location::dropdown(array('name' => "toimport_locations[" . $tab["id"] . "]=" . $data['locations_id'], 'value' => $data['locations_id'], 'comments' => 0)); echo "</td>\n"; } echo "<td>"; if (!$tolinked) { echo "<input type='checkbox' name='toimport[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . ">"; } else { $rulelink = new RuleImportComputerCollection(); $rulelink_results = array(); $params = array('entities_id' => $entity, 'plugin_ocsinventoryng_ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id); $rulelink_results = $rulelink->processAllRules(Toolbox::stripslashes_deep($tab), array(), $params); //Look for the computer using automatic link criterias as defined in OCSNG configuration $options = array('name' => "tolink[" . $tab["id"] . "]"); $show_dropdown = true; //If the computer is not explicitly refused by a rule if (!isset($rulelink_results['action']) || $rulelink_results['action'] != self::LINK_RESULT_NO_IMPORT) { if (!empty($rulelink_results['found_computers'])) { $options['value'] = $rulelink_results['found_computers'][0]; $options['entity'] = $entity; } Computer::dropdown($options); } else { echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>"; } } echo "</td></tr>\n"; } echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>"; echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">\n"; echo "<input type=hidden name='plugin_ocsinventoryng_ocsservers_id' " . "value='{$plugin_ocsinventoryng_ocsservers_id}'>"; echo "</td></tr>"; echo "</table>\n"; Html::closeForm(); if (!$tolinked) { self::checkBox($target); } Html::printPager($start, $numrows, $target, $parameters); } else { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Import new computers') . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table>"; } echo "</div>"; } else { echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Import new computers', 'ocsinventoryng') . "</th></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n"; echo "</table></div>"; } }
function plugin_ocsinventoryng_uninstall() { global $DB; $tables = array("glpi_plugin_ocsinventoryng_ocsservers", "glpi_plugin_ocsinventoryng_ocslinks", "glpi_plugin_ocsinventoryng_ocsadmininfoslinks", "glpi_plugin_ocsinventoryng_profiles", "glpi_plugin_ocsinventoryng_threads", "glpi_plugin_ocsinventoryng_servers", "glpi_plugin_ocsinventoryng_configs", "glpi_plugin_ocsinventoryng_notimportedcomputers", "glpi_plugin_ocsinventoryng_details", "glpi_plugin_ocsinventoryng_registrykeys", "glpi_plugin_ocsinventoryng_networkports", "glpi_plugin_ocsinventoryng_networkporttypes"); foreach ($tables as $table) { $DB->query("DROP TABLE IF EXISTS `{$table}`;"); } $tables_glpi = array("glpi_bookmarks", "glpi_displaypreferences", "glpi_documents_items", "glpi_logs", "glpi_tickets"); foreach ($tables_glpi as $table_glpi) { $DB->query("DELETE\n FROM `" . $table_glpi . "`\n WHERE `itemtype` IN ('PluginMassocsimportNotimported',\n 'PluginMassocsimportDetail',\n 'PluginOcsinventoryngOcsServer',\n 'PluginOcsinventoryngNotimportedcomputer',\n 'PluginOcsinventoryngDetail')"); } $query = "DELETE\n FROM `glpi_alerts`\n WHERE `itemtype` IN ('PluginMassocsimportNotimported',\n 'PluginOcsinventoryngNotimportedcomputer')"; $DB->queryOrDie($query, $DB->error()); // clean rules $rule = new RuleImportEntity(); foreach ($DB->request("glpi_rules", array('sub_type' => 'RuleImportEntity', 'name' => 'RootOcs')) as $data) { $rule->delete($data); } $notification = new Notification(); foreach (getAllDatasFromTable($notification->getTable(), "`itemtype` IN ('PluginMassocsimportNotimported',\n 'PluginOcsinventoryngNotimportedcomputer')") as $data) { $notification->delete($data); } $template = new NotificationTemplate(); foreach (getAllDatasFromTable($template->getTable(), "`itemtype` IN ('PluginMassocsimportNotimported',\n 'PluginOcsinventoryngNotimportedcomputer')") as $data) { $template->delete($data); } $cron = new CronTask(); if ($cron->getFromDBbyName('PluginMassocsimportThread', 'CleanOldThreads')) { // creation du cron - param = duree de conservation CronTask::Unregister('massocsimport'); } if ($cron->getFromDBbyName('PluginOcsinventoryngThread', 'CleanOldThreads')) { // creation du cron - param = duree de conservation CronTask::Unregister('ocsinventoryng'); } return true; }
/** * @return bool */ function plugin_ocsinventoryng_uninstall() { global $DB; include_once GLPI_ROOT . "/plugins/ocsinventoryng/inc/profile.class.php"; include_once GLPI_ROOT . "/plugins/ocsinventoryng/inc/menu.class.php"; $tables = array("glpi_plugin_ocsinventoryng_ocsservers", "glpi_plugin_ocsinventoryng_ocslinks", "glpi_plugin_ocsinventoryng_ocsadmininfoslinks", "glpi_plugin_ocsinventoryng_profiles", "glpi_plugin_ocsinventoryng_threads", "glpi_plugin_ocsinventoryng_snmpocslinks", "glpi_plugin_ocsinventoryng_ipdiscoverocslinks", "glpi_plugin_ocsinventoryng_servers", "glpi_plugin_ocsinventoryng_configs", "glpi_plugin_ocsinventoryng_notimportedcomputers", "glpi_plugin_ocsinventoryng_details", "glpi_plugin_ocsinventoryng_registrykeys", "glpi_plugin_ocsinventoryng_networkports", "glpi_plugin_ocsinventoryng_networkporttypes", "glpi_plugin_ocsinventoryng_ocsservers_profiles", "glpi_plugin_ocsinventoryng_devicebiosdatas", "glpi_plugin_ocsinventoryng_items_devicebiosdatas"); foreach ($tables as $table) { $DB->query("DROP TABLE IF EXISTS `{$table}`;"); } $tables_glpi = array("glpi_bookmarks", "glpi_displaypreferences", "glpi_logs"); foreach ($tables_glpi as $table_glpi) { $DB->query("DELETE\r\n FROM `" . $table_glpi . "`\r\n WHERE `itemtype` IN ('PluginMassocsimportNotimported',\r\n 'PluginMassocsimportDetail',\r\n 'PluginOcsinventoryngOcsServer',\r\n 'PluginOcsinventoryngNotimportedcomputer',\r\n 'PluginOcsinventoryngDetail')"); } $tables_ocs = array("ocs_glpi_crontasks", "ocs_glpi_displaypreferences", "ocs_glpi_ocsadmininfoslinks", "ocs_glpi_ocslinks", "ocs_glpi_ocsservers", "ocs_glpi_registrykeys", "ocs_glpi_profiles"); foreach ($tables_ocs as $table_ocs) { $DB->query("DROP TABLE IF EXISTS `{$table_ocs}`;"); } $tables_mass = array("backup_glpi_plugin_massocsimport_configs", "backup_glpi_plugin_massocsimport_details", "backup_glpi_plugin_massocsimport_notimported", "backup_glpi_plugin_massocsimport_servers", "backup_glpi_plugin_massocsimport_threads"); foreach ($tables_mass as $table_mass) { $DB->query("DROP TABLE IF EXISTS `{$table_mass}`;"); } $query = "DELETE\r\n FROM `glpi_alerts`\r\n WHERE `itemtype` IN ('PluginMassocsimportNotimported',\r\n 'PluginOcsinventoryngNotimportedcomputer')"; $DB->queryOrDie($query, $DB->error()); // clean rules $rule = new RuleImportEntity(); foreach ($DB->request("glpi_rules", array('sub_type' => 'RuleImportEntity')) as $data) { $rule->delete($data); } $rule = new RuleImportComputer(); foreach ($DB->request("glpi_rules", array('sub_type' => 'RuleImportComputer')) as $data) { $rule->delete($data); } $notification = new Notification(); foreach (getAllDatasFromTable($notification->getTable(), "`itemtype` IN ('PluginMassocsimportNotimported',\r\n 'PluginOcsinventoryngNotimportedcomputer')") as $data) { $notification->delete($data); } $template = new NotificationTemplate(); foreach (getAllDatasFromTable($template->getTable(), "`itemtype` IN ('PluginMassocsimportNotimported',\r\n 'PluginOcsinventoryngNotimportedcomputer')") as $data) { $template->delete($data); } $cron = new CronTask(); if ($cron->getFromDBbyName('PluginMassocsimportThread', 'CleanOldThreads')) { CronTask::Unregister('massocsimport'); CronTask::Unregister('CleanOldThreads'); } if ($cron->getFromDBbyName('PluginOcsinventoryngOcsServer', 'ocsng')) { CronTask::Unregister('ocsinventoryng'); CronTask::Unregister('ocsng'); } if ($cron->getFromDBbyName('PluginOcsinventoryngNotimportedcomputer', 'SendAlerts')) { CronTask::Unregister('SendAlerts'); } if ($cron->getFromDBbyName('PluginOcsinventoryngOcsServer', 'CleanOldAgents')) { CronTask::Unregister('CleanOldAgents'); } //Delete rights associated with the plugin $profileRight = new ProfileRight(); foreach (PluginOcsinventoryngProfile::getAllRights() as $right) { $profileRight->deleteByCriteria(array('name' => $right['field'])); } PluginOcsinventoryngMenu::removeRightsFromSession(); PluginOcsinventoryngProfile::removeRightsFromSession(); return true; }