PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Dataflow/Model/Session/Adapter/Http.php

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 87 lines | 36 code | 4 blank | 47 comment | 3 complexity | 6f3b7442403f2d17c462d0f6ebc6486f MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Dataflow
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Convert HTTP adapter
  28. *
  29. * @category Mage
  30. * @package Mage_Dataflow
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Dataflow_Model_Session_Adapter_Http extends Mage_Dataflow_Model_Convert_Adapter_Abstract
  34. {
  35. public function load()
  36. {
  37. if (!$_FILES) {
  38. ?>
  39. <form method="POST" enctype="multipart/form-data">
  40. File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
  41. </form>
  42. <?php
  43. exit;
  44. }
  45. if (!empty($_FILES['io_file']['tmp_name'])) {
  46. $uploader = new Mage_Core_Model_File_Uploader('io_file');
  47. $uploader->setAllowedExtensions(array('csv','xml'));
  48. $path = Mage::app()->getConfig()->getTempVarDir().'/import/';
  49. $uploader->save($path);
  50. if ($uploadFile = $uploader->getUploadedFileName()) {
  51. $session = Mage::getModel('dataflow/session');
  52. $session->setCreatedDate(date('Y-m-d H:i:s'));
  53. $session->setDirection('import');
  54. $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId());
  55. $session->save();
  56. $sessionId = $session->getId();
  57. $newFilename = 'import_'.$sessionId.'_'.$uploadFile;
  58. rename($path.$uploadFile, $path.$newFilename);
  59. $session->setFile($newFilename);
  60. $session->save();
  61. $this->setData(file_get_contents($path.$newFilename));
  62. Mage::register('current_dataflow_session_id', $sessionId);
  63. /*
  64. $read = @fopen($path.$newFilename, "r");
  65. if ($read) {
  66. $i = 0;
  67. while (!feof($read)) {
  68. $buffer = fgets($read, 4096);
  69. $import = Mage::getModel('dataflow/import');
  70. $import->setSerialNumber($i);
  71. $import->setSessionId($sessionId);
  72. $import->setSessionId($value);
  73. $i++;
  74. }
  75. fclose($read);
  76. }
  77. */
  78. }
  79. }
  80. return $this;
  81. }
  82. }