migrate data using feeds - gaurav goyal
DESCRIPTION
TRANSCRIPT
Migrate Data using Feeds
What is Feeds?
• Pluggable system for importing content into drupal
• Create and update drupal entities
• one-off import and periodic aggregation of data
Common Use Cases
1. Data Migration1. Import Users2. Import Nodes3. Import Taxonomy Terms
2. Data syncing
Feeds Glossary1. Feed :- A feed can appear in different forms depending on the import stage, before fetching, a feed
is the external document to be fetched(i.e. CSV file. ). After fetching, it is the raw data dump handed to the parser. After parsing, it is the normalized PHP array that is passed to the processor.
2. Feed item : - individual item(CSV Row),3. Feed node : - the node created after the import.4. Mapping : source and target, which tells the importer to map feed item property to node field. A
mapping connects a Mapping Source to a Mapping Target.5. GUID : Stands for global unique identifier. in feeds there is a unique identifier for each feed item i.e.
primary key.6. CSV :
a. Comma separated valuesb. Feeds allow us to import data into this format
7. For more visit https://drupal.org/node/622710
Feeds Architecture
Source (Say CSV File)
Feed Feed Items
Drupal Entity
HTTP CSV Nodes
File OPML Users
Xpath Taxonomy
Importer
Fetcher Parser Processor
Mapper
Migrate Data (For E.g. Nodes)1. Build a Content Type2. Create A CSV of required data3. Build a feed Importer
a. Select Fetcher type (File)b. Select Parser (CSV file) - Under CSV parser set delimiterc. Select Processor (Node Processor)d. Under node processor - e. Specify the bundle name (this will get associated with the items which will be imported by this
importer)f. Specify Author name for the imported nodesg. Under Mapping : - Map the csv fields to the content type field.h. Save the importer
4. Go to www.yoursite.com/import5. select the created importer, upload the file and click on import6. Data will get imported.
Feed HooksFeed hooks can be used to alter mapping target or mapping sources. I think Feed hooks as a point where the code is paused, and they ask “anyone wants to add something here”, and then resume again. Any module who replies to it get triggered and data is get processed.
• hook_feeds_after_import Invoked after a feed source is imported
• hook_feeds_after_parse Invoked after the feed source has been parsed and before process
• hook_feeds_processor_target_alter Alter mapping targets for feed items, this hook can also be used to create custom targets.
• hook_feeds_presave Invoked Before a feed item is saved in database.
Feeds Extensions
Feed Temper
• Feeds Tamper provides a small plugin architecture for Feeds to modify data before it gets saved.• For e.g.
o Make every letter uppercase, lowercaseo Provide the default value for a field.o Rewrite the output of a field.o ….
• Once Feeds Tamper is enabled, the list of available Feeds importers (admin/structure/feeds) displays a "Tamper" configuration link for each feed.
• You can create your own plugin
1. Feeds Tamper PHP a. https://drupal.org/project/feeds_tamper_phpb. Provides a tamper plugin for executing php code
2. Feeds Tamper String2Ida. https://drupal.org/project/feeds_tamper_string2idb. Adds support for freeform Entityreference linking when using Feeds.
3. Feeds User Picturea. https://drupal.org/project/feeds_user_pictureb. Provides Target for importing User Pictures while importing users.
Case Study of one of our drupal implementation