00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 abstract class Mage_Dataflow_Model_Convert_Action_Abstract
00038 implements Mage_Dataflow_Model_Convert_Action_Interface
00039 {
00040
00041
00042
00043
00044
00045
00046
00047
00048 protected $_params;
00049
00050
00051
00052
00053
00054
00055 protected $_profile;
00056
00057 protected $_actions = array();
00058
00059
00060
00061
00062
00063
00064 protected $_container;
00065
00066 protected $_actionDefaultClass = 'Mage_Dataflow_Model_Convert_Action';
00067
00068
00069
00070
00071
00072
00073
00074
00075 public function getParam($key, $default=null)
00076 {
00077 if (!isset($this->_params[$key])) {
00078 return $default;
00079 }
00080 return $this->_params[$key];
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090 public function setParam($key, $value=null)
00091 {
00092 if (is_array($key) && is_null($value)) {
00093 $this->_params = $key;
00094 } else {
00095 $this->_params[$key] = $value;
00096 }
00097 return $this;
00098 }
00099
00100
00101
00102
00103
00104
00105 public function getParams()
00106 {
00107 return $this->_params;
00108 }
00109
00110
00111
00112
00113
00114
00115
00116 public function setParams($params)
00117 {
00118 $this->_params = $params;
00119 return $this;
00120 }
00121
00122
00123
00124
00125
00126
00127 public function getProfile()
00128 {
00129 return $this->_profile;
00130 }
00131
00132
00133
00134
00135
00136
00137
00138 public function setProfile(Mage_Dataflow_Model_Convert_Profile_Interface $profile)
00139 {
00140 $this->_profile = $profile;
00141 return $this;
00142 }
00143
00144 public function addAction(Mage_Dataflow_Model_Convert_Action_Interface $action=null)
00145 {
00146 if (is_null($action)) {
00147 $action = new $this->_actionDefaultClass();
00148 }
00149 $this->_actions[] = $action;
00150 $action->setProfile($this->getProfile());
00151 return $action;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160 public function setContainer(Mage_Dataflow_Model_Convert_Container_Interface $container)
00161 {
00162 $this->_container = $container;
00163 $this->_container->setProfile($this->getProfile());
00164 $this->_container->setAction($this);
00165 return $this;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 public function getContainer($name=null)
00175 {
00176 if (!is_null($name)) {
00177 return $this->getProfile()->getContainer($name);
00178 }
00179
00180 if (!$this->_container) {
00181 $class = $this->getParam('class');
00182 $this->setContainer(new $class());
00183 }
00184 return $this->_container;
00185 }
00186
00187 public function importXml(Varien_Simplexml_Element $actionNode)
00188 {
00189 foreach ($actionNode->attributes() as $key=>$value) {
00190 $this->setParam($key, (string)$value);
00191 }
00192
00193 if ($actionNode['use']) {
00194 $container = $this->getProfile()->getContainer((string)$actionNode['use']);
00195 } else {
00196 $this->setParam('class', $this->getClassNameByType((string)$actionNode['type']));
00197 $container = $action->getContainer();
00198 }
00199 $this->setContainer($container);
00200 if ($this->getParam('name')) {
00201 $this->getProfile()->addContainer($this->getParam('name'), $container);
00202 }
00203 foreach ($actionNode->var as $varNode) {
00204 $container->setVar((string)$varNode['name'], (string)$varNode);
00205 }
00206 foreach ($actionNode->action as $actionSubnode) {
00207 $action = $this->addAction();
00208 $action->importXml($actionSubnode);
00209 }
00210
00211 return $this;
00212 }
00213
00214
00215
00216
00217
00218
00219 public function run(array $args=array())
00220 {
00221 if ($method = $this->getParam('method')) {
00222
00223 if (!is_callable(array($this->getContainer(), $method))) {
00224 $this->getContainer()->addException('Unable to run action method: '.$method, Mage_Dataflow_Model_Convert_Exception::FATAL);
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234 $this->getContainer()->addException('Starting '.get_class($this->getContainer()).' :: '.$method);
00235
00236 if ($this->getParam('from')) {
00237
00238 $this->getContainer()->setData($this->getContainer($this->getParam('from'))->getData());
00239 }
00240
00241
00242 $this->getContainer()->$method($args);
00243
00244 if ($this->getParam('to')) {
00245 $this->getContainer($this->getParam('to'))->setData($this->getContainer()->getData());
00246 }
00247 } else {
00248 $this->addException('No method specified', Mage_Dataflow_Model_Convert_Exception::FATAL);
00249 }
00250 return $this;
00251 }
00252
00253 public function runActions(array $args=array())
00254 {
00255 if (empty($this->_actions)) {
00256 return $this;
00257 }
00258 foreach ($this->_actions as $action) {
00259 $action->run($args);
00260 }
00261 return $this;
00262 }
00263 }