Search This Blog

Tuesday, May 15, 2012

Dataflow profile definition

Dataflow profile definition

Dataflow of data exchange process is called profile and defined as XML structure. Magento provides simple wizard-like tool for generation of some basic import/export profiles operating on products or customers entities. Advanced profiles manager is also provided for advanced users able to create XML defining profile without wizard tool and with need to use more custom dataflow operations related also to other entities. Basic concept is that data exchange process is a set of actions. Each action executes part of the process, depending on its type, which can be for example parsing one set of data into another one with parser or collecting data from a resource with adapter. Common data, passed from action to action is stored within profiles batch container.

Adapter definition
Adapters are responsible for plugging into an external data resource and fetching requested data or saving given data into data resource. For this purpose all adapters implement interface Mage_Dataflow_Model_Convert_Adapter_Interface which contains two methods: load() and save(). Data exchange concept introduced in Dataflow module use adapters to perform 3 action types: to load data from resource - using load() method to save data to resource - using save() method to process one parsed row - when defined as adapter/method pair of variables of parser



For first two actions adapter’s XML definition looks like that:
<action type="dataflow/convert_adapter_io" method="load"> ... </action>

Action tag has two parameters: type and method. Type tells us which adapter class is going to be used to perform action. It is defined using its alias. Method tells us which method of this adapter class action should call.

[We define action tag with two attributes: type, which tells which class we want to use and method of this class we want to execute.]

By default there are two available methods: load and save. Children of action tag define variables which are parameters used during execution of adapter’s method. Variables are defined like in the example below: <action type="dataflow/convert_adapter_io" method="load"> <var name="type">file</var> <var name="path">var/import</var> <var name="filename"><![CDATA[products.csv]]></var> <var name="format"><![CDATA[csv]]></var> </action>

Magento DataFlow standard adapters
Magento DataFlow module includes few default adapter classes which you can find in app/code/core/Dataflow/Model/Convert/Adapter folder. Not all of them have yet implemented load() and save() methods. For common case of reading data from or saving data to local or remote file you will use dataflow/convert_adapter_io (Mage_Dataflow_Model_Convert_Adapter_Io).


Following variables will allow you to define local/remote file as data source:
    type - defines type of io source we want to process. Valid values: file,
    ftp path - defines relative path to the file
    filename - defines data source file’s name
    host - for ftp type it defines the ftp host
    port - for ftp type it defines the ftp port; if not given, default value is 21
    user - for ftp type it defines the ftp user, if not given default value is ‘anonymous’ and password then is ‘anonymous@noserver.com’
    password - for ftp type it defines the ftp user’s password
    timeout - for ftp type it defines connection timeout; default value is 90
    file_mode - for ftp type it defines file mode; default value is FTP_BINARY ssl - for ftp type if it is not empty, then ftp ssl connection is used
    passive - for ftp type it defines connection mode; default value is false

No comments:

Post a Comment