/app/code/core/Mage/ImportExport/Model/Abstract.php
https://gitlab.com/LisovyiEvhenii/ismextensions · PHP · 135 lines · 54 code · 9 blank · 72 comment · 5 complexity · 40838be4ecbacd9411cce97a8e33fd59 MD5 · raw file
- <?php
- /**
- * Magento
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@magento.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade Magento to newer
- * versions in the future. If you wish to customize Magento for your
- * needs please refer to http://www.magento.com for more information.
- *
- * @category Mage
- * @package Mage_ImportExport
- * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- */
- /**
- * Operation abstract class
- *
- * @category Mage
- * @package Mage_ImportExport
- * @author Magento Core Team <core@magentocommerce.com>
- */
- abstract class Mage_ImportExport_Model_Abstract extends Varien_Object
- {
- /**
- * Log directory
- *
- */
- const LOG_DIRECTORY = 'log/import_export/';
- /**
- * Enable loging
- *
- * @var boolean
- */
- protected $_debugMode = false;
- /**
- * Loger instance
- * @var Mage_Core_Model_Log_Adapter
- */
- protected $_logInstance;
- /**
- * Fields that should be replaced in debug with '***'
- *
- * @var array
- */
- protected $_debugReplacePrivateDataKeys = array();
- /**
- * Contains all log information
- *
- * @var array
- */
- protected $_logTrace = array();
- /**
- * Log debug data to file.
- * Log file dir: var/log/import_export/%Y/%m/%d/%time%_%operation_type%_%entity_type%.log
- *
- * @param mixed $debugData
- * @return Mage_ImportExport_Model_Abstract
- */
- public function addLogComment($debugData)
- {
- if (is_array($debugData)) {
- $this->_logTrace = array_merge($this->_logTrace, $debugData);
- } else {
- $this->_logTrace[] = $debugData;
- }
- if (!$this->_debugMode) {
- return $this;
- }
- if (!$this->_logInstance) {
- $dirName = date('Y' . DS .'m' . DS .'d' . DS);
- $fileName = join('_', array(
- str_replace(':', '-', $this->getRunAt()),
- $this->getScheduledOperationId(),
- $this->getOperationType(),
- $this->getEntity()
- ));
- $dirPath = Mage::getBaseDir('var') . DS . self::LOG_DIRECTORY
- . $dirName;
- if (!is_dir($dirPath)) {
- mkdir($dirPath, 0750, true);
- }
- $fileName = substr(strstr(self::LOG_DIRECTORY, DS), 1)
- . $dirName . $fileName . '.log';
- $this->_logInstance = Mage::getModel('core/log_adapter', $fileName)
- ->setFilterDataKeys($this->_debugReplacePrivateDataKeys);
- }
- $this->_logInstance->log($debugData);
- return $this;
- }
- /**
- * Return human readable debug trace.
- *
- * @return array
- */
- public function getFormatedLogTrace()
- {
- $trace = '';
- $lineNumber = 1;
- foreach ($this->_logTrace as &$info) {
- $trace .= $lineNumber++ . ': ' . $info . "\n";
- }
- return $trace;
- }
- /**
- * Sets debug mode
- *
- * @param bool $mode
- * @return Mage_ImportExport_Model_Abstract
- */
- public function setDebugMode($mode = true)
- {
- $this->_debugMode = (bool)$mode;
- return $this;
- }
- }