SlideShare une entreprise Scribd logo
1  sur  20
Data migration to Drupal - Using the migrate module
                                              Ishan Mahajan
                                           DrupalCamp Delhi
                                                  April, 2011
Agenda

●   Migrate module
●
    Steps to work with migrate module
    ●   Hooks
    ●   Building classes
         –   Description
         –   Adding source
         –   Mapping
         –   Process data
●   Walk through an example migration – TYPO3 to Drupal
    ●   Code Heavy! - you may fall asleep
Migrate Module

●   Provides a flexible framework for migrating content into Drupal
●   Supports core Drupal objects such as nodes, users, taxonomy
    terms and comments.
    ●   Can define your own import handler
    ●   Can define your own field handler
●   Supports migration from XML, JSON, CSV, Databases


                                                               Cont...
Migrate Module (cont..)

●   Incremental migrations
●   Drush commands for import, listing, status, rollback etc
●   Only status UI – all mappings must to be done in code
Migration example

●   Migrate 'tt_news' from TYPO3 to Drupal
    ●   Talk about a small aspect of the migrate module (migrating
        nodes of type news)
    ●   Not talking about creating own DestinationHandlers and
        FieldHandlers
●   Migrating from a MySQL database
    ●   Both the database are on the same machine
Steps to work with migrate
Step 1: implement hook

●   Define your own module and let the migrate module know about
    it
●   Implement hook_migrate_api
        function mymodule_migrate_api() {
          return array(
           'api' => 2,
          );
    }
Step 2: define migration class

●   Give description
●   Let migrate know about the source of your content
●   Let migrate know about the destination type
●   Map the source and destination fields
●   Massage the data before being migrated.
Step 2(contd)

class Typo3NewsMigration extends Migration {
    public function __construct() {
        parent::__construct();
        ...
    }
    public function prepare(stdClass $node, stdClass $row) {
        ...
    }
}
Functions

●   public function __construct() {..}
    ●   Define the destination type(node, user, comment etc)
    ●   Describe the source(databse, xml etc.)
    ●   Field mappings
●   (optional) public function prepare(stdClass $node,
    stdClass $row) {..}
    ●   Massage the data that was pulled in – clean up text,
        links etc.
Step 2a: Give Description
●    Class description

    $this->description = t('News migration from TYPO3');
●    Dependencies

    $this->dependencies = array('Typo3NewsCategory');
●    Create map object - tracking the relationships between source row and Drupal object

    $this->map = new MigrateSQLMap($this->machineName,

     array(

         'uid' => array(

         'type' => 'int',

         'alias' => 'tn',

         )

     ),

     MigrateDestinationNode::getKeySchema()

    );
Step 2b: Setup source query
$query = db_select(TYPO3_DATABASE_NAME . '.tt_news', 'tn')

        ->fields('tn', array('uid', 'crdate', 'tstamp', 'pid', 'title', 'hidden', 'short',

               'bodytext', 'author', 'author_email', 'image', 'imagecaption', 'links', 'ext_url', 'news_files'))

        ->fields('catmm', array('sorting', 'uid_foreign'));

  $query->condition('tn.deleted', '0');

  $query->leftJoin( TYPO3_DATABASE_NAME . '.tt_news_cat_mm', 'catmm', 'catmm.uid_local = tn.uid');

  $query->leftJoin( TYPO3_DATABASE_NAME . '.tt_news_cat', 'newscat', 'newscat.uid = catmm.uid_foreign');

  // Related news articles

  $query->leftJoin(TYPO3_DATABASE_NAME . '.tt_news_related_mm', 'relatedmm', 'relatedmm.uid_local = tn.uid');



  $query->orderBy('tn.tstamp', 'ASC');

  $query->groupBy('tn.uid');

  $query->addExpression('GROUP_CONCAT(newscat.title)', 'newstags');

  ...

  $this->source = new MigrateSourceSQL($query);



NOTE: $query = Database::getConnection('for_typo3_migration', 'default');
Incremental Migrations

●   Import items which have been added/edited since the last
    migration
●   “high-water” mark for each migration class
     $this->highwaterField = array(
   'name' => 'last_changed', // Column to be used as highwater
mark
     'alias' => 'tn', // Table alias containing that column
    );
    $query->orderBy('last_changed');
Step 2c: Map the Data


●   Let the migrate module know the type of source
$this->source = new MigrateSourceSQL($query);


●   Similarly provide the destination handler
$this->destination = new MigrateDestinationNode('news');
Step 2d: Map the fields

●   Field mapings take the form
    ●   $this->addFieldMapping(‘destination_field_name’,
        ‘source_field_name’);
●   Can define default values
    ●   $this->addFieldMapping('language')
        ->defaultValue('en');
●   File fields require additional arguments
Step 2d(contd.)Fields
// Mapped fields

$this->addFieldMapping('title', 'title')

      ->description(t('Title of the node'));

$this->addFieldMapping('field_news_author_email', 'author_email');

...

// Image field

$arguments = MigrateFileFieldHandler::arguments(drupal_get_path('module', 'news') . '/pics', 'file_copy', FILE_EXISTS_RENAME);

$this->addFieldMapping('field_news_images', 'image')

      ->arguments($arguments)

      ->separator(',');

// just pass the taxonomy name

$this->addFieldMapping('News Category', 'newstags')

      ->separator(',');

// node reference field

$this->addFieldMapping('field_news_related_articles', 'related_list')

      ->sourceMigration('Typo3News')

      ->separator(',');
Step 3: Massage the data

●   On its way to Drupal!
public function prepare(stdClass $node, stdClass $row) {
     $node->status = ($row->hidden) ? '0' : '1';
     $node->body = $this->processLinkTag($node->body);
}
Running the migrations

●   Drush commands:
    ●   drush migrate-status
    ●   drush migrate-import Typo3News
         – --itemlimit
         – --feedback
         – --idlist
    ●   drush migrate-rollback Typo3News
Resources

●   http://drupal.org/project/migrate
●   http://drupal.org/project/migrate_extras
●   http://cyrve.com/import
●   http://drupal.org/project/wordpress_migrate
●   http://bit.ly/iddTad
●   http://bit.ly/hONVVb
Thank You :)

ishan@srijan.in

Contenu connexe

Tendances

Js info vis_toolkit
Js info vis_toolkitJs info vis_toolkit
Js info vis_toolkit
nikhilyagnic
 

Tendances (18)

Lodash js
Lodash jsLodash js
Lodash js
 
Js info vis_toolkit
Js info vis_toolkitJs info vis_toolkit
Js info vis_toolkit
 
Entity Query API
Entity Query APIEntity Query API
Entity Query API
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and Lodash
 
Modularity and Layered Data Model
Modularity and Layered Data ModelModularity and Layered Data Model
Modularity and Layered Data Model
 
Big xml
Big xmlBig xml
Big xml
 
Lab 13
Lab 13Lab 13
Lab 13
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscore
 
glTF 2.0 Reference Guide
glTF 2.0 Reference GuideglTF 2.0 Reference Guide
glTF 2.0 Reference Guide
 
Day 2b i/o.pptx
Day 2b   i/o.pptxDay 2b   i/o.pptx
Day 2b i/o.pptx
 
Ch9
Ch9Ch9
Ch9
 
The map interface (the java™ tutorials collections interfaces)
The map interface (the java™ tutorials   collections   interfaces)The map interface (the java™ tutorials   collections   interfaces)
The map interface (the java™ tutorials collections interfaces)
 
Grails UI Primer
Grails UI PrimerGrails UI Primer
Grails UI Primer
 
Structures and Unions
Structures and UnionsStructures and Unions
Structures and Unions
 
Ms Ajax Dom Element Class
Ms Ajax Dom Element ClassMs Ajax Dom Element Class
Ms Ajax Dom Element Class
 
Migrate
MigrateMigrate
Migrate
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
 
Day 2 repeats.pptx
Day 2 repeats.pptxDay 2 repeats.pptx
Day 2 repeats.pptx
 

Similaire à Data migration to Drupal using Migrate Module

Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
Katie Gulley
 

Similaire à Data migration to Drupal using Migrate Module (20)

Making the Move from Typo3 to Drupal
Making the Move from Typo3 to DrupalMaking the Move from Typo3 to Drupal
Making the Move from Typo3 to Drupal
 
Migrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate moduleMigrating data into Drupal using the migrate module
Migrating data into Drupal using the migrate module
 
Move Into Drupal Using The Migrate Module
Move Into Drupal Using The Migrate ModuleMove Into Drupal Using The Migrate Module
Move Into Drupal Using The Migrate Module
 
Drupal content-migration
Drupal content-migrationDrupal content-migration
Drupal content-migration
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
 
Migrate
MigrateMigrate
Migrate
 
Digital Mayflower - Data Pilgrimage with the Drupal Migrate Module
Digital Mayflower - Data Pilgrimage with the Drupal Migrate ModuleDigital Mayflower - Data Pilgrimage with the Drupal Migrate Module
Digital Mayflower - Data Pilgrimage with the Drupal Migrate Module
 
Automating Drupal Migrations
Automating Drupal MigrationsAutomating Drupal Migrations
Automating Drupal Migrations
 
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, GermanyLet's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
Let's write secure Drupal code! - 13.09.2018 @ Drupal Europe, Darmstadt, Germany
 
Drupal 8 Hooks
Drupal 8 HooksDrupal 8 Hooks
Drupal 8 Hooks
 
Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!Do you know what your drupal is doing? Observe it!
Do you know what your drupal is doing? Observe it!
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Dcm migration
Dcm migrationDcm migration
Dcm migration
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 

Plus de Srijan Technologies

[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
Srijan Technologies
 
[Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
 [Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr... [Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
[Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
Srijan Technologies
 
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
Srijan Technologies
 

Plus de Srijan Technologies (20)

[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
[Srijan Wednesday Webinar] How to Run Stateless and Stateful Services on K8S ...
 
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
[Srijan Wednesday Webinars] How to Set Up a Node.js Microservices Architectur...
 
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
[Srijan Wednesday Webinars] How to Build a Cloud Native Platform for Enterpri...
 
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
[Srijan Wednesday Webinars] Using Drupal as Data Pipeline for Digital Signage
 
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
[Srijan Wednesday Webinars] New Recipe of Decoupling: Drupal 8, Symfony and S...
 
[Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Ro...
[Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Ro...[Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Ro...
[Srijan Wednesday Webinars] Let’s Take the Best Route - Exploring Drupal 8 Ro...
 
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
[Srijan Wednesday Webinars] Is Your Business Ready for GDPR
 
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
[Srijan Wednesday Webinars] Artificial Intelligence & the Future of Business
 
[Srijan Wednesday Webinars] How to Design a Chatbot that Works
[Srijan Wednesday Webinars] How to Design a Chatbot that Works[Srijan Wednesday Webinars] How to Design a Chatbot that Works
[Srijan Wednesday Webinars] How to Design a Chatbot that Works
 
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
[Srijan Wednesday Webinars] Simplifying Migration to Drupal 8
 
Final dependency presentation.odp
Final dependency presentation.odpFinal dependency presentation.odp
Final dependency presentation.odp
 
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
[Srijan Wednesday Webinar] Leveraging the OGD Platform and Visualization Engine
 
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing [Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
[Srijan Wednesday Webinars] Why Adopt Analytics Driven Testing
 
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
[Srijan Wednesday Webinar] Key ingredients of a Powerful Test Automation System
 
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
[Srijan Wednesday Webinar] Building BPMN Web Portals with Camunda and Drupal
 
[Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
 [Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr... [Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
[Srijan Wednesday Webinar] Decoupled Demystified: The Present & Future of Dr...
 
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
[Srijan Wednesday Webinars] Automating Visual Regression using ‘Galen’
 
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
[Srijan Wednesday Webinars] NASA, Netflix, Tinder: Digital Transformation and...
 
[Srijan Wednesday Webinars] Building a High Performance QA Team
[Srijan Wednesday Webinars] Building a High Performance QA Team[Srijan Wednesday Webinars] Building a High Performance QA Team
[Srijan Wednesday Webinars] Building a High Performance QA Team
 
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
[Srijan Wednesday Webinar] Mastering Mobile Test Automation with Appium
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Data migration to Drupal using Migrate Module

  • 1. Data migration to Drupal - Using the migrate module Ishan Mahajan DrupalCamp Delhi April, 2011
  • 2. Agenda ● Migrate module ● Steps to work with migrate module ● Hooks ● Building classes – Description – Adding source – Mapping – Process data ● Walk through an example migration – TYPO3 to Drupal ● Code Heavy! - you may fall asleep
  • 3. Migrate Module ● Provides a flexible framework for migrating content into Drupal ● Supports core Drupal objects such as nodes, users, taxonomy terms and comments. ● Can define your own import handler ● Can define your own field handler ● Supports migration from XML, JSON, CSV, Databases Cont...
  • 4. Migrate Module (cont..) ● Incremental migrations ● Drush commands for import, listing, status, rollback etc ● Only status UI – all mappings must to be done in code
  • 5. Migration example ● Migrate 'tt_news' from TYPO3 to Drupal ● Talk about a small aspect of the migrate module (migrating nodes of type news) ● Not talking about creating own DestinationHandlers and FieldHandlers ● Migrating from a MySQL database ● Both the database are on the same machine
  • 6. Steps to work with migrate
  • 7. Step 1: implement hook ● Define your own module and let the migrate module know about it ● Implement hook_migrate_api function mymodule_migrate_api() { return array( 'api' => 2, ); }
  • 8. Step 2: define migration class ● Give description ● Let migrate know about the source of your content ● Let migrate know about the destination type ● Map the source and destination fields ● Massage the data before being migrated.
  • 9. Step 2(contd) class Typo3NewsMigration extends Migration { public function __construct() { parent::__construct(); ... } public function prepare(stdClass $node, stdClass $row) { ... } }
  • 10. Functions ● public function __construct() {..} ● Define the destination type(node, user, comment etc) ● Describe the source(databse, xml etc.) ● Field mappings ● (optional) public function prepare(stdClass $node, stdClass $row) {..} ● Massage the data that was pulled in – clean up text, links etc.
  • 11. Step 2a: Give Description ● Class description $this->description = t('News migration from TYPO3'); ● Dependencies $this->dependencies = array('Typo3NewsCategory'); ● Create map object - tracking the relationships between source row and Drupal object $this->map = new MigrateSQLMap($this->machineName, array( 'uid' => array( 'type' => 'int', 'alias' => 'tn', ) ), MigrateDestinationNode::getKeySchema() );
  • 12. Step 2b: Setup source query $query = db_select(TYPO3_DATABASE_NAME . '.tt_news', 'tn') ->fields('tn', array('uid', 'crdate', 'tstamp', 'pid', 'title', 'hidden', 'short', 'bodytext', 'author', 'author_email', 'image', 'imagecaption', 'links', 'ext_url', 'news_files')) ->fields('catmm', array('sorting', 'uid_foreign')); $query->condition('tn.deleted', '0'); $query->leftJoin( TYPO3_DATABASE_NAME . '.tt_news_cat_mm', 'catmm', 'catmm.uid_local = tn.uid'); $query->leftJoin( TYPO3_DATABASE_NAME . '.tt_news_cat', 'newscat', 'newscat.uid = catmm.uid_foreign'); // Related news articles $query->leftJoin(TYPO3_DATABASE_NAME . '.tt_news_related_mm', 'relatedmm', 'relatedmm.uid_local = tn.uid'); $query->orderBy('tn.tstamp', 'ASC'); $query->groupBy('tn.uid'); $query->addExpression('GROUP_CONCAT(newscat.title)', 'newstags'); ... $this->source = new MigrateSourceSQL($query); NOTE: $query = Database::getConnection('for_typo3_migration', 'default');
  • 13. Incremental Migrations ● Import items which have been added/edited since the last migration ● “high-water” mark for each migration class $this->highwaterField = array( 'name' => 'last_changed', // Column to be used as highwater mark 'alias' => 'tn', // Table alias containing that column ); $query->orderBy('last_changed');
  • 14. Step 2c: Map the Data ● Let the migrate module know the type of source $this->source = new MigrateSourceSQL($query); ● Similarly provide the destination handler $this->destination = new MigrateDestinationNode('news');
  • 15. Step 2d: Map the fields ● Field mapings take the form ● $this->addFieldMapping(‘destination_field_name’, ‘source_field_name’); ● Can define default values ● $this->addFieldMapping('language') ->defaultValue('en'); ● File fields require additional arguments
  • 16. Step 2d(contd.)Fields // Mapped fields $this->addFieldMapping('title', 'title') ->description(t('Title of the node')); $this->addFieldMapping('field_news_author_email', 'author_email'); ... // Image field $arguments = MigrateFileFieldHandler::arguments(drupal_get_path('module', 'news') . '/pics', 'file_copy', FILE_EXISTS_RENAME); $this->addFieldMapping('field_news_images', 'image') ->arguments($arguments) ->separator(','); // just pass the taxonomy name $this->addFieldMapping('News Category', 'newstags') ->separator(','); // node reference field $this->addFieldMapping('field_news_related_articles', 'related_list') ->sourceMigration('Typo3News') ->separator(',');
  • 17. Step 3: Massage the data ● On its way to Drupal! public function prepare(stdClass $node, stdClass $row) { $node->status = ($row->hidden) ? '0' : '1'; $node->body = $this->processLinkTag($node->body); }
  • 18. Running the migrations ● Drush commands: ● drush migrate-status ● drush migrate-import Typo3News – --itemlimit – --feedback – --idlist ● drush migrate-rollback Typo3News
  • 19. Resources ● http://drupal.org/project/migrate ● http://drupal.org/project/migrate_extras ● http://cyrve.com/import ● http://drupal.org/project/wordpress_migrate ● http://bit.ly/iddTad ● http://bit.ly/hONVVb