/** * @param $model PluginDatainjectionModel object * @param $entities_id **/ static function processInjection(PluginDatainjectionModel $model, $entities_id) { global $CFG_GLPI; // To prevent problem of execution time during injection ini_set("max_execution_time", "0"); // Disable recording each SQL request in $_SESSION $CFG_GLPI["debug_sql"] = 0; $nblines = PluginDatainjectionSession::getParam('nblines'); $clientinjection = new PluginDatainjectionClientInjection(); //New injection engine $engine = new PluginDatainjectionEngine($model, PluginDatainjectionSession::getParam('infos'), $entities_id); $backend = $model->getBackend(); $model->loadSpecificModel(); //Open CSV file $backend->openFile(); $index = 0; //Read CSV file $line = $backend->getNextLine(); //If header is present, then get the second line if ($model->getSpecificModel()->isHeaderPresent()) { $line = $backend->getNextLine(); } //While CSV file is not EOF $prev = ''; $deb = time(); while ($line != null) { //Inject line $injectionline = $index + ($model->getSpecificModel()->isHeaderPresent() ? 2 : 1); $clientinjection->results[] = $engine->injectLine($line[0], $injectionline); $pos = number_format($index * 100 / $nblines, 1); if ($pos != $prev) { $prev = $pos; $fin = time() - $deb; //TODO yllen Html::changeProgressBarPosition($index, $nblines, sprintf(__('%1$s (%2$s)'), sprintf(__('Injection of the file... %d%%', 'datainjection'), $pos), Html::timestampToString(time() - $deb, true))); } $line = $backend->getNextLine(); $index++; } //EOF : change progressbar to 100% ! Html::changeProgressBarPosition(100, 100, sprintf(__('%1$s (%2$s)'), __('Injection finished', 'datainjection'), Html::timestampToString(time() - $deb, true))); // Restore $CFG_GLPI["debug_sql"] = 1; //Close CSV file $backend->closeFile(); //Delete CSV file $backend->deleteFile(); //Change step $_SESSION['datainjection']['step'] = self::STEP_RESULT; //Display results form PluginDatainjectionSession::setParam('results', json_encode($clientinjection->results)); PluginDatainjectionSession::setParam('error_lines', json_encode($engine->getLinesInError())); $p['models_id'] = $model->fields['id']; $p['nblines'] = $nblines; unset($_SESSION['datainjection']['go']); $_SESSION["MESSAGE_AFTER_REDIRECT"] = ""; $url = $CFG_GLPI["root_doc"] . "/plugins/datainjection/ajax/results.php"; Ajax::updateItem("span_injection", $url, $p); }