Mage_Core_Model_Convert_Profile Class Reference

Inheritance diagram for Mage_Core_Model_Convert_Profile:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 run ()
 _parseGuiData ()
 _parseGuiDataOrig ()

Protected Member Functions

 _construct ()
 _afterLoad ()
 _beforeSave ()
 _afterSave ()


Detailed Description

Convert profile

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 32 of file Profile.php.


Member Function Documentation

_afterLoad (  )  [protected]

Processing object after load data

Returns:
Mage_Core_Model_Abstract

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 39 of file Profile.php.

00040     {
00041         if (is_string($this->getGuiData())) {
00042             $guiData = unserialize($this->getGuiData());
00043         } else {
00044             $guiData = '';
00045         }
00046         $this->setGuiData($guiData);
00047 
00048         parent::_afterLoad();
00049     }

_afterSave (  )  [protected]

Processing object after save data

Returns:
Mage_Core_Model_Abstract

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 61 of file Profile.php.

00062     {
00063         if (is_string($this->getGuiData())) {
00064             $this->setGuiData(unserialize($this->getGuiData()));
00065         }
00066 
00067         Mage::getModel('core/convert_history')
00068             ->setProfileId($this->getId())
00069             ->setActionCode($this->getOrigData('profile_id') ? 'update' : 'create')
00070             ->save();
00071 
00072         parent::_afterSave();
00073     }

_beforeSave (  )  [protected]

Processing object before save data

Returns:
Mage_Core_Model_Abstract

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 51 of file Profile.php.

00052     {
00053         parent::_beforeSave();
00054 
00055         if (is_array($this->getGuiData())) {
00056             $this->_parseGuiData();
00057             $this->setGuiData(serialize($this->getGuiData()));
00058         }
00059     }

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 34 of file Profile.php.

00035     {
00036         $this->_init('core/convert_profile');
00037     }

_parseGuiData (  ) 

Definition at line 93 of file Profile.php.

00094     {
00095         $nl = "\r\n";
00096         $import = $this->getDirection()==='import';
00097         $p = $this->getGuiData();
00098 
00099         if ($this->getDataTransfer()==='interactive') {
00100 //            $p['file']['type'] = 'file';
00101 //            $p['file']['filename'] = $p['interactive']['filename'];
00102 //            $p['file']['path'] = 'var/export';
00103 
00104             $interactiveXml = '<action type="dataflow/convert_adapter_http" method="'.($import?'load':'save').'">'.$nl;
00105             #$interactiveXml .= '    <var name="filename"><![CDATA['.$p['interactive']['filename'].']]></var>'.$nl;
00106             $interactiveXml .= '</action>';
00107 
00108             $fileXml = '';
00109         } else {
00110             $interactiveXml = '';
00111 
00112             $fileXml = '<action type="dataflow/convert_adapter_io" method="'.($import?'load':'save').'">'.$nl;
00113             $fileXml .= '    <var name="type">'.$p['file']['type'].'</var>'.$nl;
00114             $fileXml .= '    <var name="path">'.$p['file']['path'].'</var>'.$nl;
00115             $fileXml .= '    <var name="filename"><![CDATA['.$p['file']['filename'].']]></var>'.$nl;
00116             if ($p['file']['type']==='ftp') {
00117                 $hostArr = explode(':', $p['file']['host']);
00118                 $fileXml .= '    <var name="host"><![CDATA['.$hostArr[0].']]></var>'.$nl;
00119                 if (isset($hostArr[1])) {
00120                     $fileXml .= '    <var name="port"><![CDATA['.$hostArr[1].']]></var>'.$nl;
00121                 }
00122                 if (!empty($p['file']['passive'])) {
00123                     $fileXml .= '    <var name="passive">true</var>'.$nl;
00124                 }
00125                 if (!empty($p['file']['user'])) {
00126                     $fileXml .= '    <var name="user"><![CDATA['.$p['file']['user'].']]></var>'.$nl;
00127                 }
00128                 if (!empty($p['file']['password'])) {
00129                     $fileXml .= '    <var name="password"><![CDATA['.$p['file']['password'].']]></var>'.$nl;
00130                 }
00131             }
00132             $fileXml .= '</action>'.$nl.$nl;
00133         }
00134 
00135         switch ($p['parse']['type']) {
00136             case 'excel_xml':
00137                 $parseFileXml = '<action type="dataflow/convert_parser_xml_excel" method="'.($import?'parse':'unparse').'">'.$nl;
00138                 $parseFileXml .= '    <var name="single_sheet"><![CDATA['.($p['parse']['single_sheet']!==''?$p['parse']['single_sheet']:'_').']]></var>'.$nl;
00139                 break;
00140 
00141             case 'csv':
00142                 $parseFileXml = '<action type="dataflow/convert_parser_csv" method="'.($import?'parse':'unparse').'">'.$nl;
00143                 $parseFileXml .= '    <var name="delimiter"><![CDATA['.$p['parse']['delimiter'].']]></var>'.$nl;
00144                 $parseFileXml .= '    <var name="enclose"><![CDATA['.$p['parse']['enclose'].']]></var>'.$nl;
00145                 break;
00146         }
00147         $parseFileXml .= '    <var name="fieldnames">'.$p['parse']['fieldnames'].'</var>'.$nl;
00148         $parseFileXml .= '</action>'.$nl.$nl;
00149 
00150         $mapXml = '';
00151         if (isset($p['map']) && is_array($p['map'])) {
00152             foreach ($p['map'] as $side=>$fields) {
00153                 if (!is_array($fields)) {
00154                     continue;
00155                 }
00156                 foreach ($fields['db'] as $i=>$k) {
00157                     if ($k=='' || $k=='0') {
00158                         unset($p['map'][$side]['db'][$i]);
00159                         unset($p['map'][$side]['file'][$i]);
00160                     }
00161                 }
00162             }
00163         }
00164         $mapXml .= '<action type="dataflow/convert_mapper_column" method="map">'.$nl;
00165         $map = $p['map'][$this->getEntityType()];
00166         if (sizeof($map['db'])>0) {
00167             $from = $map[$import?'file':'db'];
00168             $to = $map[$import?'db':'file'];
00169             foreach ($from as $i=>$f) {
00170                 $mapXml .= '    <var name="'.$f.'"><![CDATA['.$to[$i].']]></var>'.$nl;
00171             }
00172         }
00173         if ($p['map']['only_specified']) {
00174             $mapXml .= '    <var name="_only_specified">'.$p['map']['only_specified'].'</var>'.$nl;
00175         }
00176         $mapXml .= '</action>'.$nl.$nl;
00177 
00178         $parsers = array(
00179             'product'=>'catalog/convert_parser_product',
00180             'customer'=>'customer/convert_parser_customer',
00181         );
00182 
00183         if ($import) {
00184             $parseDataXml = '<action type="'.$parsers[$this->getEntityType()].'" method="parse">'.$nl;
00185             $parseDataXml .= '    <var name="store"><![CDATA['.$this->getStoreId().']]></var>'.$nl;
00186             $parseDataXml .= '</action>'.$nl.$nl;
00187         } else {
00188             $parseDataXml = '<action type="'.$parsers[$this->getEntityType()].'" method="unparse">'.$nl;
00189             $parseDataXml .= '    <var name="store"><![CDATA['.$this->getStoreId().']]></var>'.$nl;
00190             $parseDataXml .= '</action>'.$nl.$nl;
00191         }
00192 
00193         $adapters = array(
00194             'product'=>'catalog/convert_adapter_product',
00195             'customer'=>'customer/convert_adapter_customer',
00196         );
00197 
00198         if ($import) {
00199             $entityXml = '<action type="'.$adapters[$this->getEntityType()].'" method="save">'.$nl;
00200             $entityXml .= '    <var name="store"><![CDATA['.$this->getStoreId().']]></var>'.$nl;
00201             $entityXml .= '</action>'.$nl.$nl;
00202         } else {
00203             $entityXml = '<action type="'.$adapters[$this->getEntityType()].'" method="load">'.$nl;
00204             $entityXml .= '    <var name="store"><![CDATA['.$this->getStoreId().']]></var>'.$nl;
00205             foreach ($p[$this->getEntityType()]['filter'] as $f=>$v) {
00206                 if (empty($v)) {
00207                     continue;
00208                 }
00209                 if (is_scalar($v)) {
00210                     $entityXml .= '    <var name="filter/'.$f.'"><![CDATA['.$v.']]></var>'.$nl;
00211                 } elseif (is_array($v)) {
00212                     foreach ($v as $a=>$b) {
00213                         if (empty($b)) {
00214                             continue;
00215                         }
00216                         $entityXml .= '    <var name="filter/'.$f.'/'.$a.'"><![CDATA['.$b.']]></var>'.$nl;
00217                     }
00218                 }
00219             }
00220             $entityXml .= '</action>'.$nl.$nl;
00221         }
00222 
00223         if ($import) {
00224             $xml = $interactiveXml.$fileXml.$parseFileXml.$mapXml.$parseDataXml.$entityXml;
00225         } else {
00226             $xml = $entityXml.$parseDataXml.$mapXml.$parseFileXml.$fileXml.$interactiveXml;
00227         }
00228 
00229         $this->setGuiData($p);
00230         $this->setActionsXml($xml);
00231 /*echo "<pre>".print_r($p,1)."</pre>";
00232 echo "<xmp>".$xml."</xmp>";
00233 die;*/
00234         return $this;
00235     }

_parseGuiDataOrig (  ) 

Definition at line 237 of file Profile.php.

00238     {
00239         $nl = "\r\n";
00240         $import = $this->getDirection()==='import';
00241         $p = $this->getGuiData();
00242 
00243         if ($this->getDataTransfer()==='interactive') {
00244 //            $p['file']['type'] = 'file';
00245 //            $p['file']['filename'] = $p['interactive']['filename'];
00246 //            $p['file']['path'] = 'var/export';
00247 
00248             $interactiveXml = '<action type="varien/convert_adapter_http" method="'.($import?'load':'save').'">'.$nl;
00249             #$interactiveXml .= '    <var name="filename"><![CDATA['.$p['interactive']['filename'].']]></var>'.$nl;
00250             $interactiveXml .= '</action>';
00251 
00252             $fileXml = '';
00253         } else {
00254             $interactiveXml = '';
00255 
00256             $fileXml = '<action type="varien/convert_adapter_io" method="'.($import?'load':'save').'">'.$nl;
00257             $fileXml .= '    <var name="type">'.$p['file']['type'].'</var>'.$nl;
00258             $fileXml .= '    <var name="path">'.$p['file']['path'].'</var>'.$nl;
00259             $fileXml .= '    <var name="filename"><![CDATA['.$p['file']['filename'].']]></var>'.$nl;
00260             if ($p['file']['type']==='ftp') {
00261                 $hostArr = explode(':', $p['file']['host']);
00262                 $fileXml .= '    <var name="host"><![CDATA['.$hostArr[0].']]></var>'.$nl;
00263                 if (isset($hostArr[1])) {
00264                     $fileXml .= '    <var name="port"><![CDATA['.$hostArr[1].']]></var>'.$nl;
00265                 }
00266                 if (!empty($p['file']['passive'])) {
00267                     $fileXml .= '    <var name="passive">true</var>'.$nl;
00268                 }
00269                 if (!empty($p['file']['user'])) {
00270                     $fileXml .= '    <var name="user"><![CDATA['.$p['file']['user'].']]></var>'.$nl;
00271                 }
00272                 if (!empty($p['file']['password'])) {
00273                     $fileXml .= '    <var name="password"><![CDATA['.$p['file']['password'].']]></var>'.$nl;
00274                 }
00275             }
00276             $fileXml .= '</action>'.$nl.$nl;
00277         }
00278 
00279         switch ($p['parse']['type']) {
00280             case 'excel_xml':
00281                 $parseFileXml = '<action type="varien/convert_parser_xml_excel" method="'.($import?'parse':'unparse').'">'.$nl;
00282                 $parseFileXml .= '    <var name="single_sheet"><![CDATA['.($p['parse']['single_sheet']!==''?$p['parse']['single_sheet']:'_').']]></var>'.$nl;
00283                 break;
00284 
00285             case 'csv':
00286                 $parseFileXml = '<action type="varien/convert_parser_csv" method="'.($import?'parse':'unparse').'">'.$nl;
00287                 $parseFileXml .= '    <var name="delimiter"><![CDATA['.$p['parse']['delimiter'].']]></var>'.$nl;
00288                 $parseFileXml .= '    <var name="enclose"><![CDATA['.$p['parse']['enclose'].']]></var>'.$nl;
00289                 break;
00290         }
00291         $parseFileXml .= '    <var name="fieldnames">'.$p['parse']['fieldnames'].'</var>'.$nl;
00292         $parseFileXml .= '</action>'.$nl.$nl;
00293 
00294         $mapXml = '';
00295         if (isset($p['map']) && is_array($p['map'])) {
00296             foreach ($p['map'] as $side=>$fields) {
00297                 if (!is_array($fields)) {
00298                     continue;
00299                 }
00300                 foreach ($fields['db'] as $i=>$k) {
00301                     if ($k=='' || $k=='0') {
00302                         unset($p['map'][$side]['db'][$i]);
00303                         unset($p['map'][$side]['file'][$i]);
00304                     }
00305                 }
00306             }
00307         }
00308         $mapXml .= '<action type="varien/convert_mapper_column" method="map">'.$nl;
00309         $map = $p['map'][$this->getEntityType()];
00310         if (sizeof($map['db'])>0) {
00311             $from = $map[$import?'file':'db'];
00312             $to = $map[$import?'db':'file'];
00313             foreach ($from as $i=>$f) {
00314                 $mapXml .= '    <var name="'.$f.'"><![CDATA['.$to[$i].']]></var>'.$nl;
00315             }
00316         }
00317         if ($p['map']['only_specified']) {
00318             $mapXml .= '    <var name="_only_specified">'.$p['map']['only_specified'].'</var>'.$nl;
00319         }
00320         $mapXml .= '</action>'.$nl.$nl;
00321 
00322         $parsers = array(
00323             'product'=>'catalog/convert_parser_product',
00324             'customer'=>'customer/convert_parser_customer',
00325         );
00326 
00327         if ($import) {
00328             $parseDataXml = '<action type="'.$parsers[$this->getEntityType()].'" method="parse">'.$nl;
00329             $parseDataXml .= '    <var name="store"><![CDATA['.$this->getStoreId().']]></var>'.$nl;
00330             $parseDataXml .= '</action>'.$nl.$nl;
00331         } else {
00332             $parseDataXml = '<action type="'.$parsers[$this->getEntityType()].'" method="unparse">'.$nl;
00333             $parseDataXml .= '    <var name="store"><![CDATA['.$this->getStoreId().']]></var>'.$nl;
00334             $parseDataXml .= '</action>'.$nl.$nl;
00335         }
00336 
00337         $adapters = array(
00338             'product'=>'catalog/convert_adapter_product',
00339             'customer'=>'customer/convert_adapter_customer',
00340         );
00341 
00342         if ($import) {
00343             $entityXml = '<action type="'.$adapters[$this->getEntityType()].'" method="save">'.$nl;
00344             $entityXml .= '    <var name="store"><![CDATA['.$this->getStoreId().']]></var>'.$nl;
00345             $entityXml .= '</action>'.$nl.$nl;
00346         } else {
00347             $entityXml = '<action type="'.$adapters[$this->getEntityType()].'" method="load">'.$nl;
00348             $entityXml .= '    <var name="store"><![CDATA['.$this->getStoreId().']]></var>'.$nl;
00349             foreach ($p[$this->getEntityType()]['filter'] as $f=>$v) {
00350                 if (empty($v)) {
00351                     continue;
00352                 }
00353                 if (is_scalar($v)) {
00354                     $entityXml .= '    <var name="filter/'.$f.'"><![CDATA['.$v.']]></var>'.$nl;
00355                 } elseif (is_array($v)) {
00356                     foreach ($v as $a=>$b) {
00357                         if (empty($b)) {
00358                             continue;
00359                         }
00360                         $entityXml .= '    <var name="filter/'.$f.'/'.$a.'"><![CDATA['.$b.']]></var>'.$nl;
00361                     }
00362                 }
00363             }
00364             $entityXml .= '</action>'.$nl.$nl;
00365         }
00366 
00367         if ($import) {
00368             $xml = $interactiveXml.$fileXml.$parseFileXml.$mapXml.$parseDataXml.$entityXml;
00369         } else {
00370             $xml = $entityXml.$parseDataXml.$mapXml.$parseFileXml.$fileXml.$interactiveXml;
00371         }
00372 
00373         $this->setGuiData($p);
00374         $this->setActionsXml($xml);
00375 /*echo "<pre>".print_r($p,1)."</pre>";
00376 echo "<xmp>".$xml."</xmp>";
00377 die;*/
00378         return $this;
00379     }

run (  ) 

Definition at line 75 of file Profile.php.

00076     {
00077         Mage::getModel('core/convert_history')
00078             ->setProfileId($this->getId())
00079             ->setActionCode('run')
00080             ->save();
00081 
00082         $xml = '<convert version="1.0"><profile name="default">'.$this->getActionsXml().'</profile></convert>';
00083         $profile = Mage::getModel('core/convert')->importXml($xml)->getProfile('default');
00084         try {
00085             $profile->run();
00086         } catch (Exception $e) {
00087 
00088         }
00089         $this->setExceptions($profile->getExceptions());
00090         return $this;
00091     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:56 2009 for Magento by  doxygen 1.5.8