00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Dataflow 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 00028 /** 00029 * 00030 * @category Mage 00031 * @package Mage_Dataflow 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 abstract class Mage_Dataflow_Model_Convert_Profile_Abstract 00035 implements Mage_Dataflow_Model_Convert_Profile_Interface 00036 { 00037 00038 protected $_actions; 00039 00040 protected $_containers; 00041 00042 protected $_exceptions = array(); 00043 00044 protected $_dryRun; 00045 00046 protected $_actionDefaultClass = 'Mage_Dataflow_Model_Convert_Action'; 00047 00048 protected $_containerCollectionDefaultClass = 'Mage_Dataflow_Model_Convert_Container_Collection'; 00049 00050 protected $_dataflow_profile = null; 00051 00052 public function addAction(Mage_Dataflow_Model_Convert_Action_Interface $action=null) 00053 { 00054 if (is_null($action)) { 00055 $action = new $this->_actionDefaultClass(); 00056 } 00057 $this->_actions[] = $action; 00058 $action->setProfile($this); 00059 return $action; 00060 } 00061 00062 public function setContainers(Mage_Dataflow_Model_Convert_Container_Collection $containers) 00063 { 00064 $this->_containers = $containers; 00065 return $this; 00066 } 00067 00068 public function getContainers() 00069 { 00070 if (!$this->_containers) { 00071 $this->_containers = new $this->_containerCollectionDefaultClass(); 00072 } 00073 return $this->_containers; 00074 } 00075 00076 public function getContainer($name=null) 00077 { 00078 if (is_null($name)) { 00079 $name = '_default'; 00080 } 00081 return $this->getContainers()->getItem($name); 00082 } 00083 00084 public function addContainer($name, Mage_Dataflow_Model_Convert_Container_Interface $container) 00085 { 00086 $container = $this->getContainers()->addItem($name, $container); 00087 $container->setProfile($this); 00088 return $container; 00089 } 00090 00091 public function getExceptions() 00092 { 00093 return $this->_exceptions; 00094 } 00095 00096 public function getDryRun() 00097 { 00098 return $this->_dryRun; 00099 } 00100 00101 public function setDryRun($flag) 00102 { 00103 $this->_dryRun = $flag; 00104 return $this; 00105 } 00106 00107 public function addException(Mage_Dataflow_Model_Convert_Exception $e) 00108 { 00109 $this->_exceptions[] = $e; 00110 return $this; 00111 } 00112 00113 public function importXml(Varien_Simplexml_Element $profileNode) 00114 { 00115 foreach ($profileNode->action as $actionNode) { 00116 $action = $profile->addAction(); 00117 $action->importXml($actionNode); 00118 } 00119 00120 return $this; 00121 } 00122 00123 public function run() 00124 { 00125 // print '<pre>'; 00126 // print_r($this->_dataflow_profile); 00127 // print '</pre>'; 00128 00129 if (!$this->_actions) { 00130 $e = new Mage_Dataflow_Model_Convert_Exception("Could not find any actions for this profile"); 00131 $e->setLevel(Mage_Dataflow_Model_Convert_Exception::FATAL); 00132 $this->addException($e); 00133 return; 00134 } 00135 00136 foreach ($this->_actions as $action) { 00137 /* @var $action Mage_Dataflow_Model_Convert_Action */ 00138 try { 00139 $action->run(); 00140 } 00141 catch (Exception $e) { 00142 $dfe = new Mage_Dataflow_Model_Convert_Exception($e->getMessage()); 00143 $dfe->setLevel(Mage_Dataflow_Model_Convert_Exception::FATAL); 00144 $this->addException($dfe); 00145 return ; 00146 } 00147 } 00148 return $this; 00149 } 00150 00151 function setDataflowProfile($profile) { 00152 if (is_array($profile)) { 00153 $this->_dataflow_profile = $profile; 00154 } 00155 return $this; 00156 } 00157 00158 function getDataflowProfile() 00159 { 00160 return $this->_dataflow_profile; 00161 } 00162 }