PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 2ms app.codeStats 0ms

/app/code/core/Mage/Dataflow/Model/Batch.php

https://github.com/FiveDigital/magento2
PHP | 211 lines | 82 code | 17 blank | 112 comment | 7 complexity | 00988303beb7725f156f80340e288a8d MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  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@magentocommerce.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.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Dataflow
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Dataflow Batch model
  28. *
  29. * @method Mage_Dataflow_Model_Resource_Batch _getResource()
  30. * @method Mage_Dataflow_Model_Resource_Batch getResource()
  31. * @method int getProfileId()
  32. * @method Mage_Dataflow_Model_Batch setProfileId(int $value)
  33. * @method int getStoreId()
  34. * @method Mage_Dataflow_Model_Batch setStoreId(int $value)
  35. * @method string getAdapter()
  36. * @method Mage_Dataflow_Model_Batch setAdapter(string $value)
  37. * @method string getCreatedAt()
  38. * @method Mage_Dataflow_Model_Batch setCreatedAt(string $value)
  39. *
  40. * @category Mage
  41. * @package Mage_Dataflow
  42. * @author Magento Core Team <core@magentocommerce.com>
  43. */
  44. class Mage_Dataflow_Model_Batch extends Mage_Core_Model_Abstract
  45. {
  46. /**
  47. * Lifetime abandoned batches
  48. *
  49. */
  50. const LIFETIME = 86400;
  51. /**
  52. * Field list collection array
  53. *
  54. * @var array
  55. */
  56. protected $_fieldList = array();
  57. /**
  58. * Dataflow batch io adapter
  59. *
  60. * @var Mage_Dataflow_Model_Batch_Io
  61. */
  62. protected $_ioAdapter;
  63. /**
  64. * Dataflow batch export model
  65. *
  66. * @var Mage_Dataflow_Model_Batch_Export
  67. */
  68. protected $_batchExport;
  69. /**
  70. * Dataflow batch import model
  71. *
  72. * @var Mage_Dataflow_Model_Batch_Import
  73. */
  74. protected $_batchImport;
  75. /**
  76. * Init model
  77. *
  78. */
  79. protected function _construct()
  80. {
  81. $this->_init('Mage_Dataflow_Model_Resource_Batch');
  82. }
  83. /**
  84. * Retrieve prepared field list
  85. *
  86. * @return array
  87. */
  88. public function getFieldList()
  89. {
  90. return $this->_fieldList;
  91. }
  92. /**
  93. * Parse row fields
  94. *
  95. * @param array $row
  96. */
  97. public function parseFieldList($row)
  98. {
  99. foreach ($row as $fieldName => $value) {
  100. if (!in_array($fieldName, $this->_fieldList)) {
  101. $this->_fieldList[$fieldName] = $fieldName;
  102. }
  103. }
  104. unset($fieldName, $value, $row);
  105. }
  106. /**
  107. * Retrieve Io Adapter
  108. *
  109. * @return Mage_Dataflow_Model_Batch_Io
  110. */
  111. public function getIoAdapter()
  112. {
  113. if (is_null($this->_ioAdapter)) {
  114. $this->_ioAdapter = Mage::getModel('Mage_Dataflow_Model_Batch_Io');
  115. $this->_ioAdapter->init($this);
  116. }
  117. return $this->_ioAdapter;
  118. }
  119. protected function _beforeSave()
  120. {
  121. if (is_null($this->getData('created_at'))) {
  122. $this->setData('created_at', Mage::getSingleton('Mage_Core_Model_Date')->gmtDate());
  123. }
  124. }
  125. protected function _afterDelete()
  126. {
  127. $this->getIoAdapter()->clear();
  128. }
  129. /**
  130. * Retrieve Batch export model
  131. *
  132. * @return Mage_Dataflow_Model_Batch_Export
  133. */
  134. public function getBatchExportModel()
  135. {
  136. if (is_null($this->_batchExport)) {
  137. $object = Mage::getModel('Mage_Dataflow_Model_Batch_Export');
  138. $object->setBatchId($this->getId());
  139. $this->_batchExport = Varien_Object_Cache::singleton()->save($object);
  140. }
  141. return Varien_Object_Cache::singleton()->load($this->_batchExport);
  142. }
  143. /**
  144. * Retrieve Batch import model
  145. *
  146. * @return Mage_Dataflow_Model_Import_Export
  147. */
  148. public function getBatchImportModel()
  149. {
  150. if (is_null($this->_batchImport)) {
  151. $object = Mage::getModel('Mage_Dataflow_Model_Batch_Import');
  152. $object->setBatchId($this->getId());
  153. $this->_batchImport = Varien_Object_Cache::singleton()->save($object);
  154. }
  155. return Varien_Object_Cache::singleton()->load($this->_batchImport);
  156. }
  157. /**
  158. * Run finish actions for Adapter
  159. *
  160. */
  161. public function beforeFinish()
  162. {
  163. if ($this->getAdapter()) {
  164. $adapter = Mage::getModel($this->getAdapter());
  165. if (method_exists($adapter, 'finish')) {
  166. $adapter->finish();
  167. }
  168. }
  169. }
  170. /**
  171. * Set additional params
  172. * automatic convert to serialize data
  173. *
  174. * @param mixed $data
  175. * @return Mage_Dataflow_Model_Batch_Abstract
  176. */
  177. public function setParams($data)
  178. {
  179. $this->setData('params', serialize($data));
  180. return $this;
  181. }
  182. /**
  183. * Retrieve additional params
  184. * return unserialize data
  185. *
  186. * @return mixed
  187. */
  188. public function getParams()
  189. {
  190. $data = $this->_data['params'];
  191. $data = unserialize($data);
  192. return $data;
  193. }
  194. }