Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using the Migrate Module for Fewer Headaches when Relaunching a Site

Similar presentations


Presentation on theme: "Using the Migrate Module for Fewer Headaches when Relaunching a Site"— Presentation transcript:

1 Using the Migrate Module for Fewer Headaches when Relaunching a Site
John Fiala Developer

2 What it's For You've got an existing website Wordpress Joomla
Custom DB-based Website And you want to move to Drupal But you've got users, items, or terms you want to migrate to the new site

3 Sources SQL – Any sort Drupal can read MySQL, Postgres, MS SQL, Oracle
JSON CSV XML – Although if you're reading in from someone else's site, Feeds may be what you need

4 Destinations Entity Comment File Node Term User
Table – if defined in the schema TableCopy – Just copy data from Table A to Table A'

5 How does it work? Well, you're going to need to do some Object Oriented programming

6 What Gets Migrated? Source: Destination: Users Users
Blog posts, Events, other items Tags Comments Profiles Destination: Users Nodes Taxonomy Terms Comments Other Entities

7 Keep Track of Dependencies
Nodes depend on Users Nodes depend on Terms Comments depend on Nodes and Users Entities depend on Users too If you've got any Tables you're copying over, chances are something depends on that.

8 Example: Beer! CC Attribution 2.0 – Jason Dean

9 Example Beer Tables beer_topic beer_account beer_topic_node beer_node
beer_comment

10 beer_topic & beer_topic_node
Look at the Database!

11 Beer Topic Summary: style is the key to beer_topic
style should be mapped to term name details should be mapped to term description style_parent should be mapped to the term parent hoppiness and region may or may not be mapped – there's no obvious destination Fields? Part of the description? Ask the client!

12 Code Time!

13 Getting Fancier What if we wanted to make a term name include the region and hoppiness fields? Option 1: Change the SQL to prepare the data. $query = db_select('migrate_example_beer_topic', 'met') ->fields('met', array('style', 'style_parent', 'region', 'hoppiness')); $query->addExpression("CONCAT(details, ' region:', region, ' hoppiness:', hoppiness)", 'details'); $query->orderBy('style_parent', 'ASC');

14 Getting Fancier, pt 2 Or, we could let migrate move the data over, and then make changes to the data before it was saved. We do this by implementing a method called prepare(stdClass $entity, stdClass $row)

15 Field Mappings AddFieldMapping($destination, $source)
Just maps data from $source to $destination addSimpleMappings(array($fieldnames)) If you've got fields which are the same name in both source and destination, this maps them quickly

16 Field Mapping Modifiers
defaultValue($value) Applies $value as the value if the source is empty or if you don't give a source dedupe($drupal_table, $drupal_column) Enforces uniqueness on a non-unique source issueGroup, issuePriority, issueNumber description($desc)

17 More Field Mapping Modifiers
sourceMigration($migration) Tells the field mapping to look up the new value for the field in a previous migration separator($string) Explodes a string to provide a multi-value result Arguments() Some fields are more complex than just one value


Download ppt "Using the Migrate Module for Fewer Headaches when Relaunching a Site"

Similar presentations


Ads by Google