require_once "../inc/magmi_statemanager.php"; try { $engdef = explode(":", $params["engine"]); $engine_name = $engdef[0]; $engine_class = $engdef[1]; require_once "../engines/{$engine_name}.php"; } catch (Exception $e) { die("ERROR"); } if (Magmi_StateManager::getState() !== "running") { Magmi_StateManager::setState("idle"); $pf = Magmi_StateManager::getProgressFile(true); if (file_exists($pf)) { @unlink($pf); } set_time_limit(0); $mmi_imp = new $engine_class(); $logfile = isset($params["logfile"]) ? $params["logfile"] : null; if (isset($logfile) && $logfile != "") { $fname = Magmi_StateManager::getStateDir() . DIRSEP . $logfile; if (file_exists($fname)) { @unlink($fname); } $mmi_imp->setLogger(new FileLogger($fname)); } else { $mmi_imp->setLogger(new EchoLogger()); } $mmi_imp->run($params); } else { die("RUNNING"); }
<?php require_once "../inc/magmi_statemanager.php"; require_once "progress_parser.php"; $logfile = $_REQUEST["logfile"]; if (!isset($logfile)) { $logfile = Magmi_StateManager::getProgressFile(); } $logfile = Magmi_StateManager::getStateDir() . DS . $logfile; if (file_exists($logfile)) { $parser = new DefaultProgressParser(); $parser->setFile($logfile); $parser->parse(); $count = $parser->getData("itime:count"); if ($count) { $lu = $parser->getData("lookup"); $percent = round((double) $count * 100 / $lu["nlines"], 2); $stepd = $parser->getData("step"); $step = $stepd["value"]; } else { $percent = 0; } $errors = $parser->getData("error"); $warnings = $parser->getData("warning"); //session_start(); $_SESSION["log_error"] = $errors; $_SESSION["log_warning"] = $warnings; session_write_close(); } else { die("NO FILE"); }
public function engineRun($params, $forcebuiltin = array()) { $this->log("Import Profile:{$this->_profile}", "startup"); $this->log("Import Mode:{$this->mode}", "startup"); $this->log("step:" . $this->getProp("GLOBAL", "step", 0.5) . "%", "step"); $this->createPlugins($this->_profile, $params); $this->datasource = $this->getDataSource(); $this->callPlugins("datasources,general", "beforeImport"); $nitems = $this->lookup(); Magmi_StateManager::setState("running"); // if some rows found if ($nitems > 0) { // initializing product type early (in case of db update on startImport) $this->initProdType(); $this->resetSkuStats(); // intialize store id cache $this->callPlugins("datasources,itemprocessors", "startImport"); // initializing item processors $cols = $this->datasource->getColumnNames(); $this->log(count($cols), "columns"); $this->callPlugins("itemprocessors", "processColumnList", $cols); if (count($cols) < 2) { $this->log("Invalid input data , not enough columns found,check datasource parameters", "error"); $this->log("Import Ended", "end"); Magmi_StateManager::setState("idle"); return; } $this->log("Ajusted processed columns:" . count($cols), "startup"); // initialize attribute infos & indexes from column names if ($this->mode != "update") { $this->checkRequired($cols); } $this->initAttrInfos(array_values($cols)); // counter $this->_current_row = 0; // start time $tstart = microtime(true); // differential $tdiff = $tstart; // intermediary report step $this->initDbqStats(); $pstep = $this->getProp("GLOBAL", "step", 0.5); $rstep = ceil($nitems * $pstep / 100); // read each line $lastrec = 0; $lastdbtime = 0; while (($item = $this->datasource->getNextRecord()) !== false) { $this->_timecounter->initTimingCats(array("line")); $res = $this->processDataSourceLine($item, $rstep, $tstart, $tdiff, $lastdbtime, $lastrec); // break on "forced" last if ($res["last"] == 1) { $this->log("last item encountered", "info"); break; } } $this->callPlugins("datasources,general,itemprocessors", "endImport"); $this->reportStats($this->_current_row, $tstart, $tdiff, $lastdbtime, $lastrec); $this->log("Skus imported OK:" . $this->_skustats["ok"] . "/" . $this->_skustats["nsku"], "info"); if ($this->_skustats["ko"] > 0) { $this->log("Skus imported KO:" . $this->_skustats["ko"] . "/" . $this->_skustats["nsku"], "warning"); } } else { $this->log("No Records returned by datasource", "warning"); } $this->callPlugins("datasources,general,itemprocessors", "afterImport"); $this->log("Import Ended", "end"); Magmi_StateManager::setState("idle"); $timers = $this->_timecounter->getTimers(); $f = fopen(Magmi_StateManager::getStateDir() . "/timings.txt", "w"); foreach ($timers as $cat => $info) { $rep = "\nTIMING CATEGORY:{$cat}\n--------------------------------"; foreach ($info as $phase => $pinfo) { $rep .= "\nPhase:{$phase}\n"; foreach ($pinfo as $plugin => $data) { $rdur = round($data["dur"], 4); if ($rdur > 0) { $rep .= "- Class:{$plugin} :{$rdur} "; } } } fwrite($f, $rep); } fclose($f); }