This document discusses using the Migrate module in Drupal to migrate content from one version of a Drupal site to another. It covers analyzing legacy data, mapping source and destination fields, writing migration code, and using tools like phpMyAdmin, Devel, and Drush to assist with the migration process. Key aspects of the Migrate module like migration classes, field handlers, and destination handlers are explained.
Pain-free approach to migrating with the Migrate module
1. A pain free (sort of)
approach to the
Migraine (aka Migrate)
module.
2. Dennis Solis
Solis Media Group
Over 20 years of application software development.
Two years of Drupal development
Procedural php coder
Learning OO php
Do not understand the magic of OO
Migraine module helped
2
6. Feeds
No coding except for special conditions
Setup / execution is done via a UI
LOT easier to setup and use
Comes with a mapping screen.
It is limited
Receiving module needs to support feeds.
Does not support all fields but you can write code
to handle the fields.
6
7. Feeds
Works great
Limited by lack of field handlers
It is a bit slow
Especially for LOTS of data
Does not work well if
Different contents types that reference the other.
7
9. Migrate Module
Import data / contents into Drupal 6, 7, and 8
Migrate for Drupal 6 and 7 are about 95%
compatible
Drupal 6 – uses dbtng and autoload
Mapping is done in code
Very flexible
Much Faster
Migraine is here to stay.
It is in Drupal 8 core
9
10. Migrate
Migrate 2.0
New Migrate 7.2-x-dev - – released 10-01-2013
Migrate 2.0 for D6 requires the autoload and dbtng
modules.
Migrate d 2 d
New Migrate 7.2-x-dev – released 10-01-2013
Migrate Extra – Sub-module within Migrate
10
11. Migrate D 2 D
Use this to migrate from 6 to 7 or 8
All the benefits and pain of the migrate module
Provides class specific to older versions of
Drupal.
It does a lot of the work that I had to do manually
I could not use because I went D6 to D6.
11
12. Migrate OG
Only use if you are using Migrate 1.0
The Organic Group migration support for
Migrate 2.0 has been moved into Organic
Groups itself.
12
13. Drupalcon Denver
Andrew Morton stated the migrate module:
Two weeks of banging his head
Tricky to get started with
Steep learning curve
Inscrutable
Complex
13
15. My Gifts to You
How to connect to multiple databases
Easily find the D6 source data structure
How to user the Migration UI
How to write migration code
15
20. Tools you will need
Football helmet
A LOT of aspirins
Patience
Tenacity
A little bit of knowledge
A little OO
A little migration code
20
23. Other Modules
dbtng – back ports many of the Drupal 7
database functions back to D 6
autoload – helper module to autoload
classes under PHP 5
23
24. OO definitions
An object is a self-contained component that
contains properties and methods needed to
make a certain type of data useful.
For example, in a project management application,
you would have a:
Status object
Cost object
Client object among others.
24
25. OO definitions
An object’s properties are what it knows. (This
of this as variables related to the object.)
Its methods are what it can do. (This if this as
functions or subroutines.)
25
26. OO definitions
A class is a blueprint or template or set of
instructions to build a specific type of object.
Every object is built from a class. Each class
should be designed and programmed to
accomplish one, and only one, thing.
26
27. OO definitions
An instance is a specific object built from a
specific class. It is assigned to a reference
variable that is used to access all of the instance's
properties and methods. When you make a new
instance the process is called instantiation and
is typically done using the new keyword.
27
28. OO definitions
A class is like a recipe for chocolate cake. The
recipe itself is not a cake. You can't eat the
recipe (or at least wouldn't want to).
If you correctly do what the recipe tells you to
do (instantiate it) then you have an edible cake.
That edible cake is an instance of the chocolate
cake class.
28
29. OO concepts
A class is like a recipe for chocolate cake. The
recipe itself is not a cake. You can't eat the
recipe (or at least wouldn't want to).
If you correctly do what the recipe tells you to
do (instantiate it) then you have an edible cake.
That edible cake is an instance of the chocolate
cake class.
29
30. Your Migrate Module
Migration should be in a SEPARATE
module
So you can turn it off once you are done.
Isolate it if you are going to be doing ongoing
date based updates.
30
31. Migrate supports
Support multi-field or composite keys.
Tracks the source id and it’s final destination id
and you can access this information during your
migration.
Translate from the old key to the new key.
Can do a roll back.
Can re-do a migration and update those articles
in place.
Do “date” based ongoing migrations.
31
32. Migration class
Configure all of your pieces for the migration
Selects the source data and map it to the
destination data.
32
33. Migration class
prepareRow(), prepare(), complete()
Allow you to manipulate the data or skip records
Update other rows while migrating data
Writes out the destination data.
33
38. Destination
Migrate will write the Destination nodes for
you (node, user, other supported entities, or
SQL rows).
Create one destination record for each source
record
38
39. Order is critical
Must migrate user accounts before you can
migrate user profiles.
Know you data
Create a list of the sequence in which the data
is to be converted.
39
40. Migration Class
Everything is done in code
You write a “base class” from which you then
extend in your code. In this base class, you can
define things about this migration.
Everything you want to do is an extension of
an existing migrate class.
40
41. Migration Class
Inherit and extend these classes
You have to write a small module to “extend”
the classes.
Documentation is provided in the form of
code examples.
beer.inc
wire.inc
41
42. Multiple DB in D6
Database select from within current
database:
*
$db_url = 'pgsql://username:password@localhost/databasename';
*/
*// - das - $db_url = 'mysqli://root@localhost/mis_project';
$db_url['default'] = 'mysqli://root@localhost/mis_project';
$db_url['legacy'] = 'mysqli://root@localhost/open_atrium_legacy';
$db_prefix = '';
Database select from within current
database:
$query = db_select('users_legacy', 'ul');
42
44. My Module
Structure of my migration module was placed in
sites/all/modules/custom.
My module name is: migrate_mc_oa
migrate_mc_oa.info
migrate_mc_oa.install
migrate_mc_oa.module
migrate_mc_oa.inc
44
45. My Module
Structure of my migration module
migrate_mc_oa_user.inc
migrate_mc_oa_node_og.inc
migrate_mc_oa_book.inc
migrate_mc_oa_node_ct.inc
migrate_mc_oc_comment.inc
45