SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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!
 

Mais 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
 

Mais 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
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

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