예제 #1
0
 /**
  * Merge softwares with current
  *
  * @param $item array of software ID to be merged
  *
  * @return boolean about success
  **/
 function merge($item)
 {
     global $DB, $LANG;
     $ID = $this->getField('id');
     echo "<div class='center'>";
     echo "<table class='tab_cadrehov'><tr><th>" . $LANG['software'][47] . "</th></tr>";
     echo "<tr class='tab_bg_2'><td>";
     createProgressBar($LANG['rulesengine'][90]);
     echo "</td></tr></table></div>\n";
     $item = array_keys($item);
     // Search for software version
     $req = $DB->request("glpi_softwareversions", array("softwares_id" => $item));
     $i = 0;
     if ($nb = $req->numrows()) {
         foreach ($req as $from) {
             $found = false;
             foreach ($DB->request("glpi_softwareversions", array("softwares_id" => $ID, "name" => $from["name"])) as $dest) {
                 // Update version ID on License
                 $sql = "UPDATE `glpi_softwarelicenses`\n                       SET `softwareversions_id_buy` = '" . $dest["id"] . "'\n                       WHERE `softwareversions_id_buy` = '" . $from["id"] . "'";
                 $DB->query($sql);
                 $sql = "UPDATE `glpi_softwarelicenses`\n                       SET `softwareversions_id_use` = '" . $dest["id"] . "'\n                       WHERE `softwareversions_id_use` = '" . $from["id"] . "'";
                 $DB->query($sql);
                 // Move installation to existing version in destination software
                 $sql = "UPDATE `glpi_computers_softwareversions`\n                       SET `softwareversions_id` = '" . $dest["id"] . "'\n                       WHERE `softwareversions_id` = '" . $from["id"] . "'";
                 $found = $DB->query($sql);
             }
             if ($found) {
                 // Installation has be moved, delete the source version
                 $sql = "DELETE\n                       FROM `glpi_softwareversions`\n                       WHERE `id` = '" . $from["id"] . "'";
             } else {
                 // Move version to destination software
                 $sql = "UPDATE `glpi_softwareversions`\n                       SET `softwares_id` = '{$ID}',\n                           `entities_id` = '" . $this->getField('entities_id') . "'\n                       WHERE `id` = '" . $from["id"] . "'";
             }
             if ($DB->query($sql)) {
                 $i++;
             }
             changeProgressBarPosition($i, $nb + 1);
         }
     }
     // Move software license
     $sql = "UPDATE `glpi_softwarelicenses`\n              SET `softwares_id` = '{$ID}'\n              WHERE `softwares_id` IN ('" . implode("','", $item) . "')";
     if ($DB->query($sql)) {
         $i++;
     }
     if ($i == $nb + 1) {
         //error_log ("All merge operations ok.");
         $soft = new self();
         foreach ($item as $old) {
             $soft->putInTrash($old, $LANG['software'][49]);
         }
     }
     changeProgressBarPosition($i, $nb + 1, $LANG['rulesengine'][91]);
     return $i == $nb + 1;
 }
예제 #2
0
 // Current time
 $start = explode(" ", microtime());
 $start = $start[0] + $start[1];
 // Limit computed from current time
 $max = get_cfg_var("max_execution_time");
 $max = $start + ($max > 0 ? $max / 2.0 : 30.0);
 commonHeader($LANG['rulesengine'][17], $_SERVER['PHP_SELF'], "admin", $rulecollection->menu_type, $rulecollection->menu_option);
 if (!(isset($_POST['replay_confirm']) || isset($_GET['offset'])) && $rulecollection->warningBeforeReplayRulesOnExistingDB($_SERVER['PHP_SELF'])) {
     commonFooter();
     exit;
 }
 echo "<table class='tab_cadrehov'>";
 echo "<tr><th><div class='relative'><strong>" . $rulecollection->getTitle() . "</strong>";
 echo " - " . $LANG['rulesengine'][76] . "</th></tr>\n";
 echo "<tr><td class='center'>";
 createProgressBar($LANG['rulesengine'][90]);
 echo "</td></tr>\n";
 echo "</table>";
 if (!isset($_GET['offset'])) {
     // First run
     $offset = $rulecollection->replayRulesOnExistingDB(0, $max, array(), $_POST);
     $manufacturer = isset($_POST["manufacturer"]) ? $_POST["manufacturer"] : 0;
 } else {
     // Next run
     $offset = $rulecollection->replayRulesOnExistingDB($_GET['offset'], $max, array(), $_GET);
     $manufacturer = $_GET["manufacturer"];
     // global start for stat
     $start = $_GET["start"];
 }
 if ($offset < 0) {
     // Work ended
 function ConvertField($force = 0)
 {
     include GLPI_ROOT . "/plugins/fusioninventory/inc_constants/snmp.mapping.constant.php";
     global $DB, $LANG;
     $constantsfield = array();
     foreach ($FUSIONINVENTORY_MAPPING[NETWORKING_TYPE] as $fieldtype => $array) {
         $constantsfield[$FUSIONINVENTORY_MAPPING[NETWORKING_TYPE][$fieldtype]['name']] = $fieldtype;
     }
     echo "<center><table align='center' width='500'>";
     echo "<tr>";
     echo "<td>";
     echo "Converting history port ...";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>";
     createProgressBar("Update Ports history");
     $query = "SELECT *\n                FROM " . $this->table . "\n                WHERE `Field` != '0';";
     if ($result = $DB->query($query)) {
         $nb = $DB->numrows($result);
         if ($nb > 300000 and $force == '0') {
             echo $LANG['plugin_fusioninventory']["update"][0] . "<br/>";
             echo "cd glpi/plugins/fusioninventory/front/ && php -f cli_update.php";
             echo "<br/>Waiting...";
             file_put_contents(GLPI_PLUGIN_DOC_DIR . "/fusioninventory/cli-update.txt", "1");
             sleep(20);
             return;
         }
         $i = 0;
         while ($data = $DB->fetch_array($result)) {
             $i++;
             if (isset($constantsfield[$data['Field']])) {
                 $data['Field'] = $constantsfield[$data['Field']];
                 $query_update = "UPDATE `" . $this->table . "`\n                  SET `Field`='" . $data['Field'] . "'\n                  WHERE `ID`='" . $data['ID'] . "' ";
                 $DB->query($query_update);
                 if (preg_match("/000\$/", $i)) {
                     changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
                 }
             }
         }
     }
     changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
     echo "</td>";
     echo "</tr>";
     echo "</table></center>";
     // Move connections from glpi_plugin_fusioninventory_snmphistories to glpi_plugin_fusioninventory_snmphistoryconnections
     $pfihc = new PluginFusioninventorySnmphistoryconnection();
     echo "<br/><center><table align='center' width='500'>";
     echo "<tr>";
     echo "<td>";
     echo "Moving creation connections history ...";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>";
     createProgressBar("Move create connections");
     $query = "SELECT *\n                FROM " . $this->table . "\n                WHERE `Field` = '0' \n                  AND ((`old_value` NOT LIKE '%:%')\n                        OR (`old_value` IS NULL))";
     if ($result = $DB->query($query)) {
         $nb = $DB->numrows($result);
         $i = 0;
         changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
         while ($data = $DB->fetch_array($result)) {
             $i++;
             // Search port from mac address
             $query_port = "SELECT * FROM `glpi_networking_ports`\n               WHERE `ifmac`='" . $data['new_value'] . "' ";
             if ($result_port = $DB->query($query_port)) {
                 if ($DB->numrows($result_port) == '1') {
                     $input = array();
                     $data_port = $DB->fetch_assoc($result_port);
                     $input['FK_port_source'] = $data_port['ID'];
                     $query_port2 = "SELECT * FROM `glpi_networking_ports`\n                     WHERE `on_device` = '" . $data['new_device_ID'] . "'\n                        AND `device_type` = '" . $data['new_device_type'] . "' ";
                     if ($result_port2 = $DB->query($query_port2)) {
                         if ($DB->numrows($result_port2) == '1') {
                             $data_port2 = $DB->fetch_assoc($result_port2);
                             $input['FK_port_destination'] = $data_port2['ID'];
                             $input['date'] = $data['date_mod'];
                             $input['creation'] = 1;
                             $input['process_number'] = $data['FK_process'];
                             $pfihc->add($input);
                         }
                     }
                 }
             }
             $query_delete = "DELETE FROM `" . $this->table . "`\n                  WHERE `ID`='" . $data['ID'] . "' ";
             $DB->query($query_delete);
             if (preg_match("/00\$/", $i)) {
                 changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
             }
         }
     }
     changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
     echo "</td>";
     echo "</tr>";
     echo "</table></center>";
     echo "<br/><center><table align='center' width='500'>";
     echo "<tr>";
     echo "<td>";
     echo "Moving deleted connections history ...";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>";
     createProgressBar("Move delete connections");
     $query = "SELECT *\n                FROM " . $this->table . "\n                WHERE `Field` = '0'\n                  AND ((`new_value` NOT LIKE '%:%')\n                        OR (`new_value` IS NULL))";
     if ($result = $DB->query($query)) {
         $nb = $DB->numrows($result);
         $i = 0;
         changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
         while ($data = $DB->fetch_array($result)) {
             $i++;
             // Search port from mac address
             $query_port = "SELECT * FROM `glpi_networking_ports`\n               WHERE `ifmac`='" . $data['old_value'] . "' ";
             if ($result_port = $DB->query($query_port)) {
                 if ($DB->numrows($result_port) == '1') {
                     $input = array();
                     $data_port = $DB->fetch_assoc($result_port);
                     $input['FK_port_source'] = $data_port['ID'];
                     $query_port2 = "SELECT * FROM `glpi_networking_ports`\n                     WHERE `on_device` = '" . $data['old_device_ID'] . "'\n                        AND `device_type` = '" . $data['old_device_type'] . "' ";
                     if ($result_port2 = $DB->query($query_port2)) {
                         if ($DB->numrows($result_port2) == '1') {
                             $data_port2 = $DB->fetch_assoc($result_port2);
                             $input['FK_port_destination'] = $data_port2['ID'];
                             $input['date'] = $data['date_mod'];
                             $input['creation'] = 1;
                             $input['process_number'] = $data['FK_process'];
                             if ($input['FK_port_source'] != $input['FK_port_destination']) {
                                 $pfihc->add($input);
                             }
                         }
                     }
                 }
             }
             $query_delete = "DELETE FROM `" . $this->table . "`\n                  WHERE `ID`='" . $data['ID'] . "' ";
             $DB->query($query_delete);
             if (preg_match("/00\$/", $i)) {
                 changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
             }
         }
     }
     changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
     echo "</td>";
     echo "</tr>";
     echo "</table></center>";
 }