PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/magento/app/code/core/Mage/ImportExport/Model/Abstract.php

https://bitbucket.org/jit_bec/shopifine
PHP | 117 lines | 48 code | 7 blank | 62 comment | 5 complexity | d5f0f4463f4e157ef32c3ae05deb92c6 MD5 | raw file
Possible License(s): LGPL-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_ImportExport
  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. * Operation abstract class
  28. *
  29. * @category Mage
  30. * @package Mage_ImportExport
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. abstract class Mage_ImportExport_Model_Abstract extends Varien_Object
  34. {
  35. /**
  36. * Enable loging
  37. *
  38. * @var boolean
  39. */
  40. protected $_debugMode = false;
  41. /**
  42. * Loger instance
  43. * @var Mage_Core_Model_Log_Adapter
  44. */
  45. protected $_logInstance;
  46. /**
  47. * Fields that should be replaced in debug with '***'
  48. *
  49. * @var array
  50. */
  51. protected $_debugReplacePrivateDataKeys = array();
  52. /**
  53. * Contains all log information
  54. *
  55. * @var array
  56. */
  57. protected $_logTrace = array();
  58. /**
  59. * Log debug data to file.
  60. * Log file dir: var/log/import_export/%Y/%m/%d/%time%_%operation_type%_%entity_type%.log
  61. *
  62. * @param mixed $debugData
  63. * @return Mage_ImportExport_Model_Abstract
  64. */
  65. public function addLogComment($debugData)
  66. {
  67. if (is_array($debugData)) {
  68. $this->_logTrace = array_merge($this->_logTrace, $debugData);
  69. } else {
  70. $this->_logTrace[] = $debugData;
  71. }
  72. if (!$this->_debugMode) {
  73. return $this;
  74. }
  75. if (!$this->_logInstance) {
  76. $dirName = date('Y' . DS .'m' . DS .'d' . DS);
  77. $fileName = join('_', array(
  78. str_replace(':', '-', $this->getRunAt()),
  79. $this->getScheduledOperationId(),
  80. $this->getOperationType(),
  81. $this->getEntity()
  82. ));
  83. $dirPath = Mage::getBaseDir('var') . DS . Mage_ImportExport_Model_Scheduled_Operation::LOG_DIRECTORY
  84. . $dirName;
  85. if (!is_dir($dirPath)) {
  86. mkdir($dirPath, 0777, true);
  87. }
  88. $fileName = substr(strstr(Mage_ImportExport_Model_Scheduled_Operation::LOG_DIRECTORY, DS), 1)
  89. . $dirName . $fileName . '.log';
  90. $this->_logInstance = Mage::getModel('core/log_adapter', $fileName)
  91. ->setFilterDataKeys($this->_debugReplacePrivateDataKeys);
  92. }
  93. $this->_logInstance->log($debugData);
  94. return $this;
  95. }
  96. /**
  97. * Return human readable debug trace.
  98. *
  99. * @return array
  100. */
  101. public function getFormatedLogTrace()
  102. {
  103. $trace = '';
  104. $lineNumber = 1;
  105. foreach ($this->_logTrace as &$info) {
  106. $trace .= $lineNumber++ . ': ' . $info . "\n";
  107. }
  108. return $trace;
  109. }
  110. }