A pain free migraine

879 views
794 views

Published on

Slide show which presents what I learned while working on an Drupal Open Atrium migration. This was presented at the 2013 Drupal Camp in Atlanta, Ga.

Published in: Technology, Self Improvement
2 Comments
0 Likes
Statistics
Notes
  • Hi Ningke,

    Ah, you are correct - the Dc Alt does not allow you to post comments. However, you can post a comment here and I will get it.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dennis, thank you for your presentation in Drupal camp Atlanta 2013. I tried to add comment several time on that website, but my comment did not post at all.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
879
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
2
Likes
0
Embeds 0
No embeds

No notes for slide

A pain free migraine

  1. 1. A pain free (sort of) approach to the Migraine (aka Migrate) module.
  2. 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
  3. 3. My Assignment  Migrate OA Beta to OA 1.4 on Drupal 6. 3
  4. 4. Data Migration Options    Move data by hand Feeds and Feeds Tamper Migrate module 4
  5. 5. Smoothing the Move      http://denver2012.drupal.org/program/sessions/ migration-smoothing-move Analyze – understand the legacy data Map – Line up source fields with destination fields Iterate – try, try, again – until it works Congratulations – you done 5
  6. 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. 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
  8. 8. Feeds Tamper   Manipulate the data before processing Works with Feeds 8
  9. 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. 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. 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. 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. 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
  14. 14. Learning Cliff     Open Atrium Open Atrium Data Structure Migrate Module OO Php 14
  15. 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
  16. 16. Ease the pain      phpMyAdmin Devel module Migrate UI Beer and Wine examples Drush 16
  17. 17. phpMyAdmin    How to read the keys to the tables Click on the index tab Database search for data 17
  18. 18. Open Atrium Structure 18
  19. 19. OA Data Structure        Taxonomy User and User Profile Organic Group nodes Books Content Types Comments Case Tracker Data Structure 19
  20. 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
  21. 21. Devel Module   Devel Devel node acces 21
  22. 22. Migrate Module    Migrate UI Migrate Migrate Extras 22
  23. 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. 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. 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. 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. 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. 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. 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. 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. 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. 32. Migration class Configure all of your pieces for the migration  Selects the source data and map it to the destination data.  32
  33. 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
  34. 34. Migration class 34
  35. 35. Source data    Source data can be in SQL, CSV, XML, JSON format Need to have definition of these files. I used the SQL format. 35
  36. 36. Field Handlers   A field definition within Drupal is an array structure Converts simple string data into the Drupal array structure 36
  37. 37. Destination Handlers      comments.inc fields.inc node.inc table.inc term.inc entity.inc file.inc path.inc table_copy.inc user.inc 37
  38. 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. 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. 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. 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. 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
  43. 43. Multiple DB in D7  Define the database Database::addConnectionInfo('jnn_xoops', 'default', array( 'driver' => 'mysql', 'database' => 'jnn_xoops', 'username' => 'root', 'password' => 'root', 'host' => 'localhost', 'prefix' => '', ));  Define the query $query = Database::getConnection('default', 'jnn_xoops') ->select('xoops_users', 'xu') ->fields('xu', array('uid', 'name', 'uname', 'email')); 43
  44. 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. 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
  46. 46. My Module 46
  47. 47. Let’s see the code class McOaBasicMigration extends McOaMigration { public function __construct() { parent::__construct(); $this->description = t('Descriptions'); $this->dependencies = array('Other_Migration_Dependencies'); $this->map = new MigrateSQLMap(....)); $query=db_select('comments_legacy', 'cl'); or $query = Database::getConnection('default', 'legacy') ->select('comments', 'cl'); $this->source = new MigrateSourceSQL($query); $this->destination = new MigrateDestinationComment('comment_case_tracker_case'); $this->addFieldMapping('pid', 'pid'); $this->addFieldMapping('nid', 'nid') ->sourceMigration('McOaCaseCt'); // Unmapped destination fields $this->addUnmigratedDestinations(array('fname', 'lname')); 47
  48. 48. Drush Migrate Cmds       https://drupal.org/node/1561820 drush migrate-import Article drush migrate-import Article --limit="100 items" drush migrate-import --all=User drush migrate-import –rollback –all drush migrate-import –update –group = [grp_name] 48

×