PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/magmi/web_1/magmi_run.php

https://bitbucket.org/jit_bec/shopifine
PHP | 92 lines | 81 code | 11 blank | 0 comment | 7 complexity | 7361662bdf10b89ffef94257fe7b8801 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. $params=$_REQUEST;
  3. ini_set("display_errors",1);
  4. require_once("../inc/magmi_defs.php");
  5. require_once("../inc/magmi_statemanager.php");
  6. try
  7. {
  8. $engdef=explode(":",$params["engine"]);
  9. $engine_name=$engdef[0];
  10. $engine_class=$engdef[1];
  11. require_once("../engines/$engine_name.php");
  12. }
  13. catch(Exception $e)
  14. {
  15. die("ERROR");
  16. }
  17. class FileLogger
  18. {
  19. protected $_fname;
  20. public function __construct($fname)
  21. {
  22. $this->_fname=$fname;
  23. $f=fopen($this->_fname,"w");
  24. if($f==false)
  25. {
  26. throw new Exception("CANNOT WRITE PROGRESS FILE ");
  27. }
  28. fclose($f);
  29. }
  30. public function log($data,$type)
  31. {
  32. $f=fopen($this->_fname,"a");
  33. if($f==false)
  34. {
  35. throw new Exception("CANNOT WRITE PROGRESS FILE ");
  36. }
  37. $data=preg_replace ("/(\r|\n|\r\n)/", "<br>", $data);
  38. fwrite($f,"$type:$data\n");
  39. fclose($f);
  40. }
  41. }
  42. class EchoLogger
  43. {
  44. public function log($data,$type)
  45. {
  46. $info=explode(";",$type);
  47. $type=$info[0];
  48. echo('<p class="logentry log_'.$type.'">'.$data."</p>");
  49. }
  50. }
  51. if(Magmi_StateManager::getState()!=="running")
  52. {
  53. Magmi_StateManager::setState("idle");
  54. $pf=Magmi_StateManager::getProgressFile(true);
  55. if(file_exists($pf))
  56. {
  57. @unlink($pf);
  58. }
  59. set_time_limit(0);
  60. $mmi_imp=new $engine_class();
  61. $logfile=isset($params["logfile"])?$params["logfile"]:null;
  62. if(isset($logfile) && $logfile!="")
  63. {
  64. $fname=Magmi_StateManager::getStateDir().DS.$logfile;
  65. if(file_exists($fname))
  66. {
  67. @unlink($fname);
  68. }
  69. $mmi_imp->setLogger(new FileLogger($fname));
  70. }
  71. else
  72. {
  73. $mmi_imp->setLogger(new EchoLogger());
  74. }
  75. $mmi_imp->run($params);
  76. }
  77. else
  78. {
  79. die("RUNNING");
  80. }
  81. ?>