Mage_Dataflow_Model_Convert_Adapter_Io Class Reference

Inheritance diagram for Mage_Dataflow_Model_Convert_Adapter_Io:

Mage_Dataflow_Model_Convert_Adapter_Abstract Mage_Dataflow_Model_Convert_Container_Abstract Mage_Dataflow_Model_Convert_Adapter_Interface Mage_Dataflow_Model_Convert_Container_Interface

List of all members.

Public Member Functions

 getResource ($forWrite=false)
 load ()
 save ()


Detailed Description

Definition at line 35 of file Io.php.


Member Function Documentation

getResource ( forWrite = false  ) 

Returns:
Varien_Io_Abstract

Definition at line 40 of file Io.php.

00041     {
00042         if (!$this->_resource) {
00043             $type = $this->getVar('type', 'file');
00044             $className = 'Varien_Io_'.ucwords($type);
00045             $this->_resource = new $className();
00046 
00047             $isError = false;
00048 
00049             $ioConfig = $this->getVars();
00050             switch ($this->getVar('type', 'file')) {
00051                 case 'file':
00052                     if (preg_match('#^'.preg_quote(DS, '#').'#', $this->getVar('path')) ||
00053                         preg_match('#^[a-z]:'.preg_quote(DS, '#') .'#i', $this->getVar('path'))) {
00054 
00055                         $path = $this->_resource->getCleanPath($this->getVar('path'));
00056                     }
00057                     else {
00058                         $baseDir = Mage::getBaseDir();
00059                         $path = $this->_resource->getCleanPath($baseDir . DS . trim($this->getVar('path'), DS));
00060                     }
00061 
00062                     $this->_resource->checkAndCreateFolder($path);
00063 
00064                     $realPath = realpath($path);
00065 
00066                     if (!$isError && $realPath === false) {
00067                         $message = Mage::helper('dataflow')->__('Destination folder "%s" does not exist or not access to create', $ioConfig['path']);
00068                         Mage::throwException($message);
00069                     }
00070                     elseif (!$isError && !is_dir($realPath)) {
00071                         $message = Mage::helper('dataflow')->__('Destination folder "%s" is not a directory', $realPath);
00072                         Mage::throwException($message);
00073                     }
00074                     elseif (!$isError) {
00075                         if ($forWrite && !is_writeable($realPath)) {
00076                             $message = Mage::helper('dataflow')->__('Destination folder "%s" is not a writeable', $realPath);
00077                             Mage::throwException($message);
00078                         }
00079                         else {
00080                             $ioConfig['path'] = rtrim($realPath, DS);
00081                         }
00082                     }
00083 
00084 //                    $baseDir = Mage::getBaseDir();
00085 //                    $path = $this->_resource->getCleanPath($baseDir . '/' . trim($this->getVar('path'), '/'));
00086 //                    $basePath = $this->_resource->getCleanPath($baseDir);
00087 //
00088 //                    if (strpos($path, $basePath) !== 0) {
00089 //                        $message = Mage::helper('dataflow')->__('Access denied to destination folder "%s"', $path);
00090 //                        Mage::throwException($message);
00091 //                    } else {
00092 //                        $this->_resource->checkAndCreateFolder($path);
00093 //                    }
00094 //
00095 //                    $realPath = realpath($path);
00096 //                    if (!$isError && $realPath === false) {
00097 //                        $message = Mage::helper('dataflow')->__('Destination folder "%s" does not exist or not access to create', $ioConfig['path']);
00098 //                        Mage::throwException($message);
00099 //                    }
00100 //                    elseif (!$isError && !is_dir($realPath)) {
00101 //                        $message = Mage::helper('dataflow')->__('Destination folder "%s" is not a directory', $realPath);
00102 //                        Mage::throwException($message);
00103 //                    }
00104 //                    elseif (!$isError) {
00105 //                        if ($forWrite && !is_writeable($realPath)) {
00106 //                            $message = Mage::helper('dataflow')->__('Destination folder "%s" is not a writeable', $realPath);
00107 //                            Mage::throwException($message);
00108 //                        }
00109 //                        else {
00110 //                            $ioConfig['path'] = rtrim($realPath, '/');
00111 //                        }
00112 //                    }
00113                     break;
00114                 default:
00115                     $ioConfig['path'] = rtrim($this->getVar('path'), '/');
00116                     break;
00117             }
00118 
00119             if ($isError) {
00120                 return false;
00121             }
00122             try {
00123                 $this->_resource->open($ioConfig);
00124             } catch (Exception $e) {
00125                 $message = Mage::helper('dataflow')->__('Error occured during file opening: "%s"', $e->getMessage());
00126                 Mage::throwException($message);
00127             }
00128         }
00129         return $this->_resource;
00130     }

load (  ) 

Load data

Returns:
Mage_Dataflow_Model_Convert_Adapter_Io

Implements Mage_Dataflow_Model_Convert_Adapter_Interface.

Definition at line 137 of file Io.php.

00138     {
00139         if (!$this->getResource()) {
00140             return $this;
00141         }
00142 
00143         $batchModel = Mage::getSingleton('dataflow/batch');
00144         $destFile = $batchModel->getIoAdapter()->getFile(true);
00145 
00146         $result = $this->getResource()->read($this->getVar('filename'), $destFile);
00147         $filename = $this->getResource()->pwd() . '/' . $this->getVar('filename');
00148         if (false === $result) {
00149             $message = Mage::helper('dataflow')->__('Could not load file: "%s"', $filename);
00150             Mage::throwException($message);
00151         } else {
00152             $message = Mage::helper('dataflow')->__('Loaded successfully: "%s"', $filename);
00153             $this->addException($message);
00154         }
00155 
00156         $this->setData($result);
00157         return $this;
00158     }

save (  ) 

Save result to destionation file from temporary

Returns:
Mage_Dataflow_Model_Convert_Adapter_Io

Implements Mage_Dataflow_Model_Convert_Adapter_Interface.

Definition at line 165 of file Io.php.

00166     {
00167         if (!$this->getResource(true)) {
00168             return $this;
00169         }
00170 
00171         $batchModel = Mage::getSingleton('dataflow/batch');
00172 
00173         $dataFile = $batchModel->getIoAdapter()->getFile(true);
00174 
00175         $filename = $this->getVar('filename');
00176 
00177         $result   = $this->getResource()->write($filename, $dataFile, 0777);
00178 
00179         if (false === $result) {
00180             $message = Mage::helper('dataflow')->__('Could not save file: %s', $filename);
00181             Mage::throwException($message);
00182         } else {
00183             $message = Mage::helper('dataflow')->__('Saved successfully: "%s" [%d byte(s)]', $filename, $batchModel->getIoAdapter()->getFileSize());
00184             if ($this->getVar('link')) {
00185                 $message .= Mage::helper('dataflow')->__('<a href="%s" target="_blank">Link</a>', $this->getVar('link'));
00186             }
00187             $this->addException($message);
00188         }
00189         return $this;
00190     }


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

Generated on Sat Jul 4 17:24:05 2009 for Magento by  doxygen 1.5.8